Revision: 15092
Author: [email protected]
Date: Mon Nov 8 03:13:39 2010
Log: Update Issue 2088
Backport to JBCP 1.2.x branch
http://code.google.com/p/mobicents/source/detail?r=15092
Modified:
/branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java
=======================================
---
/branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java
Tue Oct 5 04:23:20 2010
+++
/branches/jbcp/1.2/sip-servlets-release/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/SipApplicationDispatcherImpl.java
Mon Nov 8 03:13:39 2010
@@ -910,10 +910,19 @@
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);
+ }
+ dialog.delete();
+
tryToInvalidateSession(sipSessionKey, false);
+ }
}
tad.cleanUp();
}
@@ -941,38 +950,48 @@
SipServletMessageImpl sipServletMessage =
tad.getSipServletMessage();
SipSessionKey sipSessionKey =
sipServletMessage.getSipSessionKey();
MobicentsSipSession sipSession =
sipServletMessage.getSipSession();
- if(sipServletMessage instanceof SipServletRequestImpl) {
- try {
- SipServletRequestImpl sipServletRequestImpl = (SipServletRequestImpl)
sipServletMessage;
-
sipServletMessage.setTransaction(transaction);
- SipServletResponseImpl response = (SipServletResponseImpl)
sipServletRequestImpl.createResponse(408, null, false);
-
- 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);
+ boolean appNotifiedOfPrackNotReceived = false;
+ if(sipSession != 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(sipServletMessage instanceof
SipServletRequestImpl) {
+ 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);
+ }
}
}
- boolean appNotifiedOfPrackNotReceived = false;
- if(sipSession != null) {
- 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
- if(appNotifiedOfPrackNotReceived) {
- tad.cleanUp();
- transaction.setApplicationData(null);
- }
+ // don't clean up for the same reason we don't invalidate the sip
session right above
+ tad.cleanUp();
+ transaction.setApplicationData(null);
}
}
@@ -994,8 +1013,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);
@@ -1011,8 +1029,7 @@
logger.error("SipErrorListener threw
exception", t);
}
}
- } finally {
- sipContext.exitSipApp(sipSession.getSipApplicationSession(),
sipSession);
+ } finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@@ -1037,8 +1054,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);
@@ -1053,8 +1069,7 @@
logger.error("SipErrorListener threw
exception", t);
}
}
- } finally {
- sipContext.exitSipApp(sipSession.getSipApplicationSession(),
sipSession);
+ } finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@@ -1103,23 +1118,31 @@
if(b2buaHelperImpl != null && transaction instanceof ClientTransaction
&& Request.INVITE.equals(sipServletMessageImpl.getMethod())) {
removeTx = false;
}
- if(removeTx) {
-
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);
+ if(removeTx) {
+ 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);
+
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()) {
logger.debug("Transaction " + transaction + " not removed from
session " + sipSessionKey + " because the B2BUA might still need it to
create the ACK");
}
}
-
// If it is a client transaction, do not kill the proxy session
http://code.google.com/p/mobicents/issues/detail?id=1024
tryToInvalidateSession(sipSessionKey,
transactionTerminatedEvent.isServerTransaction());
}