Author: jean.deruelle
Date: Fri Apr 10 12:21:28 2009
New Revision: 5430

Modified:
trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/B2buaHelperImpl.java trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java

Log:
Fixing NPE discovered during perf test

Modified: trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
==============================================================================
--- trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java (original) +++ trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java Fri Apr 10 12:21:28 2009
@@ -711,13 +711,15 @@
                if(!isSupervisedMode()) {
                        return false;
                } else {
-                       for (Transaction transaction : ongoingTransactions) {
-                               
if(TransactionState.CALLING.equals(transaction.getState()) ||
-                                       
TransactionState.TRYING.equals(transaction.getState()) ||
-                                       
TransactionState.PROCEEDING.equals(transaction.getState()) ||
-                                       
TransactionState.COMPLETED.equals(transaction.getState()) ||
-                                       
TransactionState.CONFIRMED.equals(transaction.getState())) {
-                                               return true;
+                       if(ongoingTransactions != null) {
+                               for (Transaction transaction : 
ongoingTransactions) {
+                                       
if(TransactionState.CALLING.equals(transaction.getState()) ||
+                                               
TransactionState.TRYING.equals(transaction.getState()) ||
+                                               
TransactionState.PROCEEDING.equals(transaction.getState()) ||
+                                               
TransactionState.COMPLETED.equals(transaction.getState()) ||
+                                               
TransactionState.CONFIRMED.equals(transaction.getState())) {
+                                                       return true;
+                                       }
                                }
                        }
                        return false;
@@ -991,7 +993,7 @@
         */
        public void addOngoingTransaction(Transaction transaction) {
                
-               if(!ongoingTransactions.contains(transaction)) {
+ if(ongoingTransactions != null && !ongoingTransactions.contains(transaction)) {
                        this.ongoingTransactions.add(transaction);
                        if(logger.isDebugEnabled()) {
logger.debug("transaction "+ transaction +" has been added to sip session's ongoingTransactions" );

Modified: trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/B2buaHelperImpl.java
==============================================================================
--- trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/B2buaHelperImpl.java (original) +++ trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/B2buaHelperImpl.java Fri Apr 10 12:21:28 2009
@@ -24,6 +24,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;

 import javax.servlet.sip.B2buaHelper;
@@ -405,19 +406,22 @@
                MobicentsSipSession sipSessionImpl = (MobicentsSipSession) 
session;
                List<SipServletMessage> retval = new 
ArrayList<SipServletMessage> ();
                if (mode.equals(UAMode.UAC)) {
- for ( Transaction transaction: sipSessionImpl.getOngoingTransactions()) {
-                               if ( transaction instanceof ClientTransaction) {
- TransactionApplicationData tad = (TransactionApplicationData) transaction.getApplicationData();
-                                       SipServletMessage sipServletMessage = 
tad.getSipServletMessage();
- //not specified if ACK is a committed message in the spec but it seems not since Proxy api test - //testCanacel101 method adds a header to the ACK and it cannot be on a committed message - //so we don't want to return ACK as pending messages here. related to TCK test B2BUAHelper.testCreateRequest002 - if (!sipServletMessage.isCommitted() && !Request.ACK.equals(sipServletMessage.getMethod()) && !Request.PRACK.equals(sipServletMessage.getMethod())) {
-                                               retval.add(sipServletMessage);
-                                       }
- for(SipServletResponseImpl sipServletResponseImpl : tad.getSipServletResponses()) {
-                                               if 
(!sipServletResponseImpl.isCommitted()) {
-                                                       
retval.add(sipServletResponseImpl);
+ Set<Transaction> ongoingTransactions = sipSessionImpl.getOngoingTransactions();
+                       if(ongoingTransactions != null) {
+                               for ( Transaction transaction: 
ongoingTransactions) {
+                                       if ( transaction instanceof 
ClientTransaction) {
+ TransactionApplicationData tad = (TransactionApplicationData) transaction.getApplicationData();
+                                               SipServletMessage 
sipServletMessage = tad.getSipServletMessage();
+ //not specified if ACK is a committed message in the spec but it seems not since Proxy api test + //testCanacel101 method adds a header to the ACK and it cannot be on a committed message + //so we don't want to return ACK as pending messages here. related to TCK test B2BUAHelper.testCreateRequest002 + if (!sipServletMessage.isCommitted() && !Request.ACK.equals(sipServletMessage.getMethod()) && !Request.PRACK.equals(sipServletMessage.getMethod())) {
+                                                       
retval.add(sipServletMessage);
+                                               }
+ for(SipServletResponseImpl sipServletResponseImpl : tad.getSipServletResponses()) {
+                                                       if 
(!sipServletResponseImpl.isCommitted()) {
+                                                               
retval.add(sipServletResponseImpl);
+                                                       }
                                                }
                                        }
                                }

Modified: trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
==============================================================================
--- trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java (original) +++ trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java Fri Apr 10 12:21:28 2009
@@ -604,10 +604,11 @@
                        //This request must be a request created in a new 
SipSession
                        //or from an initial request, and must not have been 
sent.
//If any one of these preconditions are not met, the method throws an IllegalStateException. - if(!State.INITIAL.equals(session.getState()) && session.getOngoingTransactions().size() > 0) {
+                       Set<Transaction> ongoingTransactions = 
session.getOngoingTransactions();
+ if(!State.INITIAL.equals(session.getState()) && ongoingTransactions != null && ongoingTransactions.size() > 0) {
                                if(logger.isDebugEnabled()) {
                                        logger.debug("session state : " + 
session.getState());
- logger.debug("numbers of ongoing transactions : " + session.getOngoingTransactions().size()); + logger.debug("numbers of ongoing transactions : " + ongoingTransactions.size());
                                }
                                throw new IllegalStateException(
                                        "Bad state -- cannot set routing 
directive");

Reply via email to