Revision: 25a527437285
Author: Jean Deruelle <[email protected]>
Date: Fri Apr 25 16:34:22 2014 UTC
Log: Update Issue 137
Fix + non regression test
http://code.google.com/p/sipservlets/source/detail?r=25a527437285
Modified:
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletMessageImpl.java
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletResponseImpl.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/ShootmeSipServletTest.java
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletMessageImpl.java
Fri Apr 25 10:23:54 2014 UTC
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletMessageImpl.java
Fri Apr 25 16:34:22 2014 UTC
@@ -148,9 +148,9 @@
// was received. Applications can determine the actual IP address of the
UA
// that originated the message from the message Via header fields.
// But for upstream - thats a proxy stuff, fun with ReqURI, RouteHeader
- protected transient InetAddress remoteAddr = null;
+ //protected transient InetAddress remoteAddr = null;
- protected transient int remotePort = -1;
+ //protected transient int remotePort = -1;
protected transient String transport = null;
@@ -986,6 +986,12 @@
}
} else {
ViaHeader via = (ViaHeader)
message.getHeader(ViaHeader.NAME);
+ //
https://code.google.com/p/sipservlets/issues/detail?id=137
+ boolean isExternal =
sipFactoryImpl.getSipApplicationDispatcher().isViaHeaderExternal(via);
+ if(message instanceof Request && !isExternal) {
+ // locally generated messages should return null as
per Javadoc
+ return null;
+ }
if(via == null) {
return null;
} else {
@@ -1009,6 +1015,12 @@
}
} else {
ViaHeader via = (ViaHeader)
message.getHeader(ViaHeader.NAME);
+ //
https://code.google.com/p/sipservlets/issues/detail?id=137
+ boolean isExternal =
sipFactoryImpl.getSipApplicationDispatcher().isViaHeaderExternal(via);
+ if(message instanceof Request && !isExternal) {
+ // locally generated messages should return -1 as per
Javadoc
+ return -1;
+ }
if(via != null) {
port = via.getPort();
}
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletResponseImpl.java
Tue Mar 11 18:46:24 2014 UTC
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletResponseImpl.java
Fri Apr 25 16:34:22 2014 UTC
@@ -869,4 +869,21 @@
public boolean isRetransmission() {
return isRetransmission;
}
+
+ // https://code.google.com/p/sipservlets/issues/detail?id=137
+ @Override
+ public String getRemoteAddr() {
+ if(!hasBeenReceived) {
+ return null;
+ }
+ return super.getRemoteAddr();
+ }
+
+ @Override
+ public int getRemotePort() {
+ if(!hasBeenReceived) {
+ return -1;
+ }
+ return super.getRemotePort();
+ }
}
=======================================
---
/sip-servlets-test-suite/applications/simple-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/SimpleSipServlet.java
Fri Apr 18 10:10:51 2014 UTC
+++
/sip-servlets-test-suite/applications/simple-sip-servlet/src/main/java/org/mobicents/servlet/sip/testsuite/SimpleSipServlet.java
Fri Apr 25 16:34:22 2014 UTC
@@ -100,6 +100,7 @@
private static final String TEST_SYSTEM_HEADER_MODIFICATION
= "systemHeaderModification";
private static final String TEST_SERIALIZATION = "serialization";
private static final String TEST_FROM_TO_HEADER_MODIFICATION
= "fromToHeaderModification";
+ private static final String TEST_LOCALLY_GENERATED_REMOTE_ADDRESS
= "locallyGeneratedRemoteAddress";
@Resource
SipFactory sipFactory;
@@ -148,6 +149,16 @@
request.createResponse(SipServletResponse.SC_OK).send();
return;
}
+ if(fromString.contains(TEST_LOCALLY_GENERATED_REMOTE_ADDRESS)) {
+ //
https://code.google.com/p/sipservlets/issues/detail?id=137
+ SipServletResponse sipServletResponse =
request.createResponse(SipServletResponse.SC_OK);
+ if(sipServletResponse.getRemoteAddr() != null) {
+
request.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR, "getRemoteAddr
not null as it should be since response is locally generated").send();
+ return;
+ }
+ sipServletResponse.send();
+ return;
+ }
String sipSessionId = request.getSession().getId();
SipSession sipSession =
request.getApplicationSession().getSipSession(sipSessionId);
if(sipSession == null ||
!sipSession.equals(request.getSession())) {
@@ -606,7 +617,7 @@
nbOfAcks =
Integer.valueOf(nbOfAcks.intValue() + 1);
}
req.getSession().setAttribute("nbAcks",
nbOfAcks);
- } else
if(TEST_IS_SIP_SERVLET_SEND_BYE.equalsIgnoreCase(((SipURI)req.getFrom().getURI()).getUser()))
{
+ } else
if(TEST_IS_SIP_SERVLET_SEND_BYE.equalsIgnoreCase(((SipURI)req.getFrom().getURI()).getUser())
||
TEST_LOCALLY_GENERATED_REMOTE_ADDRESS.equalsIgnoreCase(((SipURI)req.getFrom().getURI()).getUser()))
{
timerService.createTimer(req.getApplicationSession(), timeout, false,
(Serializable)req.getSession());
} else
if(TEST_EXCEPTION_ON_EXPIRE.equalsIgnoreCase(((SipURI)req.getFrom().getURI()).getUser()))
{
try {
@@ -846,7 +857,12 @@
}
} else if(info instanceof SipSession){
try {
- ((SipSession)info).createRequest("BYE").send();
+ SipServletRequest bye =
((SipSession)info).createRequest("BYE");
+
if(bye.getTo().getURI().toString().contains(TEST_LOCALLY_GENERATED_REMOTE_ADDRESS)
&& bye.getRemoteAddr() != null) {
+ throw new IllegalStateException("remoteport
should be null");
+ } else {
+ bye.send();
+ }
} catch (IOException e) {
e.printStackTrace();
}
=======================================
---
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootmeSipServletTest.java
Fri Apr 18 10:10:51 2014 UTC
+++
/sip-servlets-test-suite/testsuite/src/test/java/org/mobicents/servlet/sip/testsuite/simple/ShootmeSipServletTest.java
Fri Apr 25 16:34:22 2014 UTC
@@ -782,6 +782,27 @@
assertNotNull(serverHeader);
assertTrue(serverHeader.toString().contains("MobicentsSipServletsServer"));
}
+
+ /*
+ * https://code.google.com/p/sipservlets/issues/detail?id=137
+ */
+ public void testShootmeResponseGetRemoteAddress() throws
InterruptedException, SipException, ParseException,
InvalidArgumentException {
+ String fromName = "locallyGeneratedRemoteAddress";
+ String fromSipAddress = "sip-servlets.com";
+ SipURI fromAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ fromName, fromSipAddress);
+
+ String toUser = "receiver";
+ String toSipAddress = "sip-servlets.com";
+ SipURI toAddress =
senderProtocolObjects.addressFactory.createSipURI(
+ toUser, toSipAddress);
+
+ sender.setSendBye(false);
+ sender.sendSipRequest("INVITE", fromAddress, toAddress, null,
null, false);
+ Thread.sleep(TIMEOUT*2);
+ assertTrue(sender.isAckSent());
+ assertTrue(sender.getByeReceived());
+ }
@Override
@After
--
---
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.