Package gov.nist.javax.sip.message

Examples of gov.nist.javax.sip.message.SIPResponse


            throws SipException {
        if (!this.isServer()) {
            throw new SipException("Not a Server Dialog");
        }

        SIPResponse sipResponse = (SIPResponse) relResponse;

        if (relResponse.getStatusCode() == 100)
            throw new SipException(
                    "Cannot send 100 as a reliable provisional response");

        if (relResponse.getStatusCode() / 100 > 2)
            throw new SipException(
                    "Response code is not a 1xx response - should be in the range 101 to 199 ");

        /*
         * Do a little checking on the outgoing response.
         */
        if (sipResponse.getToTag() == null) {
            throw new SipException(
                    "Badly formatted response -- To tag mandatory for Reliable Provisional Response");
        }
        ListIterator requireList = (ListIterator) relResponse
                .getHeaders(RequireHeader.NAME);
        boolean found = false;

        if (requireList != null) {

            while (requireList.hasNext() && !found) {
                RequireHeader rh = (RequireHeader) requireList.next();
                if (rh.getOptionTag().equalsIgnoreCase("100rel")) {
                    found = true;
                }
            }
        }

        if (!found) {
            Require require = new Require("100rel");
            relResponse.addHeader(require);
            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                sipStack
                        .getStackLogger()
                        .logDebug(
                                "Require header with optionTag 100rel is needed -- adding one");
            }

        }

        SIPServerTransaction serverTransaction = (SIPServerTransaction) this
                .getFirstTransactionInt();
        /*
         * put into the dialog table before sending the response so as to avoid
         * race condition with PRACK
         */
        this.setLastResponse(serverTransaction, sipResponse);

        this.setDialogId(sipResponse.getDialogId(true));

        serverTransaction.sendReliableProvisionalResponse(relResponse);

        this.startRetransmitTimer(serverTransaction, relResponse);

View Full Code Here


     * @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
     */
    public void sendResponse(Response response) throws SipException {
        if (!sipStack.isAlive())
            throw new SipException("Stack is stopped");
        SIPResponse sipResponse = (SIPResponse) response;
        Via via = sipResponse.getTopmostVia();
        if (via == null)
            throw new SipException("No via header in response!");
        SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage)response, true);
        if ( st != null   && st.getInternalState() != TransactionState._TERMINATED && this.isAutomaticDialogSupportEnabled()) {
            throw new SipException("Transaction exists -- cannot send response statelessly");
View Full Code Here

            }
        } 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();
View Full Code Here

     * @param transaction
     */
    private void sendRequestPendingResponse(SIPRequest sipRequest,
            SIPServerTransaction transaction) {
        if (transaction.getState() != TransactionState.TERMINATED) {
            SIPResponse sipResponse = sipRequest
                    .createResponse(Response.REQUEST_PENDING);
            ServerHeader serverHeader = MessageFactoryImpl
                    .getDefaultServerHeader();
            if (serverHeader != null) {
                sipResponse.setHeader(serverHeader);
            }
            try {
                RetryAfter retryAfter = new RetryAfter();
                retryAfter.setRetryAfter(1);
                sipResponse.setHeader(retryAfter);
                if (sipRequest.getMethod().equals(Request.INVITE)) {
                    sipStack.addTransactionPendingAck(transaction);
                }
                transaction.sendResponse(sipResponse);
                transaction.releaseSem();
View Full Code Here

    private void sendBadRequestResponse(SIPRequest sipRequest,
            SIPServerTransaction transaction, String reasonPhrase) {
        if (transaction.getState() != TransactionState.TERMINATED) {

            SIPResponse sipResponse = sipRequest
                    .createResponse(Response.BAD_REQUEST);
            if (reasonPhrase != null)
                sipResponse.setReasonPhrase(reasonPhrase);
            ServerHeader serverHeader = MessageFactoryImpl
                    .getDefaultServerHeader();
            if (serverHeader != null) {
                sipResponse.setHeader(serverHeader);
            }
            try {
                if (sipRequest.getMethod().equals(Request.INVITE)) {
                    sipStack.addTransactionPendingAck(transaction);
                }
View Full Code Here

    private void sendCallOrTransactionDoesNotExistResponse(
            SIPRequest sipRequest, SIPServerTransaction transaction) {

        if (transaction.getState() != TransactionState.TERMINATED) {
            SIPResponse sipResponse = sipRequest
                    .createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST);

            ServerHeader serverHeader = MessageFactoryImpl
                    .getDefaultServerHeader();
            if (serverHeader != null) {
                sipResponse.setHeader(serverHeader);
            }
            try {
                if (sipRequest.getMethod().equals(Request.INVITE)) {
                    sipStack.addTransactionPendingAck(transaction);
                }
View Full Code Here

     * @param transaction
     *
     */
    private void sendLoopDetectedResponse(SIPRequest sipRequest,
            SIPServerTransaction transaction) {
        SIPResponse sipResponse = sipRequest
                .createResponse(Response.LOOP_DETECTED);
        if (transaction.getState() != TransactionState.TERMINATED) {

            ServerHeader serverHeader = MessageFactoryImpl
                    .getDefaultServerHeader();
            if (serverHeader != null) {
                sipResponse.setHeader(serverHeader);
            }
            try {
                sipStack.addTransactionPendingAck(transaction);
                transaction.sendResponse(sipResponse);
                transaction.releaseSem();
View Full Code Here

            SIPServerTransaction transaction) {
        if (transaction.getState() != TransactionState.TERMINATED) {
            if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
                sipStack.getStackLogger().logDebug(
                        "Sending 500 response for out of sequence message");
            SIPResponse sipResponse = sipRequest
                    .createResponse(Response.SERVER_INTERNAL_ERROR);
            sipResponse.setReasonPhrase("Request out of order");
            if (MessageFactoryImpl.getDefaultServerHeader() != null) {
                ServerHeader serverHeader = MessageFactoryImpl
                        .getDefaultServerHeader();
                sipResponse.setHeader(serverHeader);
            }

            try {
                RetryAfter retryAfter = new RetryAfter();
                retryAfter.setRetryAfter(10);
                sipResponse.setHeader(retryAfter);
                sipStack.addTransactionPendingAck(transaction);
                transaction.sendResponse(sipResponse);
                transaction.releaseSem();
            } catch (Exception ex) {
                sipStack.getStackLogger().logError("Problem sending response",
View Full Code Here

                    sipStack
                            .getStackLogger()
                            .logDebug(
                                    "Sending 481 for PRACK - automatic dialog support is enabled -- cant find dialog!");
                }
                SIPResponse notExist = sipRequest
                        .createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST);

                try {
                    sipProvider.sendResponse(notExist);
                } catch (SipException e) {
                    sipStack.getStackLogger().logError(
                            "error sending response", e);
                }
                if (transaction != null) {
                    sipStack.removeTransaction(transaction);
                    transaction.releaseSem();
                }
                return;

            } else if (dialog != null) {
                if (!dialog.handlePrack(sipRequest)) {
                    if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG))
                        sipStack.getStackLogger().logDebug(
                                "Dropping out of sequence PRACK ");
                    if (transaction != null) {
                        sipStack.removeTransaction(transaction);
                        transaction.releaseSem();
                    }
                    return;
                } else {
                    try {
                        sipStack.addTransaction(transaction);
                        dialog.addTransaction(transaction);
                        dialog.addRoute(sipRequest);
                        transaction.setDialog(dialog, dialogId);
                    } catch (Exception ex) {
                        InternalErrorHandler.handleException(ex);
                    }
                }
            } else {
                if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG))
                    sipStack
                            .getStackLogger()
                            .logDebug(
                                    "Processing PRACK without a DIALOG -- this must be a proxy element");
            }

        } else if (sipRequestMethod.equals(Request.BYE)) {
            // Check for correct sequence numbering of the BYE
            if (dialog != null && !dialog.isRequestConsumable(sipRequest)) {
                if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG))
                    sipStack.getStackLogger().logDebug(
                            "Dropping out of sequence BYE "
                                    + dialog.getRemoteSeqNumber() + " "
                                    + sipRequest.getCSeq().getSeqNumber());

                if (dialog.getRemoteSeqNumber() >= sipRequest.getCSeq()
                        .getSeqNumber()
                        && transaction.getInternalState() == TransactionState._TRYING) {

                    this.sendServerInternalErrorResponse(sipRequest,
                            transaction);

                }
                // If the stack knows about the tx, then remove it.
                if (transaction != null)
                    sipStack.removeTransaction(transaction);
                return;

            } else if (dialog == null
                    && sipProvider.isAutomaticDialogSupportEnabled()) {
                // Drop bye's with 481 if dialog does not exist.
                // If dialog support is enabled then
                // there must be a dialog associated with the bye
                // No dialog could be found and requests on this
                // provider. Must act like a user agent -- so drop the request.
                // NOTE: if Automatic dialog support is not enabled,
                // then it is the application's responsibility to
                // take care of this error condition possibly.

                SIPResponse response = sipRequest
                        .createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST);
                response.setReasonPhrase("Dialog Not Found");

                if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG))
                    sipStack
                            .getStackLogger()
                            .logDebug(
                                    "dropping request -- automatic dialog "
                                            + "support enabled and dialog does not exist!");
                try {
                    transaction.sendResponse(response);
                } catch (SipException ex) {
                    sipStack.getStackLogger().logError(
                            "Error in sending response", ex);
                }
                // If the stack knows about the tx, then remove it.
                if (transaction != null) {
                    sipStack.removeTransaction(transaction);
                    transaction.releaseSem();
                    transaction = null;
                }
                return;

            }

            // note that the transaction may be null (which
            // happens when no dialog for the bye was found.
            // and automatic dialog support is disabled (i.e. the app wants
            // to manage its own dialog layer.
            if (transaction != null && dialog != null) {
                try {
                    if (sipProvider == dialog.getSipProvider()) {
                        sipStack.addTransaction(transaction);
                        dialog.addTransaction(transaction);
                        transaction.setDialog(dialog, dialogId);
                    }

                } catch (IOException ex) {
                    InternalErrorHandler.handleException(ex);
                }
            }
            if (sipStack.isLoggingEnabled()) {
                sipStack.getStackLogger().logDebug(
                        "BYE Tx = " + transaction + " isMapped ="
                                + transaction.isTransactionMapped());
            }

        } else if (sipRequestMethod.equals(Request.CANCEL)) {

            SIPServerTransaction st = (SIPServerTransaction) sipStack
                    .findCancelTransaction(sipRequest, true);
            if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
                sipStack.getStackLogger().logDebug(
                        "Got a CANCEL, InviteServerTx = " + st
                                + " cancel Server Tx ID = " + transaction
                                + " isMapped = "
                                + transaction.isTransactionMapped());

            }
            // Processing incoming CANCEL.
            // Check if we can process the CANCEL request.
            if (sipRequest.getMethod().equals(Request.CANCEL)) {
                // If the CANCEL comes in too late, there's not
                // much that the Listener can do so just do the
                // default action and avoid bothering the listener.
                if (st != null
                        && st.getInternalState() == TransactionState._TERMINATED) {
                    // If transaction already exists but it is
                    // too late to cancel the transaction then
                    // just respond OK to the CANCEL and bail.
                    if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG))
                        sipStack.getStackLogger().logDebug(
                                "Too late to cancel Transaction");
                    // send OK and just ignore the CANCEL.
                    try {

                        transaction.sendResponse(sipRequest
                                .createResponse(Response.OK));
                    } catch (Exception ex) {
                        if (ex.getCause() != null
                                && ex.getCause() instanceof IOException) {
                            st.raiseIOExceptionEvent();
                        }
                    }
                    return;
                }
                if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG))
                    sipStack.getStackLogger().logDebug(
                            "Cancel transaction = " + st);

            }
            if (transaction != null && st != null && st.getDialog() != null) {
                // Found an invite tx corresponding to the CANCEL.
                // Set up the client tx and pass up to listener.
                transaction.setDialog((SIPDialog) st.getDialog(), dialogId);
                dialog = (SIPDialog) st.getDialog();
            } else if (st == null
                    && sipProvider.isAutomaticDialogSupportEnabled()
                    && transaction != null) {
                // Could not find a invite tx corresponding to the CANCEL.
                // Automatic dialog support is enabled so I must behave like
                // an endpoint on this provider.
                // Send the error response for the cancel.

                SIPResponse response = sipRequest
                        .createResponse(Response.CALL_OR_TRANSACTION_DOES_NOT_EXIST);
                if (sipStack.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
                    sipStack.getStackLogger().logDebug(
                            "dropping request -- automatic dialog support "
                                    + "enabled and INVITE ST does not exist!");
View Full Code Here

     * @param messageToSend Response to process and send.
     */
    public void sendMessage(SIPMessage messageToSend) throws IOException {
        try {
            // Message typecast as a response
            final SIPResponse  transactionResponse = (SIPResponse) messageToSend;
            // Status code of the response being sent to the client
            final int statusCode = transactionResponse.getStatusCode();

            try {
                // Provided we have set the banch id for this we set the BID for
                // the
                // outgoing via.
                if (originalRequestBranch != null)
                    transactionResponse.getTopmostVia().setBranch(this.getBranch());
                else
                    transactionResponse.getTopmostVia().removeParameter(ParameterNames.BRANCH);

                // Make the topmost via headers match identically for the
                // transaction rsponse.
                if (!originalRequestHasPort)
                    transactionResponse.getTopmostVia().removePort();
            } catch (ParseException ex) {
                ex.printStackTrace();
            }

            // Method of the response does not match the request used to
            // create the transaction - transaction state does not change.
            if (!transactionResponse.getCSeq().getMethod().equals(
                    getMethod())) {
                sendResponse(transactionResponse);
                return;
            }

            if(!checkStateTimers(statusCode)) {
              return;
            }

            try {
                // Send the message to the client.
                // Record the last message sent out.
                if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                    sipStack.getStackLogger().logDebug(
                            "sendMessage : tx = " + this + " getState = " + this.getState());
                }
                lastResponse = transactionResponse;
            lastResponseStatusCode = transactionResponse.getStatusCode();

            this.sendResponse(transactionResponse);

            } catch (IOException e) {

View Full Code Here

TOP

Related Classes of gov.nist.javax.sip.message.SIPResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.