Skip to content

Commit

Permalink
CLOUDOPS-391: Fix UssdCM for ExecuteCallScript. Fix UssdPushTest, Cal…
Browse files Browse the repository at this point in the history
…lRegexTest
  • Loading branch information
abdulazizali77 committed Nov 24, 2017
1 parent 0d024a7 commit f89c4f4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
Expand Up @@ -1597,34 +1597,34 @@ public void testUssdPull() {
.withBody(ussdRcml)));


final SipCall bobCall = alicePhone.createSipCall();
bobCall.initiateOutgoingCall(bobContact, "sip:*777#@" + restcommContact, null, ussdClientRequestBody, "application", "vnd.3gpp.ussd+xml", null, null);
assertLastOperationSuccess(bobCall);
bobCall.waitForAuthorisation(30 * 1000);
final SipCall aliceCall = alicePhone.createSipCall();
aliceCall.initiateOutgoingCall(aliceContact, "sip:*777#@" + restcommContact, null, ussdClientRequestBody, "application", "vnd.3gpp.ussd+xml", null, null);
assertLastOperationSuccess(aliceCall);
//aliceCall.waitForAuthorisation(30 * 1000);

assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
int responseBob = bobCall.getLastReceivedResponse().getStatusCode();
assertTrue(aliceCall.waitOutgoingCallResponse(5 * 1000));
int responseBob = aliceCall.getLastReceivedResponse().getStatusCode();
if (responseBob == Response.TRYING) {
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
assertTrue(bobCall.getLastReceivedResponse().getStatusCode() == Response.RINGING);
assertTrue(aliceCall.waitOutgoingCallResponse(5 * 1000));
assertTrue(aliceCall.getLastReceivedResponse().getStatusCode() == Response.RINGING);
} else {
assertTrue(bobCall.getLastReceivedResponse().getStatusCode() == Response.RINGING);
assertTrue(aliceCall.getLastReceivedResponse().getStatusCode() == Response.RINGING);
}

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

assertTrue(bobCall.getDialog().getState().getValue()== DialogState._CONFIRMED);
assertTrue(aliceCall.getDialog().getState().getValue()== DialogState._CONFIRMED);

assertTrue(bobCall.listenForDisconnect());
assertTrue(aliceCall.listenForDisconnect());

assertTrue(bobCall.waitForDisconnect(30 * 1000));
bobCall.respondToDisconnect();
SipRequest bye = bobCall.getLastReceivedRequest();
assertTrue(aliceCall.waitForDisconnect(30 * 1000));
aliceCall.respondToDisconnect();
SipRequest bye = aliceCall.getLastReceivedRequest();
String receivedUssdPayload = new String(bye.getRawContent());
assertTrue(receivedUssdPayload.equalsIgnoreCase(ussdRestcommResponse.trim()));
bobCall.dispose();
aliceCall.dispose();

}

Expand Down
Expand Up @@ -34,7 +34,6 @@ INSERT INTO "restcomm_accounts" VALUES('ACae6e420f425248d6a26948c17a9e2acf','201
INSERT INTO "restcomm_accounts" VALUES('ACae6e420f425248d6a26948c17a9e2acg','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','subadministrator@company.com','Sub Administrator Account','ACae6e420f425248d6a26948c17a9e2acf','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acg','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_clients" VALUES('CLa2b99142e111427fbb489c3de357f60a','2013-11-04 12:52:44.144000000','2013-11-04 12:52:44.144000000','ACae6e420f425248d6a26948c17a9e2acf','2012-04-24','alice','alice','1234',1,NULL,'POST',NULL,'POST',NULL,'/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Clients/CLa2b99142e111427fbb489c3de357f60a',NULL)
INSERT INTO "restcomm_clients" VALUES('CLa2b99142e111427fbb489c3de357f60b','2013-11-04 12:52:44.144000000','2013-11-04 12:52:44.144000000','ACae6e420f425248d6a26948c17a9e2acg','2012-04-24','subaccountclient','subaccountclient','1234',1,NULL,'POST',NULL,'POST',NULL,'/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acg/Clients/CLa2b99142e111427fbb489c3de357f60b',NULL)
INSERT INTO "restcomm_clients" VALUES('CLa2b99142e111427fbb489c3de357f60c','2013-11-04 12:52:44.144000000','2013-11-04 12:52:44.144000000','ACae6e420f425248d6a26948c17a9e2acf','2012-04-24','bob','bob','1234',1,NULL,'POST',NULL,'POST',NULL,'/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Clients/CLa2b99142e111427fbb489c3de357f60c',NULL)
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e2aca','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number0','ACae6e420f425248d6a26948c17a9e2acf','1313','2012-04-24',FALSE,'http://127.0.0.1:8090/1313','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e2aca',NULL,NULL,NULL,NULL, TRUE,'0.0','http://127.0.0.1:8080/restcomm/ussd-rcml.xml','GET', NULL, NULL, NULL, NULL, NULL, NULL, 'ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e2acf','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number1','ACae6e420f425248d6a26948c17a9e2acf','7777|8888','2012-04-24',FALSE,'http://127.0.0.1:8090/regex','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e2acf',NULL,NULL,NULL,NULL, TRUE,'0.0','http://127.0.0.1:8080/restcomm/ussd-rcml.xml','GET', NULL, NULL, NULL, NULL, NULL, NULL, 'ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PHae6e420f425248d6a26948c17a9e2acg','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','Test Number 2','ACae6e420f425248d6a26948c17a9e2acf','^*77...33#$','2012-04-24',FALSE,'http://127.0.0.1:8090/regex','GET',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PHae6e420f425248d6a26948c17a9e2acg',NULL,NULL,NULL,NULL, TRUE,'0.0','http://127.0.0.1:8080/restcomm/ussd-rcml.xml','GET', NULL, NULL, NULL, NULL, NULL, NULL, 'ORafbe225ad37541eba518a74248f0ac4c')
Expand Down
Expand Up @@ -26,13 +26,13 @@

import java.io.IOException;
import java.util.List;

import java.util.regex.Pattern;

import javax.servlet.ServletContext;
import javax.servlet.sip.ServletParseException;
import javax.servlet.sip.SipApplicationSession;
import javax.servlet.sip.SipFactory;
import javax.servlet.sip.SipServletMessage;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;
import javax.servlet.sip.SipURI;
Expand All @@ -41,7 +41,6 @@
import org.restcomm.connect.commons.configuration.RestcommConfiguration;
import org.restcomm.connect.commons.configuration.sets.RcmlserverConfigurationSet;
import org.restcomm.connect.commons.dao.Sid;

import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor;
import org.restcomm.connect.commons.util.UriUtils;
import org.restcomm.connect.dao.AccountsDao;
Expand Down Expand Up @@ -151,7 +150,7 @@ public void onReceive(final Object message) throws Exception {
final Class<?> klass = message.getClass();
final ActorRef self = self();
final ActorRef sender = sender();

boolean needAuthorization = true;
//FIXME: really kludgy and ugly
Account effectiveAccount = null;
AccountsDao accountsDao = storage.getAccountsDao();
Expand All @@ -160,16 +159,25 @@ public void onReceive(final Object message) throws Exception {
effectiveAccount = accountsDao.getAccount(this.createCallRequest.accountId());
}else if (message instanceof SipServletRequest){
effectiveAccount = accountsDao.getAccount(getAccountIdFromSipRequest((SipServletRequest) message));
} else if (message instanceof ExecuteCallScript) {
effectiveAccount = accountsDao.getAccount(((ExecuteCallScript )message).account());
} else if (ExecuteCallScript.class.equals(klass)) {
effectiveAccount = accountsDao.getAccount(((ExecuteCallScript )message).account());
} else if (message instanceof SipServletResponse){
//getAccountIdFromSipRequest((SipServletResponse) message);
needAuthorization = false;
}


// UserIdentityContext uic = new UserIdentityContext(effectiveAccount, accountsDao);
// permissionsUtil.setUserIdentityContext(uic);
try {
permissionsUtil.checkPermission("Restcomm:*:Ussd", effectiveAccount.getSid());
} catch (Exception e) {
logger.debug("No permission for USSD feature "+e);
return;
if(needAuthorization){
try {
permissionsUtil.checkPermission("Restcomm:*:Ussd", effectiveAccount.getSid());
} catch (Exception e) {
logger.debug("No permission for USSD feature "+e);
return;
}
}
if (message instanceof SipServletRequest) {
final SipServletRequest request = (SipServletRequest) message;
Expand Down Expand Up @@ -201,13 +209,12 @@ public void onReceive(final Object message) throws Exception {

}

private Sid getAccountIdFromSipRequest(SipServletRequest request) {
private Sid getAccountIdFromSipRequest(SipServletMessage request) {
final ClientsDao clients = storage.getClientsDao();
//FIXME: a null check is faster?
Sid accountSid = null ; //Sid.generate(Type.INVALID);

//TODO: implement get from Proxy-Authorization

final SipURI fromUri = (SipURI) request.getFrom().getURI();
Sid sourceOrganizationSid = OrganizationUtil.getOrganizationSidBySipURIHost(storage, fromUri);
if(logger.isDebugEnabled()) {
Expand All @@ -225,9 +232,9 @@ private Sid getAccountIdFromSipRequest(SipServletRequest request) {
}

//TODO: if not available from From, should we actually get the accountSid from the To??
if(accountSid == null){
final String toUser = CallControlHelper.getUserSipId(request, useTo);
MostOptimalNumberResponse mostOptimalNumber = OrganizationUtil.getMostOptimalIncomingPhoneNumber(storage, request, toUser, sourceOrganizationSid);
if(accountSid == null && (request instanceof SipServletRequest)){
final String toUser = CallControlHelper.getUserSipId((SipServletRequest)request, useTo);
MostOptimalNumberResponse mostOptimalNumber = OrganizationUtil.getMostOptimalIncomingPhoneNumber(storage, (SipServletRequest)request, toUser, sourceOrganizationSid);
IncomingPhoneNumber number = mostOptimalNumber.number();
if(number!=null){
accountSid = number.getAccountSid();
Expand Down

0 comments on commit f89c4f4

Please sign in to comment.