Revision: 83e6c28e6c5c
Author: jean.deruelle <[email protected]>
Date: Mon Jan 28 09:54:52 2013
Log: Update Issue 172
Add more regression tests to cover more use cases and fix the
implementation as it should not be able to modify Contact
Header on OPTIONS requests
http://code.google.com/p/sipservlets/source/detail?r=83e6c28e6c5c
Modified:
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/JainSipUtils.java
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
/sip-servlets-test-suite/applications/shootist-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ShootistSipServlet.java
/sip-servlets-test-suite/applications/simple-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/SimpleSipServlet.java
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootistSipServletTest.java
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootmeSipServletTest.java
/sip-servlets-test-suite/testsuite/src/test/resources/org/mobicents/servlet/sip/testsuite/simple/simple-sip-servlet-dar.properties
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/JainSipUtils.java
Fri Jun 1 01:44:46 2012
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/JainSipUtils.java
Mon Jan 28 09:54:52 2013
@@ -159,6 +159,8 @@
CONTACT_HEADER_METHODS.add(Request.NOTIFY);
CONTACT_HEADER_METHODS.add(Request.REFER);
CONTACT_HEADER_METHODS.add(Request.UPDATE);
+ // http://code.google.com/p/sipservlets/issues/detail?id=172
+ CONTACT_HEADER_METHODS.add(Request.OPTIONS);
}
public static final Set<String> DIALOG_CREATING_METHODS = new
TreeSet<String>(
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
Fri Dec 21 03:24:48 2012
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
Mon Jan 28 09:54:52 2013
@@ -240,7 +240,7 @@
Request request = (Request) this.message;
String method = request.getMethod();
- if (method.equals(Request.REGISTER) ||
method.equals(Request.OPTIONS)) {
+ if (method.equals(Request.REGISTER)) {
return ModifiableRule.ContactNotSystem;
} else {
return ModifiableRule.ContactSystem;
=======================================
---
/sip-servlets-test-suite/applications/shootist-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ShootistSipServlet.java
Wed Nov 14 09:00:41 2012
+++
/sip-servlets-test-suite/applications/shootist-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/ShootistSipServlet.java
Mon Jan 28 09:54:52 2013
@@ -21,8 +21,6 @@
*/
package org.mobicents.servlet.sip.testsuite;
-import gov.nist.javax.sip.stack.SIPTransactionStack;
-
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
@@ -452,9 +450,32 @@
}
// http://code.google.com/p/sipservlets/issues/detail?id=156 and
http://code.google.com/p/sipservlets/issues/detail?id=172
if(ce.getServletContext().getInitParameter("setRandomContact") !=
null) {
- if(method.equalsIgnoreCase("REGISTER") ||
method.equalsIgnoreCase("OPTIONS")) {
+ if(method.equalsIgnoreCase("REGISTER"))
{
sipServletRequest.addHeader("Contact", "sip:[email protected]:3289");
}
+ if(method.equalsIgnoreCase("OPTIONS")) {
+ try {
+
sipServletRequest.addHeader("Contact", "sip:[email protected]:3289");
+ logger.error("JSR 289, Section 4.1.3 The Contact Header Field:
Contact header is a system header except for the following messages: 4.
200/OPTIONS responses. Container should have thrown an exception");
+ throw new IllegalStateException("JSR 289, Section 4.1.3 The Contact
Header Field: Contact header is a system header except for the following
messages: 4. 200/OPTIONS responses. Container should have thrown an
exception");
+ } catch(Exception e) {
+ }
+ try {
+ Address contactAddress =
sipServletRequest.getAddressHeader("Contact");
+
((SipURI)contactAddress.getURI()).setUser("optionUser");
+
((SipURI)contactAddress.getURI()).setHost("optionHost.com");
+ logger.error("JSR 289, Section 4.1.3 The Contact Header Field:
Contact header is a system header except for the following messages: 4.
200/OPTIONS responses. Container should have thrown an exception");
+ throw new IllegalStateException("JSR 289, Section 4.1.3 The Contact
Header Field: Contact header is a system header except for the following
messages: 4. 200/OPTIONS responses. Container should have thrown an
exception");
+ } catch(Exception e) {
+ }
+ try {
+ Parameterable contactHeader =
sipServletRequest.getParameterableHeader("Contact");
+
contactHeader.setParameter("optionParam", "optionValue");
+ } catch (ServletParseException
e) {
+ logger.error("an error occured while getting the contact Header",
e);
+ }
+
+ }
}
sipServletRequest.setRequestURI(requestURI);
if(ce.getServletContext().getInitParameter("enum") != null) {
=======================================
---
/sip-servlets-test-suite/applications/simple-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/SimpleSipServlet.java
Mon Oct 22 09:57:59 2012
+++
/sip-servlets-test-suite/applications/simple-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/SimpleSipServlet.java
Mon Jan 28 09:54:52 2013
@@ -771,6 +771,20 @@
SipServletResponse resp = req.createResponse(response);
resp.send();
}
+
+ @Override
+ protected void doOptions(SipServletRequest req) throws ServletException,
+ IOException {
+ int response = SipServletResponse.SC_OK;
+ SipServletResponse resp = req.createResponse(response);
+ /**
+ * non regression test for Issue 172
http://code.google.com/p/sipservlets/issues/detail?id=172
+ * Possible to add contact Header to 200 OK to OPTIONS
+ */
+ resp.addHeader("Contact", "sip:[email protected]:3289");
+ resp.send();
+ }
+
// SipErrorListener methods
=======================================
---
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootistSipServletTest.java
Wed Nov 14 09:00:41 2012
+++
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootistSipServletTest.java
Mon Jan 28 09:54:52 2013
@@ -813,7 +813,7 @@
/**
* non regression test for Issue 172
http://code.google.com/p/sipservlets/issues/detail?id=172
- * Contact header in OPTIONS overwritten by container
+ * Possible to add params to Contact header
*/
@Test
public void testShootistOptionsSetContact() throws Exception {
@@ -833,8 +833,10 @@
deployApplication(params);
Thread.sleep(TIMEOUT);
ContactHeader contactHeader = (ContactHeader)
receiver.getOptionsRequest().getHeader(ContactHeader.NAME);
- assertNotNull(contactHeader);
-
assertEquals(((SipURI)contactHeader.getAddress().getURI()).toString(),"sip:[email protected]:3289");
+ assertNotNull(contactHeader);
+ assertNotNull(contactHeader.getParameter("optionParam"));
+
assertEquals(contactHeader.getParameter("optionParam"),"optionValue");
+
assertEquals(((SipURI)contactHeader.getAddress().getURI()).getUser(), "optionUser");
}
=======================================
---
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootmeSipServletTest.java
Thu Oct 18 09:27:27 2012
+++
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootmeSipServletTest.java
Mon Jan 28 09:54:52 2013
@@ -379,6 +379,25 @@
assertTrue(sender.isFinalResponseReceived());
assertEquals(200, sender.getFinalResponseStatus());
}
+
+ /**
+ * non regression test for Issue 172
http://code.google.com/p/sipservlets/issues/detail?id=172
+ * Possible to add contact Header to 200 OK to OPTIONS
+ */
+ public void testShootmeOptions() throws Exception {
+ String fromName = "sender";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ sender.sendSipRequest("OPTIONS", fromAddress, fromAddress, null, null,
false);
+ Thread.sleep(TIMEOUT);
+ assertTrue(sender.isFinalResponseReceived());
+ assertEquals(200, sender.getFinalResponseStatus());
+ ContactHeader contactHeader = (ContactHeader)
sender.getFinalResponse().getHeader(ContactHeader.NAME);
+ assertNotNull(contactHeader);
+
assertEquals(((SipURI)contactHeader.getAddress().getURI()).toString(),"sip:[email protected]:3289");
+ }
/**
* non regression test for Issue 1104
http://code.google.com/p/mobicents/issues/detail?id=1104
=======================================
---
/sip-servlets-test-suite/testsuite/src/test/resources/org/mobicents/servlet/sip/testsuite/simple/simple-sip-servlet-dar.properties
Thu Oct 2 08:20:59 2008
+++
/sip-servlets-test-suite/testsuite/src/test/resources/org/mobicents/servlet/sip/testsuite/simple/simple-sip-servlet-dar.properties
Mon Jan 28 09:54:52 2013
@@ -1,2 +1,3 @@
INVITE:
("org.mobicents.servlet.sip.testsuite.SimpleApplication", "DAR:From", "ORIGINATING", "", "NO_ROUTE", "0")
REGISTER:
("org.mobicents.servlet.sip.testsuite.SimpleApplication", "DAR:From", "ORIGINATING", "", "NO_ROUTE", "0")
+OPTIONS:
("org.mobicents.servlet.sip.testsuite.SimpleApplication", "DAR:From", "ORIGINATING", "", "NO_ROUTE", "0")
--
---
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/groups/opt_out.