Revision: 4762d2d39ec3
Author: Jean Deruelle <[email protected]>
Date: Fri Apr 25 07:55:03 2014 UTC
Log: Update Issue 20
Fix + non regression test
(cherry picked from commit 22e74b98a11d51e872337d0ccfc8e2b09a4e40ec)
http://code.google.com/p/sipservlets/source/detail?r=4762d2d39ec3
Added:
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/ProxyRecordRoutingTcpTest.java
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/ProxyRecordRoutingTest.java
Modified:
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyUtils.java
/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ProxySipServlet.java
=======================================
--- /dev/null
+++
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/ProxyRecordRoutingTcpTest.java
Fri Apr 25 07:55:03 2014 UTC
@@ -0,0 +1,146 @@
+/*
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2011-2014, Telestax Inc and individual contributors
+ * by the @authors tag.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package org.mobicents.servlet.sip.testsuite.proxy;
+
+import java.util.ListIterator;
+
+import javax.sip.ListeningPoint;
+import javax.sip.SipProvider;
+import javax.sip.address.SipURI;
+import javax.sip.header.Header;
+import javax.sip.header.RecordRouteHeader;
+
+import org.apache.log4j.Logger;
+import org.mobicents.servlet.sip.SipServletTestCase;
+import org.mobicents.servlet.sip.testsuite.ProtocolObjects;
+import org.mobicents.servlet.sip.testsuite.TestSipListener;
+
+public class ProxyRecordRoutingTcpTest extends SipServletTestCase {
+
+ private static transient Logger logger =
Logger.getLogger(ProxyRecordRoutingTcpTest.class);
+
+ private static final String SESSION_EXPIRED = "sessionExpired";
+ private static final String SESSION_READY_TO_INVALIDATE
= "sessionReadyToInvalidate";
+ private static final String SIP_SESSION_READY_TO_INVALIDATE
= "sipSessionReadyToInvalidate";
+ private static final boolean AUTODIALOG = true;
+ TestSipListener sender;
+ TestSipListener neutral;
+ TestSipListener receiver;
+ ProtocolObjects senderProtocolObjects;
+ ProtocolObjects receiverProtocolObjects;
+ ProtocolObjects neutralProto;
+
+
+ private static final int TIMEOUT = 20000;
+
+ public ProxyRecordRoutingTcpTest(String name) {
+ super(name);
+ autoDeployOnStartup = false;
+ listeningPointTransport = ListeningPoint.TCP;
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ senderProtocolObjects = new ProtocolObjects("proxy-sender",
+ "gov.nist", ListeningPoint.TCP, AUTODIALOG,
null, null, null);
+ receiverProtocolObjects = new ProtocolObjects("proxy-receiver",
+ "gov.nist", ListeningPoint.TCP, AUTODIALOG,
null, null, null);
+ neutralProto = new ProtocolObjects("neutral",
+ "gov.nist", ListeningPoint.TCP, AUTODIALOG,
null, null, null);
+ sender = new TestSipListener(5080, 5070, senderProtocolObjects,
false);
+ sender.setRecordRoutingProxyTesting(true);
+ SipProvider senderProvider = sender.createProvider();
+
+ receiver = new TestSipListener(5057, 5070, receiverProtocolObjects,
false);
+ receiver.setRecordRoutingProxyTesting(true);
+ SipProvider receiverProvider = receiver.createProvider();
+
+ neutral = new TestSipListener(5058, 5070, neutralProto, false);
+ neutral.setRecordRoutingProxyTesting(true);
+ SipProvider neutralProvider = neutral.createProvider();
+
+ receiverProvider.addSipListener(receiver);
+ senderProvider.addSipListener(sender);
+ neutralProvider.addSipListener(neutral);
+
+ senderProtocolObjects.start();
+ receiverProtocolObjects.start();
+ neutralProto.start();
+ }
+
+ /*
+ * https://code.google.com/p/sipservlets/issues/detail?id=20
+ */
+ public void testTCPRecordRouteProxying() throws Exception {
+ deployApplication();
+ String fromName = "tcp-record-route-tcp-unique-location";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ String toSipAddress = "sip-servlets.com";
+ String toUser = "proxy-receiver";
+ SipURI toAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ toUser, toSipAddress);
+
+ sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null,
false);
+ Thread.sleep(TIMEOUT);
+ assertEquals(200,sender.getFinalResponseStatus());
+ assertTrue(sender.isAckSent());
+ ListIterator<Header> it =
receiver.getInviteRequest().getHeaders(RecordRouteHeader.NAME);
+ int countRRHeader = 0;
+ while(it.hasNext()) {
+ countRRHeader++;
+ it.next();
+ }
+ assertEquals(1, countRRHeader);
+ sender.sendBye();
+ Thread.sleep(TIMEOUT);
+ assertTrue(receiver.getByeReceived());
+ assertTrue(sender.getOkToByeReceived());
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ senderProtocolObjects.destroy();
+ receiverProtocolObjects.destroy();
+ neutralProto.destroy();
+ logger.info("Test completed");
+ super.tearDown();
+ }
+
+ @Override
+ public void deployApplication() {
+ assertTrue(tomcat
+ .deployContext(
+ projectHome
+
+ "/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/sipapp",
+ "sip-test-context",
"/sip-test"));
+ }
+
+ @Override
+ protected String getDarConfigurationFile() {
+ return "file:///"
+ + projectHome
+ +
"/sip-servlets-test-suite/testsuite/src/test/resources/"
+
+ "org/mobicents/servlet/sip/testsuite/proxy/simple-sip-servlet-dar.properties";
+ }
+}
=======================================
--- /dev/null
+++
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/proxy/ProxyRecordRoutingTest.java
Fri Apr 25 07:55:03 2014 UTC
@@ -0,0 +1,190 @@
+/*
+ * TeleStax, Open Source Cloud Communications
+ * Copyright 2011-2014, Telestax Inc and individual contributors
+ * by the @authors tag.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package org.mobicents.servlet.sip.testsuite.proxy;
+
+import javax.sip.ListeningPoint;
+import javax.sip.SipProvider;
+import javax.sip.address.SipURI;
+
+import org.apache.log4j.Logger;
+import org.mobicents.servlet.sip.SipServletTestCase;
+import org.mobicents.servlet.sip.testsuite.ProtocolObjects;
+import org.mobicents.servlet.sip.testsuite.TestSipListener;
+
+public class ProxyRecordRoutingTest extends SipServletTestCase {
+
+ private static transient Logger logger =
Logger.getLogger(ProxyRecordRoutingTest.class);
+
+ private static final String SESSION_EXPIRED = "sessionExpired";
+ private static final String SESSION_READY_TO_INVALIDATE
= "sessionReadyToInvalidate";
+ private static final String SIP_SESSION_READY_TO_INVALIDATE
= "sipSessionReadyToInvalidate";
+ private static final boolean AUTODIALOG = true;
+ TestSipListener sender;
+ TestSipListener neutral;
+ TestSipListener receiver;
+ ProtocolObjects senderProtocolObjects;
+ ProtocolObjects receiverProtocolObjects;
+ ProtocolObjects neutralProto;
+
+
+ private static final int TIMEOUT = 20000;
+
+ public ProxyRecordRoutingTest(String name) {
+ super(name);
+ autoDeployOnStartup = false;
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ senderProtocolObjects = new ProtocolObjects("proxy-sender",
+ "gov.nist", ListeningPoint.UDP, AUTODIALOG,
null, null, null);
+ receiverProtocolObjects = new ProtocolObjects("proxy-receiver",
+ "gov.nist", ListeningPoint.UDP, AUTODIALOG,
null, null, null);
+ neutralProto = new ProtocolObjects("neutral",
+ "gov.nist", ListeningPoint.UDP, AUTODIALOG,
null, null, null);
+ sender = new TestSipListener(5080, 5070, senderProtocolObjects,
false);
+ sender.setRecordRoutingProxyTesting(true);
+ SipProvider senderProvider = sender.createProvider();
+
+ receiver = new TestSipListener(5057, 5070, receiverProtocolObjects,
false);
+ receiver.setRecordRoutingProxyTesting(true);
+ SipProvider receiverProvider = receiver.createProvider();
+
+ neutral = new TestSipListener(5058, 5070, neutralProto, false);
+ neutral.setRecordRoutingProxyTesting(true);
+ SipProvider neutralProvider = neutral.createProvider();
+
+ receiverProvider.addSipListener(receiver);
+ senderProvider.addSipListener(sender);
+ neutralProvider.addSipListener(neutral);
+
+ senderProtocolObjects.start();
+ receiverProtocolObjects.start();
+ neutralProto.start();
+ }
+
+ /*
+ * https://code.google.com/p/sipservlets/issues/detail?id=2
+ */
+ public void testRedirectProxying() throws Exception {
+ deployApplication();
+ String fromName = "redirect-unique-location";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ String toSipAddress = "sip-servlets.com";
+ String toUser = "proxy-receiver";
+ SipURI toAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ toUser, toSipAddress);
+
+ receiver.setFinalResponseToSend(302);
+ sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null,
false);
+ Thread.sleep(TIMEOUT);
+ assertEquals(200,sender.getFinalResponseStatus());
+ assertTrue(sender.isAckSent());
+ sender.sendBye();
+ Thread.sleep(TIMEOUT);
+ assertTrue(neutral.getByeReceived());
+ assertFalse(receiver.getByeReceived());
+ assertTrue(sender.getOkToByeReceived());
+ }
+
+ /*
+ * Non Regression test for
https://code.google.com/p/sipservlets/issues/detail?id=2
+ */
+ public void testCancelRedirectProxying() throws Exception {
+ deployApplication();
+ String fromName = "redirect-unique-location";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ String toSipAddress = "sip-servlets.com";
+ String toUser = "proxy-receiver";
+ SipURI toAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ toUser, toSipAddress);
+
+ receiver.setFinalResponseToSend(302);
+ neutral.setWaitForCancel(true);
+ sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null,
false);
+ Thread.sleep(TIMEOUT);
+ sender.sendCancel();
+ Thread.sleep(TIMEOUT);
+ assertEquals(487,sender.getFinalResponseStatus());
+ assertTrue(neutral.isCancelReceived());
+ }
+
+ /*
+ * Non Regression test for
https://code.google.com/p/sipservlets/issues/detail?id=266
+ */
+ public void testCancel480Proxying() throws Exception {
+ deployApplication();
+ String fromName = "cancel-480-sequential-2-locations";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ String toSipAddress = "sip-servlets.com";
+ String toUser = "proxy-receiver";
+ SipURI toAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ toUser, toSipAddress);
+
+ receiver.setFinalResponseToSend(480);
+ neutral.setWaitForCancel(true);
+ sender.sendSipRequest("INVITE", fromAddress, toAddress, null, null,
false);
+ Thread.sleep(TIMEOUT);
+ sender.sendCancel();
+ Thread.sleep(TIMEOUT);
+ // We receive 480 and not 487 because of JSR 289 Section 10.2.6
+ // When receiving a CANCEL for a transaction for which a Proxy object
exists the server responds
+ // to the CANCEL with a 200 and if the original request has not been
proxied yet the container responds to it with a 487 final
+ // response. otherwise, all branches are cancelled, and response
processing continues as usual
+ assertEquals(480,sender.getFinalResponseStatus());
+ assertTrue(neutral.isCancelReceived());
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ senderProtocolObjects.destroy();
+ receiverProtocolObjects.destroy();
+ neutralProto.destroy();
+ logger.info("Test completed");
+ super.tearDown();
+ }
+
+ @Override
+ public void deployApplication() {
+ assertTrue(tomcat
+ .deployContext(
+ projectHome
+
+ "/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/sipapp",
+ "sip-test-context",
"sip-test"));
+ }
+
+ @Override
+ protected String getDarConfigurationFile() {
+ return "file:///"
+ + projectHome
+ +
"/sip-servlets-test-suite/testsuite/src/test/resources/"
+
+ "org/mobicents/servlet/sip/testsuite/proxy/simple-sip-servlet-dar.properties";
+ }
+}
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyUtils.java
Tue Mar 11 18:46:24 2014 UTC
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/proxy/ProxyUtils.java
Fri Apr 25 07:55:03 2014 UTC
@@ -56,9 +56,8 @@
import org.mobicents.servlet.sip.message.SipServletResponseImpl;
import org.mobicents.servlet.sip.startup.StaticServiceHolder;
/**
- * TODO: Use outbound interface from ProxyParams.outboundInterface when
adding local
- * listening point addresses.
- *
+ * @author [email protected]
+ * @author [email protected]
*/
public class ProxyUtils {
private static final Logger logger = Logger.getLogger(ProxyUtils.class);
@@ -111,7 +110,19 @@
}
}
- if(outboundTransport == null) outboundTransport =
ListeningPoint.UDP;
+ if(outboundTransport == null) {
+ // https://code.google.com/p/sipservlets/issues/detail?id=20 in
case the Request URI doesn't contain the transport
+ // check the RecordRoute to see if it's set there to a different
value
+ String rrHeaderTransport = null;
+ if(routeRecord != null) {
+ rrHeaderTransport =
routeRecord.getTransportParam();
+ }
+ if(rrHeaderTransport == null) {
+ outboundTransport = ListeningPoint.UDP;
+ } else {
+ outboundTransport = rrHeaderTransport;
+ }
+ }
((MessageExt)clonedRequest).setApplicationData(outboundTransport);
=======================================
---
/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ProxySipServlet.java
Tue Apr 22 19:43:45 2014 UTC
+++
/sip-servlets-test-suite/applications/proxy-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ProxySipServlet.java
Fri Apr 25 07:55:03 2014 UTC
@@ -340,6 +340,10 @@
proxy.setSupervised(true);
if(recordRoute) {
proxy.getRecordRouteURI().setParameter("testparamname",
"TESTVALUE");
+ if((via.contains("TCP") || via.contains("tcp")) &&
fromURI.getUser().contains("tcp-record-route-tcp")) {
+
proxy.getRecordRouteURI().setTransportParam("TCP");
+ uri1.removeParameter("transport");
+ }
}
proxy.setParallel(true);
if(CHECK_URI.equals(fromURI.getUser())) {
--
---
You received this message because you are subscribed to the Google Groups "mobicents-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.