Revision: 14886
Author: [email protected]
Date: Tue Oct 26 02:22:03 2010
Log: Update Issue 1837
Backport to JBCP 5 branch
http://code.google.com/p/mobicents/source/detail?r=14886
Modified:
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/dispatchers/SubsequentRequestDispatcher.java
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/MobicentsSipSession.java
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/reinvite/CallForwardingB2BUAReInviteJunitTest.java
=======================================
---
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/dispatchers/SubsequentRequestDispatcher.java
Wed Oct 6 00:59:53 2010
+++
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/dispatchers/SubsequentRequestDispatcher.java
Tue Oct 26 02:22:03 2010
@@ -18,16 +18,21 @@
import gov.nist.javax.sip.header.extensions.JoinHeader;
import gov.nist.javax.sip.header.extensions.ReplacesHeader;
+import gov.nist.javax.sip.message.MessageExt;
+import gov.nist.javax.sip.stack.SIPTransaction;
import java.io.IOException;
import java.util.List;
+import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.sip.ProxyBranch;
import javax.servlet.sip.SipServletResponse;
import javax.sip.Dialog;
+import javax.sip.ServerTransaction;
import javax.sip.SipException;
import javax.sip.SipProvider;
+import javax.sip.Transaction;
import javax.sip.header.Parameters;
import javax.sip.header.RouteHeader;
import javax.sip.header.SubscriptionStateHeader;
@@ -48,6 +53,7 @@
import org.mobicents.servlet.sip.message.SipFactoryImpl;
import org.mobicents.servlet.sip.message.SipServletMessageImpl;
import org.mobicents.servlet.sip.message.SipServletRequestImpl;
+import org.mobicents.servlet.sip.message.TransactionApplicationData;
import org.mobicents.servlet.sip.proxy.ProxyBranchImpl;
import org.mobicents.servlet.sip.proxy.ProxyImpl;
import org.mobicents.servlet.sip.startup.SipContext;
@@ -350,38 +356,61 @@
}
}
// If it's not for a proxy then it's just an AR, so go to the next
application
- else {
+ else {
// Issue 1401
http://code.google.com/p/mobicents/issues/detail?id=1401
// JSR 289 Section 11.2.2
Receiving ACK :
// "Applications are not notified of incoming ACKs for non-2xx final
responses to INVITE."
boolean callServlet = true;
- SipServletRequestImpl sessionCreatingTransactionRequest =
((SipServletRequestImpl)sipSession.getSessionCreatingTransactionRequest());
- // checking if the sessionCreatingTransactionRequest is not null, it
can happen on failover, in this case it is fine, since we support
- // dialog established failover
only.
-
if(sessionCreatingTransactionRequest != null) {
- final SipServletResponse lastFinalResponse =
sessionCreatingTransactionRequest.getLastFinalResponse();
-
if(logger.isDebugEnabled()) {
- logger.debug("last final response " +
lastFinalResponse);
- }
-
if(Request.ACK.equalsIgnoreCase(requestMethod)) {
- if(lastFinalResponse != null && lastFinalResponse.getStatus()
= 300) {
- callServlet =
false;
-
if(logger.isDebugEnabled()) {
- logger.debug("not calling the servlet since this is an ACK
for a final error response");
- }
- }
- // Issue 1494 :
http://code.google.com/p/mobicents/issues/detail?id=1494
- // Only the first ACK makes it up to the
application, in case the sip stack
- // generates an error response the last final response will be
null
- // for the corresponding ACK and it should
not be passed to the app
-
if(lastFinalResponse == null) {
- if(logger.isDebugEnabled()) {
- logger.debug("not calling the
servlet since this is an ACK for a null last final response, which means
the ACK was for a sip stack generated error response");
- }
- callServlet = false;
- sipSession.setAckReceived(false);
- }
- }
+
if(Request.ACK.equalsIgnoreCase(requestMethod)) {
+ final Set<Transaction> ongoingTransactions =
sipSession.getOngoingTransactions();
+ // Issue 1837
http://code.google.com/p/mobicents/issues/detail?id=1837
+ // ACK was received by
JAIN-SIP but was not routed to application
+ // we need to go through the set of all ongoing tx since and INFO
request can be received before a reINVITE tx has been completed
+ if(ongoingTransactions
!= null) {
+
if(logger.isDebugEnabled()) {
+ logger.debug("going through all Stx to
check if we need to pass the ACK up to the application");
+ }
+ for
(Transaction transaction: ongoingTransactions) {
+
if(logger.isDebugEnabled()) {
+ logger.debug(" tx to check "+
transaction);
+ }
+ if (transaction instanceof ServerTransaction &&
((SIPTransaction)transaction).getMethod().equals(Request.INVITE)) {
+
if(logger.isDebugEnabled()) {
+ logger.debug("Stx found "+
transaction.getBranchId() +" to check if we need to pass the ACK up to the
application");
+ }
+ final TransactionApplicationData tad =
(TransactionApplicationData) transaction.getApplicationData();
+
if(tad != null) {
+ final SipServletMessageImpl sipServletMessage =
tad.getSipServletMessage();
+ if(sipServletMessage != null && sipServletMessage instanceof
SipServletRequestImpl &&
+ ((MessageExt)request).getCSeqHeader().getSeqNumber() ==
((MessageExt)sipServletMessage.getMessage()).getCSeqHeader().getSeqNumber())
{
+ SipServletRequestImpl correspondingInviteRequest =
(SipServletRequestImpl)sipServletMessage;
+ final SipServletResponse lastFinalResponse =
correspondingInviteRequest.getLastFinalResponse();
+
if(logger.isDebugEnabled()) {
+ logger.debug("last final response " +
lastFinalResponse);
+ }
+
+ if(lastFinalResponse != null &&
lastFinalResponse.getStatus() >= 300) {
+
callServlet = false;
+
if(logger.isDebugEnabled()) {
+ logger.debug("not calling the servlet since this is an
ACK for a final error response");
+
}
+
}
+ // Issue 1494 :
http://code.google.com/p/mobicents/issues/detail?id=1494
+ // Only the first ACK makes it up to
the application, in case the sip stack
+ // generates an error response the last final response will
be null
+ // for the corresponding ACK and it
should not be passed to the app
+
if(lastFinalResponse == null) {
+
if(logger.isDebugEnabled()) {
+ logger.debug("not calling the
servlet since this is an ACK for a null last final response, which means
the ACK was for a sip stack generated error response");
+ }
+ callServlet
= false;
+
sipSession.setAckReceived(false);
+
}
+
}
+
}
+ }
+ }
+ }
}
// JSR 289 Section 6.2.1 :
// any state transition caused
by the reception of a SIP message,
=======================================
---
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/MobicentsSipSession.java
Mon Aug 9 01:15:32 2010
+++
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/MobicentsSipSession.java
Tue Oct 26 02:22:03 2010
@@ -79,25 +79,19 @@
String getHandler();
Dialog getSessionCreatingDialog();
-
void setSessionCreatingDialog(Dialog dialog);
SipServletMessageImpl getSessionCreatingTransactionRequest();
-
void setSessionCreatingTransactionRequest(SipServletMessageImpl
message);
Set<Transaction> getOngoingTransactions();
-
void removeOngoingTransaction(Transaction transaction);
-
void addOngoingTransaction(Transaction transaction);
Serializable getStateInfo();
-
void setStateInfo(Serializable stateInfo);
Principal getUserPrincipal();
-
void setUserPrincipal(Principal principal);
void setRoutingRegion(SipApplicationRoutingRegion routingRegion);
=======================================
---
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
Mon Sep 20 13:30:34 2010
+++
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/session/SipSessionImpl.java
Tue Oct 26 02:22:03 2010
@@ -225,8 +225,8 @@
*/
protected transient SipServletRequestImpl
sessionCreatingTransactionRequest;
protected transient boolean isSessionCreatingTransactionServer;
- // =============================================================
-
+
+ // TODO : Can be optimized into separate server tx and client tx to speed
up some parts of the cod
protected transient Set<Transaction> ongoingTransactions;
volatile protected transient ConcurrentHashMap<String,
MobicentsSipSession> derivedSipSessions;
=======================================
---
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/reinvite/CallForwardingB2BUAReInviteJunitTest.java
Fri Jul 2 14:00:41 2010
+++
/branches/jbcp/5.x-mead/sip-servlets/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/reinvite/CallForwardingB2BUAReInviteJunitTest.java
Tue Oct 26 02:22:03 2010
@@ -101,6 +101,7 @@
sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null,
false);
Thread.sleep(TIMEOUT);
assertTrue(sender.isInviteReceived());
+ assertTrue(sender.isAckReceived());
assertNotNull(sender.getInviteRequest().getHeader("ReInvite"));
MaxForwardsHeader maxForwardsHeader = (MaxForwardsHeader)
receiver.getInviteRequest().getHeader(MaxForwardsHeader.NAME);
assertNotNull(maxForwardsHeader);
@@ -167,7 +168,43 @@
assertTrue(sender.isCancelOkReceived());
assertTrue(sender.isRequestTerminatedReceived());
assertTrue(receiver.isCancelReceived());
- }
+ }
+
+ /**
+ * Non Regression test for
+ * http://code.google.com/p/mobicents/issues/detail?id=1837
+ * ACK was received by JAIN-SIP but was not routed to application
+ */
+ public void testCallForwardingCallerReInviteAckRaceInfo() throws
Exception {
+ sender = new TestSipListener(5080, 5070, senderProtocolObjects,
false);
+ SipProvider senderProvider = sender.createProvider();
+
+ receiver = new TestSipListener(5090, 5070, receiverProtocolObjects,
false);
+ SipProvider receiverProvider = receiver.createProvider();
+
+ receiverProvider.addSipListener(receiver);
+ senderProvider.addSipListener(sender);
+
+ senderProtocolObjects.start();
+ receiverProtocolObjects.start();
+
+ String fromName = "forward-pending-sender";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ String toSipAddress = "sip-servlets.com";
+ String toUser = "receiver";
+ SipURI toAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ toUser, toSipAddress);
+
+ sender.setTimeToWaitBeforeAck(9000);
+ sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null,
false);
+ Thread.sleep(8000);
+ receiver.sendInDialogSipRequest("UPDATE", null, null, null,
null);
+ Thread.sleep(5000);
+ assertTrue(receiver.isAckReceived());
+ }
@Override
protected void tearDown() throws Exception {