Search in sources :

Example 1 with Response

use of javax.sip.message.Response in project Openfire by igniterealtime.

the class SipManager method processResponse.

// -------------------- PROCESS RESPONSE
public void processResponse(ResponseEvent responseReceivedEvent) {
    Log.debug("RESPONSE [" + responseReceivedEvent.getResponse().getStatusCode() + "]");
    ClientTransaction clientTransaction = responseReceivedEvent.getClientTransaction();
    if (clientTransaction == null) {
        return;
    }
    Response response = responseReceivedEvent.getResponse();
    String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
    // OK
    if (response.getStatusCode() == Response.OK) {
        // REGISTER
        if (method.equals(Request.REGISTER)) {
            registerProcessing.processOK(clientTransaction, response);
        }
    } else // NOT_FOUND
    if (response.getStatusCode() == Response.NOT_FOUND) {
        if (method.equals(Request.REGISTER)) {
            try {
                unregister();
                registrationFailed(RegistrationEvent.Type.NotFound);
            } catch (CommunicationsException e) {
                Log.error("NOT FOUND", e);
            }
            Log.debug("REGISTER NOT FOUND");
        }
    } else // NOT_IMPLEMENTED
    if (response.getStatusCode() == Response.NOT_IMPLEMENTED) {
        if (method.equals(Request.REGISTER)) {
            // Fixed typo issues - Reported by pizarro
            registerProcessing.processNotImplemented(clientTransaction, response);
        }
    } else // 401 UNAUTHORIZED
    if (response.getStatusCode() == Response.UNAUTHORIZED || response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED) {
        if (method.equals(Request.REGISTER)) {
            CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
            if (cseq.getSequenceNumber() < 2)
                registerProcessing.processAuthenticationChallenge(clientTransaction, response);
            else
                registrationFailed(RegistrationEvent.Type.WrongPass);
        }
    } else // 403 Wrong Authorization user for this account
    if (response.getStatusCode() == Response.FORBIDDEN) {
        registrationFailed(RegistrationEvent.Type.Forbidden);
    }
}
Also used : Response(javax.sip.message.Response) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 2 with Response

use of javax.sip.message.Response in project Openfire by igniterealtime.

the class SimpleSession method sendResponse.

public ServerTransaction sendResponse(int status, Request request, ServerTransaction serverTransaction) {
    try {
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Starting response sending process.");
        if (serverTransaction == null)
            serverTransaction = udpSipProvider.getNewServerTransaction(request);
        Response response = messageFactory.createResponse(status, request);
        // Set "Exprires" header
        if (request.getHeader(ExpiresHeader.NAME) != null)
            response.setHeader(request.getHeader(ExpiresHeader.NAME));
        // Add "Contact" header
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Preparing \"Contact\" header...");
        try {
            SipURI contactURI = addressFactory.createSipURI(null, InetAddress.getLocalHost().getHostAddress());
            contactURI.setPort(sipPort);
            Address contactAddress = addressFactory.createAddress(contactURI);
            //				contactAddress.setDisplayName(mySipUsername);
            ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
            response.addHeader(contactHeader);
        } catch (Exception e) {
            Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Exception occured when adding ContactHeader.", e);
        //				return false;	// We can continue with this though.
        }
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Sending response:  " + response.toString());
        serverTransaction.sendResponse(response);
        //			udpSipProvider.sendResponse(response);
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Response sent!");
        return serverTransaction;
    } catch (Exception ex) {
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  ", ex);
    }
    return null;
}
Also used : Response(javax.sip.message.Response) ContactHeader(javax.sip.header.ContactHeader) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 3 with Response

use of javax.sip.message.Response in project camel by apache.

the class SipPresenceAgentListener method processResponse.

public synchronized void processResponse(ResponseEvent responseReceivedEvent) {
    Response response = responseReceivedEvent.getResponse();
    Integer statusCode = response.getStatusCode();
    if (SIP_MESSAGE_CODES.containsKey(statusCode)) {
        LOG.debug(SIP_MESSAGE_CODES.get(statusCode) + " received from Subscriber");
    }
}
Also used : Response(javax.sip.message.Response)

Example 4 with Response

use of javax.sip.message.Response in project camel by apache.

the class SipPresenceAgentListener method processPublish.

private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    try {
        Request request = requestEvent.getRequest();
        LOG.debug("SipPresenceAgentListener: Received a Publish request, sending OK");
        LOG.debug("SipPresenceAgentListener request: {}", request);
        EventHeader eventHeader = (EventHeader) requestEvent.getRequest().getHeader(EventHeader.NAME);
        Response response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
        sipPresenceAgent.getProvider().sendResponse(response);
        // Send notification to subscriber
        sendNotification(eventHeader, false, request.getContent());
    } catch (Exception e) {
        LOG.error("Exception thrown during publish/notify processing in the Sip Presence Agent Listener", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) EventHeader(javax.sip.header.EventHeader) SipException(javax.sip.SipException) ParseException(java.text.ParseException)

Example 5 with Response

use of javax.sip.message.Response in project camel by apache.

the class SipSubscriptionListener method processNotify.

public synchronized void processNotify(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    LOG.debug("Notification received at Subscriber");
    SipProvider provider = (SipProvider) requestEvent.getSource();
    Request notify = requestEvent.getRequest();
    try {
        if (serverTransactionId == null) {
            LOG.info("ServerTransaction is null. Creating new Server transaction");
            serverTransactionId = provider.getNewServerTransaction(notify);
        }
        Dialog dialog = serverTransactionId.getDialog();
        if (dialog != subscriberDialog) {
            forkedDialog = dialog;
        }
        //Dispatch the response along the route
        dispatchExchange(notify.getContent());
        // Send back an success response
        Response response = sipSubscriber.getConfiguration().getMessageFactory().createResponse(200, notify);
        response.addHeader(sipSubscriber.getConfiguration().getContactHeader());
        serverTransactionId.sendResponse(response);
        SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
        // Subscription is terminated?
        if (subscriptionState.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
            LOG.info("Subscription state is terminated. Deleting the current dialog");
            dialog.delete();
        }
    } catch (Exception e) {
        LOG.error("Exception thrown during Notify processing in the SipSubscriptionListener.", e);
    }
}
Also used : Response(javax.sip.message.Response) Dialog(javax.sip.Dialog) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) Request(javax.sip.message.Request) CamelException(org.apache.camel.CamelException) SipProvider(javax.sip.SipProvider)

Aggregations

Response (javax.sip.message.Response)77 ParseException (java.text.ParseException)42 SipException (javax.sip.SipException)41 InvalidArgumentException (javax.sip.InvalidArgumentException)32 Request (javax.sip.message.Request)28 ServerTransaction (javax.sip.ServerTransaction)22 TransactionUnavailableException (javax.sip.TransactionUnavailableException)20 Dialog (javax.sip.Dialog)18 ToHeader (javax.sip.header.ToHeader)17 Test (org.junit.Test)17 ListeningPoint (javax.sip.ListeningPoint)16 ContactHeader (javax.sip.header.ContactHeader)16 SipURI (javax.sip.address.SipURI)13 SIPResponse (gov.nist.javax.sip.message.SIPResponse)12 ClientTransaction (javax.sip.ClientTransaction)12 SipProvider (javax.sip.SipProvider)11 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)11 ViaHeader (javax.sip.header.ViaHeader)11 FromHeader (javax.sip.header.FromHeader)10 CSeqHeader (javax.sip.header.CSeqHeader)9