Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for SIP Refer to support plus sign (+) in IncomingPhoneNumber #1772

Merged
merged 1 commit into from Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -758,9 +758,22 @@ private void transfer(SipServletRequest request) throws Exception {
return;
}

IncomingPhoneNumber number = storage.getIncomingPhoneNumbersDao().getIncomingPhoneNumber(cdr.getTo());
final IncomingPhoneNumbersDao numbers = storage.getIncomingPhoneNumbersDao();
String phone = cdr.getTo();
IncomingPhoneNumber number = numbers.getIncomingPhoneNumber(phone);
if(number == null){
if (phone.startsWith("+")) {
//remove the (+) and check if exists
phone= phone.replaceFirst("\\+","");
number = numbers.getIncomingPhoneNumber(phone);
} else {
//Add "+" add check if number exists
phone = "+".concat(phone);
number = numbers.getIncomingPhoneNumber(phone);
}
}
if (number == null) {
number = storage.getIncomingPhoneNumbersDao().getIncomingPhoneNumber("*");
number = numbers.getIncomingPhoneNumber("*");
}

if (number == null || (number.getReferUrl() == null && number.getReferApplicationSid() == null)) {
Expand Down
Expand Up @@ -419,6 +419,132 @@ public void testTransferToAnyNumber() throws ParseException, InterruptedExceptio
assertTrue(maxConcurrentOutgoingCalls==1);
}

@Test
public void testTransferToNumberWithPlusSign() throws ParseException, InterruptedException, MalformedURLException, SipException {

stubFor(get(urlPathEqualTo("/1112"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(dialGeorgeRcml)));

stubFor(get(urlPathEqualTo("/2222"))
.withQueryParam("ReferTarget", equalTo("alice"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(dialAliceRcml)));

SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));

SipCall georgeCall = georgePhone.createSipCall();
georgeCall.listenForIncomingCall();

SipCall aliceCall = alicePhone.createSipCall();
aliceCall.listenForIncomingCall();

final SipCall bobCall = bobPhone.createSipCall();

bobCall.initiateOutgoingCall(bobContact, "sip:1112@127.0.0.1:5080", null, body, "application", "sdp", null, null);

assertLastOperationSuccess(bobCall);
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
final int callResponse = bobCall.getLastReceivedResponse().getStatusCode();
assertTrue(callResponse == Response.TRYING || callResponse == Response.RINGING);
logger.info("Last response: "+callResponse);

if (callResponse == Response.TRYING) {
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
logger.info("Last response: "+bobCall.getLastReceivedResponse().getStatusCode());
}

assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());
assertTrue(bobCall.sendInviteOkAck());

assertTrue(georgeCall.waitForIncomingCall(5000));
assertTrue(georgeCall.sendIncomingCallResponse(Response.TRYING, "George-Trying", 3600));
assertTrue(georgeCall.sendIncomingCallResponse(Response.RINGING, "George-Ringing", 3600));

SipRequest lastReceivedRequest = georgeCall.getLastReceivedRequest();
String receivedBody = new String(lastReceivedRequest.getRawContent());
assertTrue(georgeCall.sendIncomingCallResponse(Response.OK, "George-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(georgeCall.waitForAck(5000));

SipURI referTo = georgeSipStack.getAddressFactory().createSipURI("alice", "127.0.0.1:5080");

ReferSubscriber subscription = georgePhone.refer(georgeCall.getDialog(), referTo, null, 5000);
assertNotNull(subscription);
assertTrue(subscription.isSubscriptionPending());

assertTrue(subscription.processResponse(1000));
assertTrue(subscription.isSubscriptionPending());
assertNoSubscriptionErrors(subscription);

georgeCall.listenForDisconnect();
assertTrue(georgeCall.waitForDisconnect(10000));
assertTrue(georgeCall.respondToDisconnect());

assertTrue(aliceCall.waitForIncomingCall(5000));
assertTrue(aliceCall.sendIncomingCallResponse(Response.TRYING, "Alice-Trying", 3600));
assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Alice-Ringing", 3600));
receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
assertTrue(aliceCall.sendIncomingCallResponse(Response.OK, "Alice-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(aliceCall.waitForAck(5000));

int liveCalls = MonitoringServiceTool.getInstance().getLiveCalls(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
int liveIncomingCalls = MonitoringServiceTool.getInstance().getLiveIncomingCalls(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
int liveOutgoingCalls = MonitoringServiceTool.getInstance().getLiveOutgoingCalls(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
int liveCallsArraySize = MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
assertTrue(liveCalls==2);
assertTrue(liveIncomingCalls==1);
assertTrue(liveOutgoingCalls==1);
assertTrue(liveCallsArraySize==2);

bobCall.listenForDisconnect();

assertTrue(aliceCall.disconnect());

assertTrue(bobCall.waitForDisconnect(5000));
assertTrue(bobCall.respondToDisconnect());

Thread.sleep(10000);

logger.info("About to check the Requests");
List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1112")));
assertTrue(requests.size() == 1);
String requestBody = new URL(requests.get(0).getAbsoluteUrl()).getQuery();
List<String> params = Arrays.asList(requestBody.split("&"));
String callSid = "";
for (String param : params) {
if (param.contains("CallSid")) {
callSid = param.split("=")[1];
}
}
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
JsonObject jsonObj = cdr.getAsJsonObject();
assertTrue(jsonObj.get("status").getAsString().equalsIgnoreCase("completed"));

JsonObject metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
assertNotNull(metrics);
liveCalls = metrics.getAsJsonObject("Metrics").get("LiveCalls").getAsInt();
logger.info("LiveCalls: "+liveCalls);
liveCallsArraySize = metrics.getAsJsonArray("LiveCallDetails").size();
logger.info("LiveCallsArraySize: "+liveCallsArraySize);
assertTrue(liveCalls==0);
assertTrue(liveCallsArraySize==0);
int maxConcurrentCalls = metrics.getAsJsonObject("Metrics").get("MaximumConcurrentCalls").getAsInt();
int maxConcurrentIncomingCalls = metrics.getAsJsonObject("Metrics").get("MaximumConcurrentIncomingCalls").getAsInt();
int maxConcurrentOutgoingCalls = metrics.getAsJsonObject("Metrics").get("MaximumConcurrentIncomingCalls").getAsInt();
assertTrue(maxConcurrentCalls==2);
assertTrue(maxConcurrentIncomingCalls==1);
assertTrue(maxConcurrentOutgoingCalls==1);
}

@Test
public void testTransferHangupByBob() throws ParseException, InterruptedException, MalformedURLException, SipException {

Expand Down
Expand Up @@ -31,4 +31,5 @@ INSERT INTO "restcomm_clients" VALUES('CLa2b99142e111427fbb489c3de357f60a','2013
INSERT INTO "restcomm_clients" VALUES('CLa2b99142e111427fbb489c3de357f70a','2013-11-04 12:52:44.144000000','2013-11-04 12:52:44.144000000','ACae6e420f425248d6a26948c17a9e2acf','2012-04-24','henrique','henrique','1234',1,NULL,'POST',NULL,'POST',NULL,'/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Clients/CLa2b99142e111427fbb489c3de357f70a')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e2acf','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number','ACae6e420f425248d6a26948c17a9e2acf','*','2012-04-24',FALSE,'http://127.0.0.1:8090/gottacatchemall','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e2acf', NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,null,'http://127.0.0.1:8090/2222','GET')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e2bcf','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number 2','ACae6e420f425248d6a26948c17a9e2acf','1111','2012-04-24',FALSE,'http://127.0.0.1:8090/1111','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e2bcf', NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,null,'http://127.0.0.1:8090/2222','GET')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e3bcf','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number 2','ACae6e420f425248d6a26948c17a9e2acf','+1112','2012-04-24',FALSE,'http://127.0.0.1:8090/1112','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e2bcf', NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,null,'http://127.0.0.1:8090/2222','GET')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e21cf','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number 3','ACae6e420f425248d6a26948c17a9e2acf','1212','2012-04-24',FALSE,'http://127.0.0.1:8090/1111','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e21cf', NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,null,null,'GET')