Skip to content

Commit

Permalink
Fixes for #288. This closes #288
Browse files Browse the repository at this point in the history
  • Loading branch information
gvagenas committed Jun 13, 2015
1 parent 40f6149 commit deb3081
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
2 changes: 1 addition & 1 deletion release/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<property name="restcomm.docs.as7.dir" location="${release.as7.dir}/docs/restcomm" />

<!--mobicents binaries versions-->
<property name="sipservlets-build" value="602"/>
<property name="sipservlets-build" value="605"/>
<property name="mobicents-sipservlets-as7.version" value="3.1.${sipservlets-build}" />
<!--<property name="jain-sip-ri.version" value="7.0.3.190" />-->
<property name="mobicents-media.version" value="3.0.2.Final" />
Expand Down
4 changes: 2 additions & 2 deletions restcomm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<javamail.version>1.4</javamail.version>
<servletapi.version>2.5</servletapi.version>
<!-- <sipservletapi.version>7.0.0.GA-TelScale</sipservletapi.version> -->
<sipservletapi.version>3.1.602</sipservletapi.version>
<sipservletapi.version>3.1.605</sipservletapi.version>
<staxapi.version>1.0.1</staxapi.version>
<staximpl.version>1.2.0</staximpl.version>
<servlet-api.version>7.0.50</servlet-api.version>
Expand All @@ -105,7 +105,7 @@
<scalatest.version>1.9.1</scalatest.version>
<hsqldb.version>2.3.2</hsqldb.version>
<!-- <sip-ri.version>1.2.167</sip-ri.version> -->
<sip-ri.version>1.2.228</sip-ri.version>
<sip-ri.version>1.2.233</sip-ri.version>
<arquillian.version>1.0.3.Final</arquillian.version>
<mss.arquillian.version>1.0.0-CR1</mss.arquillian.version>
<mss.shrinkwrap.version>1.0.0-CR1</mss.shrinkwrap.version>
Expand Down
8 changes: 4 additions & 4 deletions restcomm/restcomm.application/src/main/webapp/WEB-INF/sip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</pattern>
</servlet-mapping>
</servlet-selection>

<servlet>
<servlet-name>RestComm</servlet-name>
<display-name>RestComm</display-name>
Expand All @@ -62,7 +62,7 @@
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet>
<servlet-name>SmsService</servlet-name>
<display-name>SmsService</display-name>
Expand Down Expand Up @@ -92,7 +92,7 @@
</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>

<servlet>
<servlet-name>ProxyManager</servlet-name>
<display-name>ProxyManager</display-name>
Expand All @@ -108,7 +108,7 @@
org.mobicents.servlet.restcomm.Bootstrapper
</listener-class>
</listener>
<listener>
<listener>
<listener-class>
org.mobicents.servlet.restcomm.sms.SmsServiceProxy
</listener-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ public static boolean redirectToB2BUA(final SipServletRequest request, final Cli
if (fromClient != null) {
Address fromAddress = sipFactory.createAddress(from, fromClient.getFriendlyName());
Address toAddress = sipFactory.createAddress(to, to.getUser());
outRequest = sipFactory.createRequest(request.getApplicationSession(), request.getMethod(), fromAddress, toAddress);
outRequest = sipFactory.createRequest(request.getApplicationSession(), request.getMethod(), fromAddress,
toAddress);
} else {
outRequest = sipFactory.createRequest(request.getApplicationSession(), request.getMethod(), from, to);
}
Expand Down Expand Up @@ -419,10 +420,27 @@ public static void forwardResponse(final SipServletResponse response) throws IOE
}
return;
}

// We don't forward 200 OK Response to BYE.
if (response.getStatus() == 200 && response.getMethod().equalsIgnoreCase("BYE")) {
if (logger.isDebugEnabled()) {
logger.debug("response to BYE not forwarding");
}
return;
}
// forward the response
response.getSession().setAttribute(B2BUA_LAST_RESPONSE, response);
SipServletRequest request = (SipServletRequest) getLinkedSession(response).getAttribute(B2BUA_LAST_REQUEST);
SipServletResponse resp = request.createResponse(response.getStatus());
SipURI originalURI = null;
Address contact = null;
try {
originalURI = (SipURI) response.getAddressHeader("Contact").getURI();
((SipURI) resp.getAddressHeader("Contact").getURI()).setUser(originalURI.getUser());
contact = resp.getAddressHeader("Contact");
} catch (ServletParseException e1) {}
catch (NullPointerException e2) {}
logger.info("Contact: " + contact);
CallDetailRecord callRecord = records.getCallDetailRecord((Sid) request.getSession().getAttribute(CDR_SID));

if (response.getContent() != null) {
Expand Down Expand Up @@ -483,6 +501,34 @@ public static void forwardResponse(final SipServletResponse response) throws IOE

}

public static void updateCDR(SipServletMessage message, CallStateChanged.State state) {
CallDetailRecordsDao records = daoManager.getCallDetailRecordsDao();
SipServletRequest request = null;

// Update CallDetailRecord
if (message instanceof SipServletResponse) {
request = (SipServletRequest) getLinkedSession((SipServletResponse) message).getAttribute(B2BUA_LAST_REQUEST);
} else if (message instanceof SipServletRequest) {
request = (SipServletRequest) message;
}
CallDetailRecord callRecord = records.getCallDetailRecord((Sid) request.getSession().getAttribute(CDR_SID));

if (callRecord != null) {
logger.info("CDR found! Updating");
callRecord = callRecord.setStatus(state.name());
final DateTime now = DateTime.now();
callRecord = callRecord.setEndTime(now);
int seconds;
if (callRecord.getStartTime() != null) {
seconds = (int) (DateTime.now().getMillis() - callRecord.getStartTime().getMillis()) / 1000;
} else {
seconds = 0;
}
callRecord = callRecord.setDuration(seconds);
records.updateCallDetailRecord(callRecord);
}
}

/**
* Check whether a SIP request or response belongs to a peer to peer (B2BUA) session
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.servlet.sip.SipServletResponse;
import javax.servlet.sip.SipSession;
import javax.servlet.sip.SipURI;
import javax.sip.message.Response;

import org.apache.commons.configuration.Configuration;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -951,6 +952,8 @@ public void bye(final Object message) throws IOException {
if (logger.isInfoEnabled()) {
logger.info(String.format("B2BUA: Got BYE request: \n %s", request));
}

//Prepare the BYE request to the linked session
request.getSession().setAttribute(B2BUAHelper.B2BUA_LAST_REQUEST, request);
SipServletRequest clonedBye = linkedB2BUASession.createRequest("BYE");
linkedB2BUASession.setAttribute(B2BUAHelper.B2BUA_LAST_REQUEST, clonedBye);
Expand Down Expand Up @@ -980,6 +983,11 @@ public void bye(final Object message) throws IOException {
clonedBye.setRequestURI(fromInetUri);
}
}
B2BUAHelper.updateCDR(request, CallStateChanged.State.COMPLETED);
//Prepare 200 OK for received BYE
SipServletResponse okay = request.createResponse(Response.OK);
okay.send();
//Send the Cloned BYE
clonedBye.send();
} else {
final ActorRef call = (ActorRef) application.getAttribute(Call.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ private void register(final Object message) throws Exception {
// request.getSession().invalidate();
// }
if (request.getApplicationSession().isValid()) {
request.getApplicationSession().invalidate();
try {
request.getApplicationSession().invalidate();
} catch (IllegalStateException exception) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public void run() {

assertTrue(!(mariaCall.getLastReceivedResponse().getStatusCode() >= 400));

assertTrue(dimitriCall.waitForAck(3000));

Thread.sleep(3000);
dimitriCall.listenForDisconnect();
assertTrue(mariaCall.disconnect());
Expand Down
8 changes: 4 additions & 4 deletions restcomm/restcomm.testsuite/src/test/resources/sip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</pattern>
</servlet-mapping>
</servlet-selection>

<servlet>
<servlet-name>RestComm</servlet-name>
<display-name>RestComm</display-name>
Expand All @@ -62,7 +62,7 @@
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet>
<servlet-name>SmsService</servlet-name>
<display-name>SmsService</display-name>
Expand Down Expand Up @@ -92,7 +92,7 @@
</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>

<servlet>
<servlet-name>ProxyManager</servlet-name>
<display-name>ProxyManager</display-name>
Expand All @@ -108,7 +108,7 @@
org.mobicents.servlet.restcomm.Bootstrapper
</listener-class>
</listener>
<listener>
<listener>
<listener-class>
org.mobicents.servlet.restcomm.sms.SmsServiceProxy
</listener-class>
Expand Down

0 comments on commit deb3081

Please sign in to comment.