Skip to content

Commit a52b6e5

Browse files
committed
Merge branch 'master' of github.com:RestComm/Restcomm-Connect
2 parents af93f70 + d2ced7f commit a52b6e5

20 files changed

Lines changed: 327 additions & 87 deletions

File tree

restcomm/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,14 @@
564564
<groupId>org.apache.tomcat</groupId>
565565
<artifactId>tomcat-coyote</artifactId>
566566
<version>${tomcat7.version}</version>
567-
<scope>provided</scope>
567+
<scope>test</scope>
568568
</dependency>
569569

570570
<dependency>
571571
<groupId>org.apache.tomcat</groupId>
572572
<artifactId>tomcat-jasper</artifactId>
573573
<version>${tomcat7.version}</version>
574-
<scope>provided</scope>
574+
<scope>test</scope>
575575
</dependency>
576576

577577
<dependency>
@@ -585,20 +585,21 @@
585585
<groupId>org.mobicents.servlet.sip.containers</groupId>
586586
<artifactId>sip-servlets-catalina-7</artifactId>
587587
<version>${sipservletapi.version}</version>
588-
<scope>provided</scope>
588+
<scope>test</scope>
589589
</dependency>
590590

591591
<dependency>
592592
<groupId>org.mobicents.servlet.sip</groupId>
593593
<artifactId>sip-servlets-application-router</artifactId>
594594
<version>${sipservletapi.version}</version>
595-
<scope>provided</scope>
595+
<scope>test</scope>
596596
</dependency>
597597

598598
<dependency>
599599
<groupId>org.hsqldb</groupId>
600600
<artifactId>hsqldb</artifactId>
601601
<version>${hsqldb.version}</version>
602+
<scope>test</scope>
602603
</dependency>
603604

604605
<!--

restcomm/restcomm.application/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@
6565
<dependency>
6666
<groupId>org.mobicents.servlet.sip</groupId>
6767
<artifactId>sip-servlets-spec</artifactId>
68-
<version>${sipservletapi.version}</version>
6968
<scope>provided</scope>
7069
</dependency>
70+
71+
<dependency>
72+
<groupId>org.mobicents.servlet.sip.containers</groupId>
73+
<artifactId>sip-servlets-catalina-7</artifactId>
74+
<scope>provided</scope>
75+
</dependency>
7176

7277
<dependency>
7378
<groupId>javax.servlet</groupId>

restcomm/restcomm.commons/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
<groupId>javax.mail</groupId>
7575
<artifactId>mail</artifactId>
7676
</dependency>
77+
78+
<dependency>
79+
<groupId>com.google.code.gson</groupId>
80+
<artifactId>gson</artifactId>
81+
</dependency>
7782

7883
<dependency>
7984
<groupId>junit</groupId>

restcomm/restcomm.dao/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@
6767
<version>${project.version}</version>
6868
<scope>provided</scope>
6969
</dependency>
70+
71+
<dependency>
72+
<groupId>org.apache.tomcat</groupId>
73+
<artifactId>tomcat-coyote</artifactId>
74+
<scope>provided</scope>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>org.mobicents.servlet.sip.containers</groupId>
79+
<artifactId>sip-servlets-catalina-7</artifactId>
80+
<scope>provided</scope>
81+
</dependency>
7082

7183
<dependency>
7284
<groupId>com.googlecode.libphonenumber</groupId>

restcomm/restcomm.dao/src/main/java/org/restcomm/connect/dao/common/OrganizationUtil.java

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -44,93 +44,100 @@ public class OrganizationUtil {
4444

4545
private static Logger logger = Logger.getLogger(OrganizationUtil.class);
4646

47+
48+
public static MostOptimalNumberResponse getMostOptimalIncomingPhoneNumber(DaoManager storage, SipServletRequest request, String phone,
49+
Sid sourceOrganizationSid) {
50+
MostOptimalNumberResponse res = null;
51+
Sid destinationOrganizationSid = getOrganizationSidBySipURIHost(storage, (SipURI) request.getRequestURI());
52+
// try to get destinationOrganizationSid from toUril
53+
destinationOrganizationSid = destinationOrganizationSid != null ? destinationOrganizationSid : getOrganizationSidBySipURIHost(storage, (SipURI) request.getTo().getURI());
54+
if (destinationOrganizationSid == null) {
55+
logger.error("destinationOrganizationSid is NULL: request Uri is: " + (SipURI) request.getRequestURI() + " To Uri is: " + (SipURI) request.getTo().getURI());
56+
res = new MostOptimalNumberResponse(null, false);
57+
} else {
58+
if (logger.isDebugEnabled()) {
59+
logger.debug("getMostOptimalIncomingPhoneNumber: sourceOrganizationSid: " + sourceOrganizationSid + " : destinationOrganizationSid: " + destinationOrganizationSid + " request Uri is: " + (SipURI) request.getRequestURI() + " To Uri is: " + (SipURI) request.getTo().getURI());
60+
}
61+
res = getMostOptimalIncomingPhoneNumber(storage, destinationOrganizationSid, phone, sourceOrganizationSid);
62+
}
63+
return res;
64+
}
65+
4766
/**
4867
* @param storage DaoManager
4968
* @param request SipServletRequest
5069
* @param phone
5170
* @param sourceOrganizationSid organization Sid of request initiator
5271
* @return
5372
*/
54-
public static MostOptimalNumberResponse getMostOptimalIncomingPhoneNumber(DaoManager storage, SipServletRequest request, String phone,
73+
public static MostOptimalNumberResponse getMostOptimalIncomingPhoneNumber(DaoManager storage, Sid destinationOrganizationSid, String phone,
5574
Sid sourceOrganizationSid) {
56-
if(logger.isDebugEnabled())
57-
logger.debug("getMostOptimalIncomingPhoneNumber: "+phone);
5875

5976
IncomingPhoneNumber number = null;
6077
boolean failCall = false;
6178
List<IncomingPhoneNumber> numbers = new ArrayList<IncomingPhoneNumber>();
6279
final IncomingPhoneNumbersDao numbersDao = storage.getIncomingPhoneNumbersDao();
6380
try{
64-
Sid destinationOrganizationSid = getOrganizationSidBySipURIHost(storage, (SipURI)request.getRequestURI());
65-
// try to get destinationOrganizationSid from toUril
66-
destinationOrganizationSid = destinationOrganizationSid != null ? destinationOrganizationSid : getOrganizationSidBySipURIHost(storage, (SipURI)request.getTo().getURI());
67-
if(destinationOrganizationSid == null){
68-
logger.error("destinationOrganizationSid is NULL: request Uri is: "+(SipURI)request.getRequestURI()+ " To Uri is: "+(SipURI)request.getTo().getURI());
69-
}else{
70-
if(logger.isDebugEnabled())
71-
logger.debug("getMostOptimalIncomingPhoneNumber: sourceOrganizationSid: "+sourceOrganizationSid+" : destinationOrganizationSid: "+destinationOrganizationSid +" request Uri is: "+(SipURI)request.getRequestURI()+ " To Uri is: "+(SipURI)request.getTo().getURI());
72-
73-
// Format the destination to an E.164 phone number.
74-
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
75-
String formatedPhone = null;
76-
if (!(phone.contains("*") || phone.contains("#"))) {
77-
try {
78-
formatedPhone = phoneNumberUtil.format(phoneNumberUtil.parse(phone, "US"), PhoneNumberFormat.E164);
79-
} catch (NumberParseException e) {
80-
//logger.error("Exception when try to format : " + e);
81-
}
82-
}
83-
if (formatedPhone == null) {
84-
//Don't format to E.164 if phone contains # or * as this is
85-
//for a Regex or USSD short number
86-
formatedPhone = phone;
87-
}else {
88-
//get all number with same number, by both formatedPhone and unformatedPhone
89-
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, formatedPhone, numbersDao);
81+
// Format the destination to an E.164 phone number.
82+
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
83+
String formatedPhone = null;
84+
if (!(phone.contains("*") || phone.contains("#"))) {
85+
try {
86+
formatedPhone = phoneNumberUtil.format(phoneNumberUtil.parse(phone, "US"), PhoneNumberFormat.E164);
87+
} catch (NumberParseException e) {
88+
//logger.error("Exception when try to format : " + e);
9089
}
90+
}
91+
if (formatedPhone == null) {
92+
//Don't format to E.164 if phone contains # or * as this is
93+
//for a Regex or USSD short number
94+
formatedPhone = phone;
95+
}else {
96+
//get all number with same number, by both formatedPhone and unformatedPhone
97+
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, formatedPhone, numbersDao);
98+
}
99+
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, phone, numbersDao);
100+
if (phone.startsWith("+")) {
101+
//remove the (+) and check if exists
102+
phone= phone.replaceFirst("\\+","");
91103
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, phone, numbersDao);
92-
if (phone.startsWith("+")) {
93-
//remove the (+) and check if exists
94-
phone= phone.replaceFirst("\\+","");
95-
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, phone, numbersDao);
96-
} else {
97-
//Add "+" add check if number exists
98-
phone = "+".concat(phone);
99-
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, phone, numbersDao);
100-
}
101-
if(numbers == null || numbers.isEmpty()){
102-
// https://github.com/Mobicents/RestComm/issues/84 using wildcard as default application
103-
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, "*", numbersDao);
104-
}
105-
if(numbers != null && !numbers.isEmpty()){
106-
// find number in same organization
107-
for(IncomingPhoneNumber n : numbers){
108-
if(n != null){
109-
if(logger.isDebugEnabled())
110-
logger.debug(String.format("getMostOptimalIncomingPhoneNumber: Got a similar number from DB: Analysis report: Number:Sid = %s : %s | Is Number pure sip? %s | Number's organizations: %s", n.getPhoneNumber(), n.getSid(), n.isPureSip(), n.getOrganizationSid()));
111-
if(n.getOrganizationSid().equals(destinationOrganizationSid)){
112-
/*
113-
* check if request is coming from same org
114-
* if not then only allow provider numbers
115-
*/
116-
if((sourceOrganizationSid != null && sourceOrganizationSid.equals(destinationOrganizationSid)) || (sourceOrganizationSid == null) || !n.isPureSip()){
117-
number = n;
118-
if(logger.isInfoEnabled())
119-
logger.info(String.format("Found most optimal phone number: Number:Sid = %s : %s", n.getPhoneNumber(), n.getSid()));
120-
}else{
121-
if(logger.isDebugEnabled())
122-
logger.debug("not allowed to call this number due to organizational restrictions");
123-
}
104+
} else {
105+
//Add "+" add check if number exists
106+
phone = "+".concat(phone);
107+
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, phone, numbersDao);
108+
}
109+
if(numbers == null || numbers.isEmpty()){
110+
// https://github.com/Mobicents/RestComm/issues/84 using wildcard as default application
111+
numbers = OrganizationUtil.searchAndAddNumberToTheList(numbers, "*", numbersDao);
112+
}
113+
if(numbers != null && !numbers.isEmpty()){
114+
// find number in same organization
115+
for(IncomingPhoneNumber n : numbers){
116+
if(n != null){
117+
if(logger.isDebugEnabled())
118+
logger.debug(String.format("getMostOptimalIncomingPhoneNumber: Got a similar number from DB: Analysis report: Number:Sid = %s : %s | Is Number pure sip? %s | Number's organizations: %s", n.getPhoneNumber(), n.getSid(), n.isPureSip(), n.getOrganizationSid()));
119+
if(n.getOrganizationSid().equals(destinationOrganizationSid)){
120+
/*
121+
* check if request is coming from same org
122+
* if not then only allow provider numbers
123+
*/
124+
if((sourceOrganizationSid != null && sourceOrganizationSid.equals(destinationOrganizationSid)) || (sourceOrganizationSid == null) || !n.isPureSip()){
125+
number = n;
126+
if(logger.isInfoEnabled())
127+
logger.info(String.format("Found most optimal phone number: Number:Sid = %s : %s", n.getPhoneNumber(), n.getSid()));
124128
}else{
125129
if(logger.isDebugEnabled())
126-
logger.debug(String.format("getMostOptimalIncomingPhoneNumber: Number:Sid = %s : %s does not belong to requested/destination organization: %s", n.getPhoneNumber(), n.getSid(), destinationOrganizationSid));
130+
logger.debug("not allowed to call this number due to organizational restrictions");
127131
}
128-
if(number != null)
129-
break;
132+
}else{
133+
if(logger.isDebugEnabled())
134+
logger.debug(String.format("getMostOptimalIncomingPhoneNumber: Number:Sid = %s : %s does not belong to requested/destination organization: %s", n.getPhoneNumber(), n.getSid(), destinationOrganizationSid));
130135
}
136+
if(number != null)
137+
break;
131138
}
132-
failCall = number == null;
133139
}
140+
failCall = number == null;
134141
}
135142
}catch(Exception e){
136143
logger.error("Error while trying to retrive getMostOptimalIncomingPhoneNumber: ", e);

restcomm/restcomm.dao/src/main/java/org/restcomm/connect/dao/mybatis/MybatisIncomingPhoneNumbersDao.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public final class MybatisIncomingPhoneNumbersDao implements IncomingPhoneNumber
4848
private static final String namespace = "org.mobicents.servlet.sip.restcomm.dao.IncomingPhoneNumbersDao.";
4949
private final SqlSessionFactory sessions;
5050
private final Logger logger = Logger.getLogger(MybatisIncomingPhoneNumbersDao.class.getName());
51-
private List<IncomingPhoneNumber> listPhones;
5251

5352
public MybatisIncomingPhoneNumbersDao(final SqlSessionFactory sessions) {
5453
super();
@@ -89,13 +88,13 @@ private List<IncomingPhoneNumber> getIncomingPhoneNumber(final String selector,
8988
}
9089
}
9190
//check if there is a Regex match only if parameter is a String aka phone Number
92-
listPhones = getIncomingPhoneNumbersRegex();
91+
List<IncomingPhoneNumber> listPhones = getIncomingPhoneNumbersRegex();
9392
if (listPhones != null && listPhones.size() > 0) {
9493
inboundPhoneNumber = ((String)parameter).replace("+1", "");
9594
if (inboundPhoneNumber.matches("[\\d,*,#,+]+")) {
96-
IncomingPhoneNumber incomingPhoneNumber = checkIncomingPhoneNumberRegexMatch(selector, inboundPhoneNumber);
95+
IncomingPhoneNumber incomingPhoneNumber = checkIncomingPhoneNumberRegexMatch(selector, inboundPhoneNumber, listPhones);
9796
if(incomingPhoneNumber != null)
98-
incomingPhoneNumbers.add(checkIncomingPhoneNumberRegexMatch(selector, inboundPhoneNumber));
97+
incomingPhoneNumbers.add(checkIncomingPhoneNumberRegexMatch(selector, inboundPhoneNumber, listPhones));
9998
}
10099
}
101100
}finally {
@@ -104,7 +103,7 @@ private List<IncomingPhoneNumber> getIncomingPhoneNumber(final String selector,
104103
return incomingPhoneNumbers;
105104
}
106105

107-
public IncomingPhoneNumber checkIncomingPhoneNumberRegexMatch ( String selector, String inboundPhoneNumber){
106+
public IncomingPhoneNumber checkIncomingPhoneNumberRegexMatch ( String selector, String inboundPhoneNumber, List<IncomingPhoneNumber> listPhones){
108107
final SqlSession session = sessions.openSession();
109108
String phoneRegexPattern = null;
110109
try {

restcomm/restcomm.dao/src/test/java/org/restcomm/connect/dao/mybatis/ConfDetailRecordsDaoTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ public void testAddRead() throws Exception {
149149
manager.getConferenceDetailRecordsDao().addConferenceDetailRecord(cdr);
150150
ConferenceDetailRecord cdrResult = manager.getConferenceDetailRecordsDao().getConferenceDetailRecord(sid);
151151
assertEquals(cdr.getFriendlyName(), cdrResult.getFriendlyName());
152-
ConferenceRecordCountFilter.Builder filterBuilder = ConferenceRecordCountFilter.builder();
153-
ConferenceRecordCountFilter filter = filterBuilder.byMasterMsId("masterMsId").build();
154-
Integer confCount = manager.getConferenceDetailRecordsDao().countByFilter(filter);
155-
assertEquals(Integer.valueOf(1), confCount);
156152
}
157153

158154
}

restcomm/restcomm.dns.api/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
<artifactId>restcomm-connect.commons</artifactId>
1919
<version>${project.version}</version>
2020
</dependency>
21+
22+
<dependency>
23+
<groupId>org.apache.tomcat</groupId>
24+
<artifactId>tomcat-coyote</artifactId>
25+
<scope>provided</scope>
26+
</dependency>
2127

2228
</dependencies>
2329
</project>

restcomm/restcomm.docs/sources-asciidoc/src/main/asciidoc/api/incoming-phone-numbers-api.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,7 @@ curl -X GET https://administrator%40company.com:77f8c12cc7b8f8423e5c38b03524916
526526
|^*222*...*...*500#$| the Regext (^*222*...*...*500#$) matches *222*888*999*500# or *222*444*321*500# the dots maches any character
527527
|999...| Matches 999222, 999123, 999555 the dots matches any character
528528

529+
WARNING: Watch out, Regex has been disabled for incoming SMPP/SMS messages because SMPP is not supporting Organizations.
530+
531+
529532
|=====================================================================================================================================================================================================================================================

0 commit comments

Comments
 (0)