Revision: 15091
Author: [email protected]
Date: Mon Nov  8 02:56:22 2010
Log: Update Issue 2088

Backporting changes to the JBCP 5.X branch
http://code.google.com/p/mobicents/source/detail?r=15091

Modified:
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java /branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletResponseImpl.java

=======================================
--- /branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java Wed Oct 27 11:45:01 2010 +++ /branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java Mon Nov 8 02:56:22 2010
@@ -760,7 +760,7 @@
                final Response response = responseEventExt.getResponse();

                if(logger.isDebugEnabled()) {
-                       logger.debug("Response " + 
responseEvent.getResponse().toString());
+                       logger.debug("Response " + response.toString());
                }

final CSeqHeader cSeqHeader = (CSeqHeader)response.getHeader(CSeqHeader.NAME);
@@ -774,8 +774,8 @@
                }

                updateResponseStatistics(response);
- ClientTransaction clientTransaction = responseEvent.getClientTransaction();
-               final Dialog dialog = responseEvent.getDialog();
+ ClientTransaction clientTransaction = responseEventExt.getClientTransaction();
+               final Dialog dialog = responseEventExt.getDialog();
                final boolean isForkedResponse = 
responseEventExt.isForkedResponse();
                final boolean isRetransmission = 
responseEventExt.isRetransmission();
final ClientTransactionExt originalTransaction = responseEventExt.getOriginalTransaction();
@@ -954,10 +954,21 @@
final SipSessionKey sipSessionKey = sipServletMessage.getSipSessionKey(); final MobicentsSipSession sipSession = sipServletMessage.getSipSession();
                                if(sipSession != null) {
-                                       
checkForAckNotReceived(sipServletMessage);
-                                       
checkForPrackNotReceived(sipServletMessage);
-                                       dialog.delete();
-                                       tryToInvalidateSession(sipSessionKey, 
false);
+ SipContext sipContext = findSipApplication(sipSessionKey.getApplicationName());
+                                       //the context can be null if the server 
is being shutdown
+                                       if(sipContext != null) {
+                                               try {
+ sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                                       
checkForAckNotReceived(sipServletMessage);
+                                                       
checkForPrackNotReceived(sipServletMessage);
+                                               } finally {
+ sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                               }
+ // Issue 1822 http://code.google.com/p/mobicents/issues/detail?id=1822 + // don't delete the dialog so that the app can send the BYE even after the noAckReceived has been called
+//                                             dialog.delete();
+                                               
tryToInvalidateSession(sipSessionKey, false);
+                                       }
                                }
                                tad.cleanUp();
                        }
@@ -987,35 +998,44 @@
                        MobicentsSipSession sipSession = 
sipServletMessage.getSipSession();
                        boolean appNotifiedOfPrackNotReceived = false;
                        if(sipSession != null) {
- // session can be null if a message was sent outside of the container by the container itself during Initial request dispatching - // but the external host doesn't send any response so we call out to the applicationonly if the session is not null - // naoki : Fix for Issue 1618 http://code.google.com/p/mobicents/issues/detail?id=1618 on Timeout don't do the 408 processing for Server Transactions - if(sipServletMessage instanceof SipServletRequestImpl && !timeoutEvent.isServerTransaction()) { + SipContext sipContext = findSipApplication(sipSessionKey.getApplicationName());
+                               //the context can be null if the server is 
being shutdown
+                               if(sipContext != null) {
                                        try {
- SipServletRequestImpl sipServletRequestImpl = (SipServletRequestImpl) sipServletMessage;
-                                               
sipServletMessage.setTransaction(transaction);
- SipServletResponseImpl response = (SipServletResponseImpl) sipServletRequestImpl.createResponse(408, null, false);
-                                               // Fix for Issue 1734
-                                               
sipServletRequestImpl.setResponse(response);
-
-                                               
MessageDispatcher.callServlet(response);
-                                               if(tad.getProxyBranch() != 
null) {
-                                                       
tad.getProxyBranch().setResponse(response);
-                                                       
tad.getProxyBranch().onResponse(response, response.getStatus());
-                                               }
-                                               
sipSession.updateStateOnResponse(response, true);
-                                       } catch (Throwable t) {
- logger.error("Failed to deliver 408 response on transaction timeout" + transaction, t); + sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession); + // session can be null if a message was sent outside of the container by the container itself during Initial request dispatching + // but the external host doesn't send any response so we call out to the applicationonly if the session is not null + // naoki : Fix for Issue 1618 http://code.google.com/p/mobicents/issues/detail?id=1618 on Timeout don't do the 408 processing for Server Transactions + if(sipServletMessage instanceof SipServletRequestImpl && !timeoutEvent.isServerTransaction()) {
+                                                       try {
+ SipServletRequestImpl sipServletRequestImpl = (SipServletRequestImpl) sipServletMessage;
+                                                               
sipServletMessage.setTransaction(transaction);
+ SipServletResponseImpl response = (SipServletResponseImpl) sipServletRequestImpl.createResponse(408, null, false);
+                                                               // Fix for 
Issue 1734
+                                                               
sipServletRequestImpl.setResponse(response);
+
+                                                               
MessageDispatcher.callServlet(response);
+                                                               
if(tad.getProxyBranch() != null) {
+                                                                       
tad.getProxyBranch().setResponse(response);
+                                                                       
tad.getProxyBranch().onResponse(response, response.getStatus());
+                                                               }
+                                                               
sipSession.updateStateOnResponse(response, true);
+                                                       } catch (Throwable t) {
+ logger.error("Failed to deliver 408 response on transaction timeout" + transaction, t);
+                                                       }
+                                               }
+                                               
checkForAckNotReceived(sipServletMessage);
+ appNotifiedOfPrackNotReceived = checkForPrackNotReceived(sipServletMessage);
+                                               
sipSession.removeOngoingTransaction(transaction);
+                                       } finally {
+ sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                       }
+ // don't invalidate here because if the application sends a final response on the noPrack received + // the ACK to this final response won't be able to get routed since the sip session would have been invalidated
+                                       if(!appNotifiedOfPrackNotReceived) {
+                                               
tryToInvalidateSession(sipSessionKey, false);
                                        }
                                }
-                               checkForAckNotReceived(sipServletMessage);
- appNotifiedOfPrackNotReceived = checkForPrackNotReceived(sipServletMessage);
-                               
sipSession.removeOngoingTransaction(transaction);
- // don't invalidate here because if the application sends a final response on the noPrack received - // the ACK to this final response won't be able to get routed since the sip session would have been invalidated
-                               if(!appNotifiedOfPrackNotReceived) {
-                                       tryToInvalidateSession(sipSessionKey, 
false);
-                               }
                        }
// don't clean up for the same reason we don't invalidate the sip session right above
                        tad.cleanUp();
@@ -1030,7 +1050,7 @@
                        
((SipServletRequestImpl)sipServletMessage).getLastFinalResponse();
                final ProxyImpl proxy = sipSession.getProxy();
                if(logger.isDebugEnabled()) {
- logger.debug("checkForAckNotReceived : last Final Response " + lastFinalResponse); + logger.debug("checkForAckNotReceived : request " + sipServletMessage + " last Final Response " + lastFinalResponse);
                }
                boolean notifiedApplication = false;
if(sipServletMessage instanceof SipServletRequestImpl && Request.INVITE.equals(sipServletMessage.getMethod()) &&
@@ -1041,8 +1061,7 @@
                                
sipContext.getListeners().getSipErrorListeners();

final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-                       try {
- sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession);
+                       try {
                                final ClassLoader cl = 
sipContext.getLoader().getClassLoader();
                                
Thread.currentThread().setContextClassLoader(cl);

@@ -1058,10 +1077,25 @@
                                                logger.error("SipErrorListener threw 
exception", t);
                                        }
                                }
-                       } finally {
- sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                       } finally {
                                
Thread.currentThread().setContextClassLoader(oldClassLoader);
                        }
+                       if(!notifiedApplication) {
+                               // Issue 1822 
http://code.google.com/p/mobicents/issues/detail?id=1822
+                               // RFC 3261 Section 13.3.1.4 The INVITE is 
Accepted
+ // "If the server retransmits the 2xx response for 64*T1 seconds without receiving an ACK,
+                               // the dialog is confirmed, but the session 
SHOULD be terminated.
+                               // This is accomplished with a BYE, as described in 
Section 15."
+                               SipServletRequest bye = 
sipSession.createRequest(Request.BYE);
+                               if(logger.isDebugEnabled()) {
+ logger.debug("no applications called for ACK not received, sending BYE " + bye);
+                               }
+                               try {
+                                       bye.send();
+                               } catch (IOException e) {
+                                       logger.error("Couldn't send the BYE " + 
bye, e);
+                               }
+                       }
                }
                return notifiedApplication;
        }
@@ -1084,8 +1118,7 @@
                                
sipContext.getListeners().getSipErrorListeners();

final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-                       try {
- sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession);
+                       try {
                                final ClassLoader cl = 
sipContext.getLoader().getClassLoader();
                                
Thread.currentThread().setContextClassLoader(cl);

@@ -1100,8 +1133,7 @@
                                                logger.error("SipErrorListener threw 
exception", t);
                                        }
                                }
-                       } finally {
- sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                       } finally {
                                
Thread.currentThread().setContextClassLoader(oldClassLoader);
                        }
                }
@@ -1136,7 +1168,7 @@
                                if(logger.isDebugEnabled()) {
logger.debug("no sip session were returned for this key " + sipServletMessageImpl.getSipSessionKey() + " and message " + sipServletMessageImpl);
                                }
-                       }
+                       }

// Issue 1333 : B2buaHelper.getPendingMessages(linkedSession, UAMode.UAC) returns empty list // don't remove the transaction on terminated state for INVITE Tx because it won't be possible
@@ -1147,18 +1179,27 @@
                                        removeTx = false;
                                }
                                if(removeTx) {
- if(b2buaHelperImpl != null && tad.getSipServletMessage() instanceof SipServletRequestImpl) { - b2buaHelperImpl.unlinkOriginalRequestInternal((SipServletRequestImpl)tad.getSipServletMessage());
-                                       }
-                                       
sipSession.removeOngoingTransaction(transaction);
-                                       tad.cleanUp();
- // Issue 1468 : to handle forking, we shouldn't cleanup the app data since it is needed for the forked responses
-                                       boolean nullifyAppData = true;
- if(((SipStackImpl)((SipProvider)transactionTerminatedEvent.getSource()).getSipStack()).getMaxForkTime()
0 && Request.INVITE.equals(sipServletMessageImpl.getMethod())) {
-                                               nullifyAppData = false;
-                                       }
-                                       if(nullifyAppData) {
-                                               
transaction.setApplicationData(null);
+ SipContext sipContext = findSipApplication(sipSessionKey.getApplicationName());
+                                       //the context can be null if the server 
is being shutdown
+                                       if(sipContext != null) {
+                                               try {
+ sipContext.enterSipApp(sipSession.getSipApplicationSession(), sipSession); + if(b2buaHelperImpl != null && tad.getSipServletMessage() instanceof SipServletRequestImpl) { + b2buaHelperImpl.unlinkOriginalRequestInternal((SipServletRequestImpl)tad.getSipServletMessage());
+                                                       }
+                                                       
sipSession.removeOngoingTransaction(transaction);
+                                                       tad.cleanUp();
+ // Issue 1468 : to handle forking, we shouldn't cleanup the app data since it is needed for the forked responses
+                                                       boolean nullifyAppData 
= true;
+ if(((SipStackImpl)((SipProvider)transactionTerminatedEvent.getSource()).getSipStack()).getMaxForkTime()
0 && Request.INVITE.equals(sipServletMessageImpl.getMethod())) {
+                                                               nullifyAppData 
= false;
+                                                       }
+                                                       if(nullifyAppData) {
+                                                               
transaction.setApplicationData(null);
+                                                       }
+                                               } finally {
+ sipContext.exitSipApp(sipSession.getSipApplicationSession(), sipSession);
+                                               }
                                        }
                                } else {
                                        if(logger.isDebugEnabled()) {
=======================================
--- /branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletResponseImpl.java Wed Oct 27 11:45:01 2010 +++ /branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletResponseImpl.java Mon Nov 8 02:56:22 2010
@@ -539,10 +539,13 @@
final Dialog dialog = transaction == null ? null:transaction.getDialog();
                        //keeping track of application data and transaction in 
the dialog
                        if(dialog != null) {
-                               if(dialog.getApplicationData() == null) {
-                                       dialog.setApplicationData(
-                                                       
originalRequest.getTransactionApplicationData());
-                               }
+ // Issue 1822 : we need to reset the application data even if dialg appdata is null otherwise the app is not invoked for noAckReceived on re INVITE
+//                             if(dialog.getApplicationData() == null) {
+ final TransactionApplicationData originalRequestAppData = originalRequest.getTransactionApplicationData();
+                               if(originalRequestAppData != null) {
+                                       
dialog.setApplicationData(originalRequestAppData);
+                               }
+//                             }
                                
((TransactionApplicationData)dialog.getApplicationData()).
                                        setTransaction(transaction);
                        }

Reply via email to