Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Conditions Of Use
    *
    * This software was developed by employees of the National Institute of
    * Standards and Technology (NIST), an agency of the Federal Government.
    * Pursuant to title 15 Untied States Code Section 105, works of NIST
    * employees are not subject to copyright protection in the United States
    * and are considered to be in the public domain.  As a result, a formal
    * license is not needed to use the software.
   *
   * This software is provided by NIST as a service and is expressly
   * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
   * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
   * AND DATA ACCURACY.  NIST does not warrant or make any representations
   * regarding the use of the software or the results thereof, including but
   * not limited to the correctness, accuracy, reliability or usefulness of
   * the software.
   *
   * Permission to use this software is contingent upon your acceptance
   * of the terms of this agreement
   *
   * .
   *
   */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
  
  package gov.nist.javax.sip;
  
  
  
  
  /*
   * Bug fixes and Contributions by Lamine Brahimi, Andreas Bystrom, Bill Roome, John Martin, Daniel
   * Machin Vasquez-Illa, Antonis Karydas, Joe Provino, Bruce Evangelder, Jeroen van Bemmel, Robert
   * S. Rosen, Vladimir Ralev
   */
An adapter class from the JAIN implementation objects to the NIST-SIP stack. The primary purpose of this class is to do early rejection of bad messages and deliver meaningful messages to the application. This class is essentially a Dialog filter. It is a helper for the UAC Core. It checks for and rejects requests and responses which may be filtered out because of sequence number, Dialog not found, etc. Note that this is not part of the JAIN-SIP spec (it does not implement a JAIN-SIP interface). This is part of the glue that ties together the NIST-SIP stack and event model with the JAIN-SIP stack. This is strictly an implementation class.

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.97 $ $Date: 2010-12-02 22:04:18 $
  
  	
  	private static StackLogger logger = CommonLogger.getLogger(DialogFilter.class);
  
      protected SIPTransaction transactionChannel;
  
      protected ListeningPointImpl listeningPoint;
 
     private SIPTransactionStack sipStack;
 
     public DialogFilter(SIPTransactionStack sipStack) {
         this. = sipStack;
 
     }

    
Send back a Request Pending response.

Parameters:
sipRequest
transaction
 
     private void sendRequestPendingResponse(SIPRequest sipRequest,
             SIPServerTransaction transaction) {
         if (transaction.getState() != .) {
             SIPResponse sipResponse = sipRequest
                     .createResponse(.);
             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(.)) {
                     .addTransactionPendingAck(transaction);
                 }
                 transaction.sendResponse(sipResponse);
                 transaction.releaseSem();
             } catch (Exception ex) {
                 .logError(
                         "Problem sending error response"ex);
                 transaction.releaseSem();
                 .removeTransaction(transaction);
             }
         }
     }

    
Send a BAD REQUEST response.

Parameters:
sipRequest
transaction
reasonPhrase
 
 
     private void sendBadRequestResponse(SIPRequest sipRequest,
             SIPServerTransaction transactionString reasonPhrase) {
         if (transaction.getState() != .) {
 
             SIPResponse sipResponse = sipRequest
                     .createResponse(.);
             if (reasonPhrase != null)
                 sipResponse.setReasonPhrase(reasonPhrase);
             ServerHeader serverHeader = MessageFactoryImpl
                     .getDefaultServerHeader();
             if (serverHeader != null) {
                 sipResponse.setHeader(serverHeader);
             }
             try {
                 if (sipRequest.getMethod().equals(.)) {
                     .addTransactionPendingAck(transaction);
                 }
                 transaction.sendResponse(sipResponse);
                 transaction.releaseSem();
             } catch (Exception ex) {
                 .logError(
                         "Problem sending error response"ex);
                 transaction.releaseSem();
                 .removeTransaction(transaction);
 
             }
         }
     }

    
Send a CALL OR TRANSACTION DOES NOT EXIST response.

Parameters:
sipRequest
transaction
 
 
             SIPRequest sipRequestSIPServerTransaction transaction) {
 
         if (transaction.getState() != .) {
             SIPResponse sipResponse = sipRequest
                     .createResponse(.);
 
             ServerHeader serverHeader = MessageFactoryImpl
                     .getDefaultServerHeader();
             if (serverHeader != null) {
                 sipResponse.setHeader(serverHeader);
             }
             try {
                 if (sipRequest.getMethod().equals(.)) {
                     .addTransactionPendingAck(transaction);
                 }
                 transaction.sendResponse(sipResponse);
                 transaction.releaseSem();
             } catch (Exception ex) {
                 .logError(
                         "Problem sending error response"ex);
                 transaction.releaseSem();
                 .removeTransaction(transaction);
 
             }
 
         }
     }

    
Send back a LOOP Detected Response.

Parameters:
sipRequest
transaction
 
     private void sendLoopDetectedResponse(SIPRequest sipRequest,
             SIPServerTransaction transaction) {
         SIPResponse sipResponse = sipRequest
                 .createResponse(.);
         if (transaction.getState() != .) {
 
             ServerHeader serverHeader = MessageFactoryImpl
                     .getDefaultServerHeader();
             if (serverHeader != null) {
                 sipResponse.setHeader(serverHeader);
             }
             try {
                 .addTransactionPendingAck(transaction);
                 transaction.sendResponse(sipResponse);
                 transaction.releaseSem();
             } catch (Exception ex) {
                 .logError(
                         "Problem sending error response"ex);
                 transaction.releaseSem();
                 .removeTransaction(transaction);
 
             }
         }
 
     }

    
Send back an error Response.

Parameters:
sipRequest
transaction
 
 
     private void sendServerInternalErrorResponse(SIPRequest sipRequest,
             SIPServerTransaction transaction) {
         if (transaction.getState() != .) {
             if (.isLoggingEnabled(.))
                 .logDebug(
                         "Sending 500 response for out of sequence message");
             SIPResponse sipResponse = sipRequest
                     .createResponse(.);
             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);
                 .addTransactionPendingAck(transaction);
                 transaction.sendResponse(sipResponse);
                 transaction.releaseSem();
             } catch (Exception ex) {
                 .logError("Problem sending response",
                         ex);
                 transaction.releaseSem();
                 .removeTransaction(transaction);
             }
         }
     }

    
Process a request. Check for various conditions in the dialog that can result in the message being dropped. Possibly return errors for these conditions.

Throws:
SIPServerException is thrown when there is an error processing the request.
 
     public void processRequest(SIPRequest sipRequest,
             MessageChannel incomingMessageChannel) {
         // Generate the wrapper JAIN-SIP object.
                 &&  != null)
             .logDebug(
                     "PROCESSING INCOMING REQUEST " + sipRequest
                             + " transactionChannel = " + 
                             + " listening point = "
                             + .getIPAddress() + ":"
                             + .getPort());
         if ( == null) {
             if (.isLoggingEnabled(.))
                 .logDebug(
                         "Dropping message: No listening point registered!");
             return;
         }
 
                 .getSIPStack();
 
         SipProviderImpl sipProvider = .getProvider();
         if (sipProvider == null) {
             if (.isLoggingEnabled(.))
                 .logDebug("No provider - dropping !!");
             return;
         }
 
         if (sipStack == null)
             InternalErrorHandler.handleException("Egads! no sip stack!");
 
         // Look for the registered SIPListener for the message channel.
 
         SIPServerTransaction transaction = (SIPServerTransactionthis.;
         if (transaction != null) {
             if (.isLoggingEnabled(.))
                 .logDebug(
                         "transaction state = " + transaction.getState());
         }
         final String dialogId = sipRequest.getDialogId(true);
         SIPDialog dialog = sipStack.getDialog(dialogId);
         /*
          * Check if we got this request on the contact address of the dialog If
          * not the dialog does not belong to this request. We check this
          * condition if a contact address has been assigned to the dialog.
          * Forgive the sins of B2BUA's that like to record route ACK's
          */
         if (dialog != null && sipProvider != dialog.getSipProvider()) {
             final Contact contact = dialog.getMyContactHeader();
             if (contact != null) {
                 SipUri contactUri = (SipUri) (contact.getAddress().getURI());
                 String ipAddress = contactUri.getHost();
                 int contactPort = contactUri.getPort();
                 String contactTransport = contactUri.getTransportParam();
                 if (contactTransport == null)
                     contactTransport = "udp";
                 if (contactPort == -1) {
                     if (contactTransport.equals("udp")
                             || contactTransport.equals("tcp"))
                         contactPort = 5060;
                     else
                         contactPort = 5061;
                 }
                 // Check if the dialog contact is the same as the provider on
                 // which we got the request. Otherwise, dont assign this
                 // dialog to the request.
                 if (ipAddress != null
                         && (!ipAddress.equals(.getIPAddress()) || contactPort != 
                                 .getPort())) {
                     if (.isLoggingEnabled(.)) {
                         .logDebug(
                                 "nulling dialog -- listening point mismatch!  "
                                         + contactPort + "  lp port = "
                                         + .getPort());
 
                     }
                     dialog = null;
                 }
 
             }
         }
 
         /*
          * RFC 3261 8.2.2.2 Merged requests: If the request has no tag in the To
          * header field, the UAS core MUST check the request against ongoing
          * transactions. If the From tag, Call-ID, and CSeq exactly match those
          * associated with an ongoing transaction, but the request does not
          * match that transaction (based on the matching rules in Section
          * 17.2.3), the UAS core SHOULD generate a 482 (Loop Detected) response
          * and pass it to the server transaction. This support is only enabled
          * when the stack has been instructed to function with Automatic Dialog
          * Support.
          */
         if (sipProvider.isDialogErrorsAutomaticallyHandled()
                 && sipRequest.getToTag() == null) {
             if (sipStack.findMergedTransaction(sipRequest)) {
                 this.sendLoopDetectedResponse(sipRequesttransaction);
                 return;
             }
         }
 
         if (.isLoggingEnabled(.)) {
             .logDebug("dialogId = " + dialogId);
             .logDebug("dialog = " + dialog);
         }
 
         /*
          * RFC 3261 Section 16.4 If the first value in the Route header field
          * indicates this proxy,the proxy MUST remove that value from the
          * request .
          */
 
         // If the message is being processed
         // by a Proxy, then the proxy will take care of stripping the
         // Route header. If the request is being processed by an
         // endpoint, then the stack strips off the route header.
         if (sipRequest.getHeader(.) != null
                 && transaction.getDialog() != null) {
             final RouteList routes = sipRequest.getRouteHeaders();
             final Route route = (Routeroutes.getFirst();
             final SipUri uri = (SipUriroute.getAddress().getURI();
             final HostPort hostPort = uri.getHostPort();
             int port;
             if (hostPort.hasPort()) {
                 port = hostPort.getPort();
             } else {
                 if (.getTransport().equalsIgnoreCase(
                         .))
                     port = 5061;
                 else
                     port = 5060;
             }
             String host = hostPort.getHost().encode();
             if ((host.equals(.getIPAddress()) || host
                     .equalsIgnoreCase(.getSentBy()))
                     && port == .getPort()) {
                 if (routes.size() == 1)
                     sipRequest.removeHeader(.);
                 else
                     routes.removeFirst();
             }
         }
         final String sipRequestMethod = sipRequest.getMethod();
         if (sipRequestMethod.equals(.) && dialog != null
                 && sipProvider.isDialogErrorsAutomaticallyHandled()) {
             /*
              * An agent responding to a REFER method MUST return a 400 (Bad
              * Request) if the request contained zero or more than one Refer-To
              * header field values.
              */
             ReferToHeader sipHeader = (ReferToHeadersipRequest
                     .getHeader(.);
             if (sipHeader == null) {
                 this.sendBadRequestResponse(sipRequesttransaction,
                         "Refer-To header is missing");
                 return;
 
             }
 
             /*
              * A refer cannot be processed until previous transaction has been
              * completed.
              */
             SIPTransaction lastTransaction = ((SIPDialogdialog)
                     .getLastTransaction();
             if (lastTransaction != null
                     && sipProvider.isDialogErrorsAutomaticallyHandled()) {               
                 final String lastTransactionMethod = lastTransaction.getMethod();
                 if (lastTransaction instanceof SIPServerTransaction) {
                     // Handle Pseudo State Trying on Server Transaction
                     if ((lastTransaction.getInternalState() == .
                                     || lastTransaction.getInternalState() == .)
                             && lastTransactionMethod.equals(.)) {
                         this
                                 .sendRequestPendingResponse(sipRequest,
                                         transaction);
                         return;
                     }
                 } else if (lastTransaction instanceof SIPClientTransaction) {
                     if (lastTransactionMethod.equals(.)
                             && lastTransaction.getInternalState() != .
                             && lastTransaction.getInternalState() != .) {
                         this
                                 .sendRequestPendingResponse(sipRequest,
                                         transaction);
                         return;
                     }
                 }
             }
 
         } else if (sipRequestMethod.equals(.)) {
             /*
              * Got an UPDATE method and the user dialog does not exist and the
              * user wants to be a User agent.
              */
             if (sipProvider.isAutomaticDialogSupportEnabled() && dialog == null) {
                 this.sendCallOrTransactionDoesNotExistResponse(sipRequest,
                         transaction);
                 return;
             }
         } else if (sipRequestMethod.equals(.)) {
 
             if (transaction != null && transaction.isInviteTransaction()) {
                 // This is an ack for a 3xx-6xx response. Just let the tx laer
                 // take care of it.
                 if (.isLoggingEnabled(.))
                     .logDebug(
                             "Processing ACK for INVITE Tx ");
 
             } else {
                 if (.isLoggingEnabled(.))
                     .logDebug(
                             "Processing ACK for dialog " + dialog);
 
                 if (dialog == null) {
                     if (.isLoggingEnabled(.)) {
                         .logDebug(
                                 "Dialog does not exist "
                                         + sipRequest.getFirstLine()
                                         + " isServerTransaction = " + true);
 
                     }
                     SIPServerTransaction st = sipStack
                             .getRetransmissionAlertTransaction(dialogId);
                     if (st != null && st.isRetransmissionAlertEnabled()) {
                         st.disableRetransmissionAlerts();
 
                     }
                     /*
                      * JvB: must never drop ACKs that dont match a transaction!
                      * One cannot be sure if it isn't an ACK for a 2xx response
                      */
                     SIPServerTransaction ackTransaction = sipStack
                             .findTransactionPendingAck(sipRequest);
                     /*
                      * Found a transaction ( that we generated ) which is
                      * waiting for ACK. So ACK it and return.
                      */
                     if (ackTransaction != null) {
                         if (.isLoggingEnabled(.))
                             .logDebug(
                                     "Found Tx pending ACK");
                         try {
                             ackTransaction.setAckSeen();
                             sipStack.removeTransaction(ackTransaction);
                             sipStack
                                     .removeTransactionPendingAck(ackTransaction);
                         } catch (Exception ex) {
                             if (.isLoggingEnabled()) {
                                 .logError(
                                         "Problem terminating transaction"ex);
                             }
                         }
                         return;
                     }
 
                 } else {
                     if (!dialog.handleAck(transaction)) {
                         if (!dialog.isSequnceNumberValidation()) {
                             if (.isLoggingEnabled(.)) {
                                 .logDebug(
                                         "Dialog exists with loose dialog validation "
                                                 + sipRequest.getFirstLine()
                                                 + " isServerTransaction = "
                                                 + true + " dialog = "
                                                 + dialog.getDialogId());
 
                             }
                             SIPServerTransaction st = sipStack
                                     .getRetransmissionAlertTransaction(dialogId);                           
                             if (st != null && st.isRetransmissionAlertEnabled()) {
                             	st.disableRetransmissionAlerts();
 
                             }
                             // Issue 319 : https://jain-sip.dev.java.net/issues/show_bug.cgi?id=319
                             // remove the pending ack to stop the transaction timer for transaction
                             // where the stack replied with a final error response.
                             SIPServerTransaction ackTransaction = sipStack
                                     .findTransactionPendingAck(sipRequest);
                             /*
                              * Found a transaction ( that we generated ) which is
                              * waiting for ACK. So ACK it and return.
                              */
                             if (ackTransaction != null) {
                                 if (.isLoggingEnabled(.))
                                     .logDebug(
                                             "Found Tx pending ACK");
                                 try {
                                     ackTransaction.setAckSeen();
                                     sipStack.removeTransaction(ackTransaction);
                                     sipStack
                                             .removeTransactionPendingAck(ackTransaction);
                                 } catch (Exception ex) {
                                     if (.isLoggingEnabled()) {
                                         .logError(
                                                 "Problem terminating transaction"ex);
                                     }
                                 }
                             }
                         } else {
                             if (
                                     .isLoggingEnabled(.)) {
                                 
                                         .logDebug(
                                                 "Dropping ACK - cannot find a transaction or dialog");
                             }
                             SIPServerTransaction ackTransaction = sipStack
                                     .findTransactionPendingAck(sipRequest);
                             if (ackTransaction != null) {
                                 if (.isLoggingEnabled(.))
                                     .logDebug(
                                             "Found Tx pending ACK");
                                 try {
                                     ackTransaction.setAckSeen();
                                     sipStack.removeTransaction(ackTransaction);
                                     sipStack
                                             .removeTransactionPendingAck(ackTransaction);
                                 } catch (Exception ex) {
                                     if (.isLoggingEnabled()) {
                                         
                                                 .logError(
                                                         "Problem terminating transaction",
                                                         ex);
                                     }
                                 }
                             }
                             /*
                              * For test only we support a flag that will deliver
                              * retransmitted ACK for 200 OK responses to the
                              * listener.
                              */
                             if ((!sipStack
                                     .isDeliverRetransmittedAckToListener())
                                     || (ackTransaction != null && !sipStack
                                             .isNon2XXAckPassedToListener())) {
                                 return;
                             }
                         }
                     } else {
 
                         dialog.addTransaction(transaction);
                         transaction.passToListener();
                         dialog.addRoute(sipRequest);
                         transaction.setDialog(dialogdialogId);
                         if (sipRequest.getMethod().equals(.)
                                 && sipProvider
                                         .isDialogErrorsAutomaticallyHandled()) {
                             sipStack.putInMergeTable(transactionsipRequest);
                         }
                         /*
                          * Note that ACK is a pseudo transaction. It is never
                          * added to the stack and you do not get transaction
                          * terminated events on ACK.
                          */
 
                         if (sipStack.isDeliverTerminatedEventForAck()) {
                             try {
                                 sipStack.addTransaction(transaction);
                                 transaction.scheduleAckRemoval();
                             } catch (IOException ex) {
 
                             }
                         } else {
                             transaction.setMapped(true);
                         }
 
                     }
                 }
             }
         } else if (sipRequestMethod.equals(.)) {
 
             /*
              * RFC 3262: A matching PRACK is defined as one within the same
              * dialog as the response, and whose method, CSeq-num, and
              * response-num in the RAck header field match, respectively, the
              * method from the CSeq, the sequence number from the CSeq, and the
              * sequence number from the RSeq of the reliable provisional
              * response.
              */
 
             if (.isLoggingEnabled(.))
                 .logDebug(
                         "Processing PRACK for dialog " + dialog);
 
             if (dialog == null && sipProvider.isAutomaticDialogSupportEnabled()) {
                 if (.isLoggingEnabled(.)) {
                     .logDebug(
                             "Dialog does not exist "
                                     + sipRequest.getFirstLine()
                                     + " isServerTransaction = " + true);
 
                 }
                 if (.isLoggingEnabled(.)) {
                     
                             .logDebug(
                                     "Sending 481 for PRACK - automatic dialog support is enabled -- cant find dialog!");
                 }
                 SIPResponse notExist = sipRequest
                         .createResponse(.);
 
                 try {
                     sipProvider.sendResponse(notExist);
                 } catch (SipException e) {
                     .logError(
                             "error sending response"e);
                 }
                 if (transaction != null) {
                     sipStack.removeTransaction(transaction);
                     transaction.releaseSem();
                 }
                 return;
 
             } else if (dialog != null) {
                 if (!dialog.handlePrack(sipRequest)) {
                     if (.isLoggingEnabled(.))
                         .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(dialogdialogId);
                     } catch (Exception ex) {
                         InternalErrorHandler.handleException(ex);
                     }
                 }
             } else {
                 if (.isLoggingEnabled(.))
                     
                             .logDebug(
                                     "Processing PRACK without a DIALOG -- this must be a proxy element");
             }
 
         } else if (sipRequestMethod.equals(.)) {
             // Check for correct sequence numbering of the BYE
             if (dialog != null && !dialog.isRequestConsumable(sipRequest)) {
                 if (.isLoggingEnabled(.))
                     .logDebug(
                             "Dropping out of sequence BYE "
                                     + dialog.getRemoteSeqNumber() + " "
                                     + sipRequest.getCSeq().getSeqNumber());
 
                 if (dialog.getRemoteSeqNumber() >= sipRequest.getCSeq()
                         .getSeqNumber()
                         && transaction.getInternalState() == .) {
 
                     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.setReasonPhrase("Dialog Not Found");
 
                 if (.isLoggingEnabled(.))
                     
                             .logDebug(
                                     "dropping request -- automatic dialog "
                                             + "support enabled and dialog does not exist!");
                 try {
                     transaction.sendResponse(response);
                 } catch (SipException ex) {
                     .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(dialogdialogId);
                     }
 
                 } catch (IOException ex) {
                     InternalErrorHandler.handleException(ex);
                 }
             }
             if (.isLoggingEnabled(.)) {
                 .logDebug(
                         "BYE Tx = " + transaction + " isMapped ="
                                 + transaction.isTransactionMapped());
             }
 
         } else if (sipRequestMethod.equals(.)) {
 
             SIPServerTransaction st = (SIPServerTransactionsipStack
                     .findCancelTransaction(sipRequesttrue);
             if (.isLoggingEnabled(.)) {
                 .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(.)) {
                 // 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() == .) {
                     // If transaction already exists but it is
                     // too late to cancel the transaction then
                     // just respond OK to the CANCEL and bail.
                     if (.isLoggingEnabled(.))
                         .logDebug(
                                 "Too late to cancel Transaction");
                     // send OK and just ignore the CANCEL.
                     try {
 
                         transaction.sendResponse(sipRequest
                                 .createResponse(.));
                     } catch (Exception ex) {
                         if (ex.getCause() != null
                                 && ex.getCause() instanceof IOException) {
                             st.raiseIOExceptionEvent();
                         }
                     }
                     return;
                 }
                 if (.isLoggingEnabled(.))
                     .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((SIPDialogst.getDialog(), dialogId);
                 dialog = (SIPDialogst.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(.);
                 if (.isLoggingEnabled(.)) {
                     .logDebug(
                             "dropping request -- automatic dialog support "
                                     + "enabled and INVITE ST does not exist!");
                 }
                 try {
                     sipProvider.sendResponse(response);
                 } catch (SipException ex) {
                     InternalErrorHandler.handleException(ex);
                 }
                 if (transaction != null) {
                     sipStack.removeTransaction(transaction);
                     transaction.releaseSem();
                 }
                 return;
 
             }
 
             // INVITE was handled statefully so the CANCEL must also be
             // statefully handled.
             if (st != null) {
                 try {
                     if (transaction != null) {
                         sipStack.addTransaction(transaction);
                         transaction.setPassToListener();
                         transaction.setInviteTransaction(st);
                         // Dont let the INVITE and CANCEL be concurrently
                         // processed.
                         st.acquireSem();
 
                     }
 
                 } catch (Exception ex) {
                     InternalErrorHandler.handleException(ex);
                 }
             }
         } else if (sipRequestMethod.equals(.)) {
             SIPTransaction lastTransaction = dialog == null ? null : dialog
                     .getInviteTransaction();
 
             /*
              * RFC 3261 Chapter 14. A UAS that receives a second INVITE before
              * it sends the final response to a first INVITE with a lower CSeq
              * sequence number on the same dialog MUST return a 500 (Server
              * Internal Error) response to the second INVITE and MUST include a
              * Retry-After header field with a randomly chosen value of between
              * 0 and 10 seconds.
              */
 
             if (dialog != null
                     && transaction != null
                     && lastTransaction != null
                     && sipRequest.getCSeq().getSeqNumber() > lastTransaction.getCSeq()
                     && lastTransaction instanceof SIPServerTransaction
                     && sipProvider.isDialogErrorsAutomaticallyHandled()
                     && dialog.isSequnceNumberValidation()
                     && lastTransaction.isInviteTransaction()
                     && lastTransaction.getInternalState() != .
                     && lastTransaction.getInternalState() != .
                     && lastTransaction.getInternalState() != .) {
 
                 if (.isLoggingEnabled(.)) {
                     .logDebug(
                             "Sending 500 response for out of sequence message");
                 }
                 this.sendServerInternalErrorResponse(sipRequesttransaction);
                 return;
 
             }
 
             /*
              * Saw an interleaved invite before ACK was sent. RFC 3261 Chapter
              * 14. A UAS that receives an INVITE on a dialog while an INVITE it
              * had sent on that dialog is in progress MUST return a 491 (Request
              * Pending) response to the received INVITE.
              */
             lastTransaction = (dialog == null ? null : dialog
                     .getLastTransaction());
 
             if (dialog != null
                     && sipProvider.isDialogErrorsAutomaticallyHandled()
                     && lastTransaction != null
                     && lastTransaction.isInviteTransaction()
                     && lastTransaction instanceof ClientTransaction
                     && lastTransaction.getState() != . 
                     && lastTransaction.getState() != .)
                      {
                 if (.isLoggingEnabled(.)) {
                 	.logDebug("DialogFilter::processRequest:lastTransaction.getState(): " + lastTransaction.getState() +       
                                     " Sending 491 response for clientTx.");
                 }
                 this.sendRequestPendingResponse(sipRequesttransaction);
                 return;
             }
 
             if ( dialog != null
                     && lastTransaction != null
                     && sipProvider.isDialogErrorsAutomaticallyHandled()
                     && lastTransaction.isInviteTransaction()
                     && lastTransaction instanceof ServerTransaction
                     && sipRequest.getCSeq().getSeqNumber() > lastTransaction.getCSeq()
                     // Handle Pseudo State Trying on Server Transaction
                     && (lastTransaction.getInternalState() == .
                                     || lastTransaction.getInternalState() == .)) {
                 // Note that the completed state will be reached when we have
                 // sent an error response and the terminated state will be reached when we
                 // have sent an OK response. We do not need to wait till the ACK to be seen.
                 if (.isLoggingEnabled(.)) {
                     
                             .logDebug(
                                     "Sending 491 response. Last transaction is in PROCEEDING state.");
                     .logDebug(
                             "last Transaction state = " + lastTransaction
                                     + " state " + lastTransaction.getState());
                 }
                 this.sendRequestPendingResponse(sipRequesttransaction);
                 return;
 
             }
         }
 
         // Sequence numbers are supposed to be incremented
         // sequentially within a dialog for RFC 3261
         // Note BYE, CANCEL and ACK is handled above - so no check here.
 
         if (.isLoggingEnabled(.)) {
             .logDebug(
                     "CHECK FOR OUT OF SEQ MESSAGE " + dialog + " transaction "
                            + transaction);
        }
        if (dialog != null && transaction != null
                && !sipRequestMethod.equals(.)
                && !sipRequestMethod.equals(.)
                && !sipRequestMethod.equals(.)
                && !sipRequestMethod.equals(.)) {
            if (!dialog.isRequestConsumable(sipRequest)) {
                /*
                 * RFC 3261: "UAS Behavior" section (12.2.2): If the remote
                 * sequence number was not empty, but the sequence number of the
                 * request is lower than the remote sequence number, the request
                 * is out of order and MUST be rejected with a 500 (Server
                 * Internal Error) response.
                 */
                // Drop the request
                if (.isLoggingEnabled(.)) {
                    .logDebug(
                            "Dropping out of sequence message "
                                    + dialog.getRemoteSeqNumber() + " "
                                    + sipRequest.getCSeq());
                }
                // send error when stricly higher, ignore when ==
                // (likely still processing, error would interrupt that)
                /*
                 * && (transaction.getState() == TransactionState.TRYING ||
                 * transaction .getState() == TransactionState.PROCEEDING)
                 */
                if (dialog.getRemoteSeqNumber() > sipRequest.getCSeq()
                        .getSeqNumber()
                        && sipProvider.isDialogErrorsAutomaticallyHandled()) {
                    this.sendServerInternalErrorResponse(sipRequest,
                            transaction);
                } else {
                    try {
                        transaction.terminate();
                    } catch (ObjectInUseException e) {
                        if (.isLoggingEnabled()) {
                            .logError(
                                    "Unexpected exception"e);
                        }
                    }
                }
                return;
            }
            try {
                if (sipProvider == dialog.getSipProvider()) {
                    sipStack.addTransaction(transaction);
                    // This will set the remote sequence number.
                    if (!dialog.addTransaction(transaction)) {
                        return;
                    }
                    dialog.addRoute(sipRequest);
                    transaction.setDialog(dialogdialogId);
                }
            } catch (IOException ex) {
                transaction.raiseIOExceptionEvent();