Search in sources :

Example 11 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipProviderImpl method getNewDialog.

/*
     * (non-Javadoc)
     *
     * @see javax.sip.SipProvider#getNewDialog(javax.sip.Transaction)
     */
public Dialog getNewDialog(Transaction transaction) throws SipException {
    if (transaction == null)
        throw new NullPointerException("Null transaction!");
    if (!sipStack.isAlive())
        throw new SipException("Stack is stopped.");
    if (isAutomaticDialogSupportEnabled())
        throw new SipException(" Error - AUTOMATIC_DIALOG_SUPPORT is on");
    if (!sipStack.isDialogCreated(transaction.getRequest().getMethod()))
        throw new SipException("Dialog cannot be created for this method " + transaction.getRequest().getMethod());
    SIPDialog dialog = null;
    SIPTransaction sipTransaction = (SIPTransaction) transaction;
    if (transaction instanceof ServerTransaction) {
        SIPServerTransaction st = (SIPServerTransaction) transaction;
        Response response = st.getLastResponse();
        if (response != null) {
            if (response.getStatusCode() != 100)
                throw new SipException("Cannot set dialog after response has been sent");
        }
        SIPRequest sipRequest = (SIPRequest) transaction.getRequest();
        String dialogId = sipRequest.getDialogId(true);
        dialog = sipStack.getDialog(dialogId);
        if (dialog == null) {
            dialog = sipStack.createDialog((SIPTransaction) transaction);
            // create and register the dialog and add the inital route set.
            dialog.addTransaction(sipTransaction);
            dialog.addRoute(sipRequest);
            sipTransaction.setDialog(dialog, null);
        } else {
            sipTransaction.setDialog(dialog, sipRequest.getDialogId(true));
        }
        if (sipRequest.getMethod().equals(Request.INVITE) && this.isDialogErrorsAutomaticallyHandled()) {
            sipStack.putInMergeTable(st, sipRequest);
        }
    } else {
        SIPClientTransaction sipClientTx = (SIPClientTransaction) transaction;
        SIPResponse response = sipClientTx.getLastResponse();
        if (response == null) {
            // A response has not yet been received, then set this up as the
            // default dialog.
            SIPRequest request = (SIPRequest) sipClientTx.getRequest();
            String dialogId = request.getDialogId(false);
            dialog = sipStack.getDialog(dialogId);
            if (dialog != null) {
                throw new SipException("Dialog already exists!");
            } else {
                dialog = sipStack.createDialog(sipTransaction);
            }
            sipClientTx.setDialog(dialog, null);
        } else {
            throw new SipException("Cannot call this method after response is received!");
        }
    }
    dialog.addEventListener(this);
    return dialog;
}
Also used : Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SIPDialog(gov.nist.javax.sip.stack.SIPDialog) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) SipException(javax.sip.SipException) ServerTransaction(javax.sip.ServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPRequest(gov.nist.javax.sip.message.SIPRequest)

Example 12 with Response

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

the class SipManager method sendNotImplemented.

/**
     * Sends a NOT_IMPLEMENTED response through the specified transaction.
     *
     * @param serverTransaction the transaction to send the response through.
     * @param request           the request that is being answered.
     */
void sendNotImplemented(ServerTransaction serverTransaction, Request request) {
    Response notImplemented;
    try {
        notImplemented = messageFactory.createResponse(Response.NOT_IMPLEMENTED, request);
        attachToTag(notImplemented, serverTransaction.getDialog());
    } catch (ParseException ex) {
        fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
        return;
    }
    try {
        serverTransaction.sendResponse(notImplemented);
    } catch (SipException ex) {
        fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
    }
}
Also used : Response(javax.sip.message.Response) ParseException(java.text.ParseException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 13 with Response

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

the class SimpleListener method processResponse.

public void processResponse(ResponseEvent responseEvent) {
    if (responseEvent.getClientTransaction() != null) {
        Log.debug("SimpleListener for " + myUsername + ":  Getting client transaction...");
        ClientTransaction clientTransaction = responseEvent.getClientTransaction();
        Dialog clientDialog = clientTransaction.getDialog();
        getSession().printDialog(clientDialog);
    }
    Log.debug("SimpleListener for " + myUsername + ":  Received a response event:  " + responseEvent.getResponse().toString());
    //		String   fromAddr = "";
    String toAddr = "";
    Response response = responseEvent.getResponse();
    //		}
    if (response.getHeader(ToHeader.NAME) != null) {
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        URI toUri = toHeader.getAddress().getURI();
        if (toUri instanceof SipUri)
            toAddr = ((SipUri) toUri).getUser() + "@" + ((SipUri) toUri).getHost();
        else
            toAddr = toUri.toString();
    }
    if (response.getHeader(CSeqHeader.NAME) != null) {
        String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
        if (method.equals(Request.REGISTER)) {
            if (response.getStatusCode() / 100 == 2) {
                int expires = 0;
                if (response.getHeader(ContactHeader.NAME) != null) {
                    expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
                } else if (response.getHeader(ExpiresHeader.NAME) != null) {
                    expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
                }
                if (expires > 0) {
                    Log.debug("SimpleListener(" + myUsername + ").processResponse:  " + getSession().getRegistration().getUsername() + " log in successful!");
                    getSession().sipUserLoggedIn();
                } else {
                    if (getSession().getLoginStatus().equals(TransportLoginStatus.LOGGING_OUT)) {
                        Log.debug("SimpleListener(" + myUsername + ").processResponse:  " + getSession().getRegistration().getUsername() + " log out successful!");
                        getSession().sipUserLoggedOut();
                        getSession().removeStack();
                    }
                }
            }
        }
        if (method.equals(Request.SUBSCRIBE)) {
            if (response.getStatusCode() / 100 == 2) {
                Log.debug("SimpleListener for " + myUsername + ":  Handling SUBSCRIBE acknowledgement!!");
                int expires = 0;
                if (response.getHeader(ContactHeader.NAME) != null) {
                    expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
                }
                if (response.getHeader(ExpiresHeader.NAME) != null) {
                    expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
                }
                if (expires > 0) {
                    // Confirm subscription of roster item
                    getSession().contactSubscribed(toAddr);
                } else {
                    // Confirm unsubscription of roster item
                    getSession().contactUnsubscribed(toAddr);
                }
                Log.debug("SimpleListener for " + myUsername + ":  Handled SUBSCRIBE acknowledgement!!");
            }
        }
    }
}
Also used : Response(javax.sip.message.Response) CSeqHeader(javax.sip.header.CSeqHeader) Dialog(javax.sip.Dialog) ClientTransaction(javax.sip.ClientTransaction) ToHeader(javax.sip.header.ToHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) SipUri(gov.nist.javax.sip.address.SipUri) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI)

Example 14 with Response

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

the class SipSubscriptionListener method processResponse.

public void processResponse(ResponseEvent responseReceivedEvent) {
    LOG.debug("Response received at Subscriber");
    Response response = responseReceivedEvent.getResponse();
    Transaction clientTransactionId = responseReceivedEvent.getClientTransaction();
    LOG.debug("Response received with client transaction id {}:{}", clientTransactionId, response.getStatusCode());
    if (clientTransactionId == null) {
        if (LOG.isWarnEnabled()) {
            LOG.warn("Stray response -- dropping");
        }
        return;
    }
}
Also used : Response(javax.sip.message.Response) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction)

Example 15 with Response

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

the class SipPresenceAgentListener method processSubscribe.

public void processSubscribe(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
        LOG.debug("SipPresenceAgentListener: Received a Subscribe request, sending OK");
        LOG.debug("SipPresenceAgentListener request: {}", request);
        EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
        if (eventHeader == null) {
            LOG.debug("Cannot find event header.... dropping request.");
            return;
        }
        // Always create a ServerTransaction, best as early as possible in the code
        Response response = null;
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
        boolean isInitial = requestEvent.getDialog() == null;
        if (isInitial) {
            String toTag = UUID.randomUUID().toString();
            response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
            ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
            // Application is supposed to set.
            toHeader.setTag(toTag);
            this.dialog = st.getDialog();
            // subscribe dialogs do not terminate on bye.
            this.dialog.terminateOnBye(false);
        } else {
            response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(200, request);
        }
        // Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
        response.addHeader(sipPresenceAgent.getConfiguration().getContactHeader());
        // Expires header is mandatory in 2xx responses to SUBSCRIBE
        response.addHeader(sipPresenceAgent.getConfiguration().getExpiresHeader());
        st.sendResponse(response);
        LOG.debug("SipPresenceAgentListener: Sent OK Message");
        LOG.debug("SipPresenceAgentListener response: {}", response);
        sendNotification(eventHeader, isInitial, request.getContent());
    } catch (Throwable e) {
        LOG.error("Exception thrown during Notify processing in the SipPresenceAgentListener.", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) ToHeader(javax.sip.header.ToHeader) EventHeader(javax.sip.header.EventHeader) ServerTransaction(javax.sip.ServerTransaction) SipProvider(javax.sip.SipProvider)

Aggregations

Response (javax.sip.message.Response)21 SipException (javax.sip.SipException)10 Request (javax.sip.message.Request)9 ParseException (java.text.ParseException)8 SIPResponse (gov.nist.javax.sip.message.SIPResponse)6 ServerTransaction (javax.sip.ServerTransaction)5 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)3 ResponseEvent (javax.sip.ResponseEvent)3 SipProvider (javax.sip.SipProvider)3 ToHeader (javax.sip.header.ToHeader)3 SipUri (gov.nist.javax.sip.address.SipUri)2 SIPRequest (gov.nist.javax.sip.message.SIPRequest)2 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)2 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)2 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)2 ClientTransaction (javax.sip.ClientTransaction)2 Dialog (javax.sip.Dialog)2 InvalidArgumentException (javax.sip.InvalidArgumentException)2 SipURI (javax.sip.address.SipURI)2 CSeqHeader (javax.sip.header.CSeqHeader)2