Skip to content

Commit 9c5eddc

Browse files
author
Orestis Tsakiridis
committed
Merge branch 'cors_support_and_video_config'
Merges PRs #2136, #2253, #2268
2 parents 8ae5985 + 39392ed commit 9c5eddc

14 files changed

Lines changed: 1233 additions & 108 deletions

File tree

restcomm/configuration/config-scripts/as7-config-scripts/restcomm/advanced.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ LBHOST='' #Obligatory to set if Load Balancer is used for PSTN (DID provider con
9393
#RVD workspace path. (If not set default will be used).
9494
#Default: leave empty.
9595
RVD_LOCATION=''
96+
RVD_URL='' # override if RVD is not under the same domain with restcomm. Use a base url like http://myrvd.restcomm.com . No path included.
97+
RVD_VIDEO_SUPPORT='false' # Toggle RVD Video RCML generation and UI
98+
RVD_MAX_MEDIA_FILE_SIZE=4194304 # Limit media file size when uploading. For video should probably be greater
99+
96100

97101
#RMS pool size (Un-comment the resource that you want to set the pool size)
98102
#RMS pool size (Should calculated from number of concurrent calls expected).

restcomm/configuration/config-scripts/as7-config-scripts/restcomm/autoconfig.d/config-restcomm.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,38 @@ confRVD(){
560560
fi
561561
}
562562

563+
## Adds/removes <rcmlserver>/<base-url> element based on $RVD_URL
564+
## This version of confRcmlserver() will used xmlstarlet and will probably sed commands that rely on empty elements like <x></x> instead of <x/>
565+
#confRcmlserver(){
566+
# echo "Configuring <rcmlserver/>..."
567+
# local RESTCOMM_XML=$RESTCOMM_DEPLOY/WEB-INF/conf/restcomm.xml
568+
# if [ -z "$RVD_URL" ]; then
569+
# # remove <rcmlserver>/<base-url> element altogether
570+
# xmlstarlet ed -P -d "/restcomm/rcmlserver/base-url" "$RESTCOMM_XML" > "${RESTCOMM_XML}.bak"
571+
# mv ${RESTCOMM_XML}.bak "$RESTCOMM_XML"
572+
# else
573+
# # remove existing <base-url/> element
574+
# xmlstarlet ed -P -d /restcomm/rcmlserver/base-url "$RESTCOMM_XML" > "${RESTCOMM_XML}.bak"
575+
# mv ${RESTCOMM_XML}.bak "$RESTCOMM_XML"
576+
# # add it anew
577+
# xmlstarlet ed -P -s /restcomm/rcmlserver -t elem -n base-url -v "$RVD_URL" "${RESTCOMM_XML}" > "${RESTCOMM_XML}.bak"
578+
# mv "${RESTCOMM_XML}.bak" "$RESTCOMM_XML"
579+
# fi
580+
# echo "<rcmlserver/> configured"
581+
#}
582+
583+
# Updates <rcmlserver>/<base-url> according to $RVD_URL
584+
# This version of confRcmlserver() used sed for backwards compatibility with existing sed commands in this
585+
confRcmlserver() {
586+
echo "Configuring <rcmlserver/>..."
587+
local RESTCOMM_XML=$RESTCOMM_DEPLOY/WEB-INF/conf/restcomm.xml
588+
sed "/<rcmlserver>/,/<\/rcmlserver>/ s|<base-url>.*</base-url>|<base-url>${RVD_URL}</base-url>|" "$RESTCOMM_XML" > "${RESTCOMM_XML}.bak"
589+
mv ${RESTCOMM_XML}.bak "$RESTCOMM_XML"
590+
echo "base-url set to '$RVD_URL'"
591+
echo "<rcmlserver/> configured"
592+
}
593+
594+
563595
#Auto Configure RMS Networking, if MANUAL_SETUP=false.
564596
configRMSNetworking() {
565597
if [[ "$MANUAL_SETUP" == "false" || "$MANUAL_SETUP" == "FALSE" ]]; then
@@ -606,6 +638,7 @@ updateRecordingsPath
606638
configHypertextPort
607639
configOutboundProxy
608640
otherRestCommConf
641+
confRcmlserver
609642
confRVD
610643
configRMSNetworking
611644
echo 'Configured RestComm!'
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
##
3+
## Configures rvd.xml based on global configuration options in restcomm.conf and advanced.conf.
4+
##
5+
## usage:
6+
##
7+
## ./config-rvd-logging.sh - adds handler and logger (INFO) elements if missing
8+
## ./config-rvd-logging.sh DEBUG - creates or updates loggers by setting level to DEBUG
9+
## ./config-rvd-logging.sh DEBUG FILE - creates or updates loggers (DEBUG) but also configures them to use the 'FILE' periodic handler (main restcomm log)
10+
##
11+
## requirements:
12+
##
13+
## RESTCOMM_HOME env variable to be set
14+
## rvd.xml should be in place (under $RESTCOMM_HOME/standalone/deployments/restcomm-rvd.war)
15+
##
16+
## Author: otsakir@gmail.com - Orestis Tsakiridis
17+
18+
# Variables
19+
RVD_ROOT=$RESTCOMM_HOME/standalone/deployments/restcomm-rvd.war
20+
RVD_XML_FILE=$RVD_ROOT/WEB-INF/rvd.xml
21+
22+
updateVideoSupport() {
23+
matchesCount=`xmlstarlet sel -t -v "count(/rvd/videoSupport)" "$RVD_XML_FILE"`
24+
if [ $matchesCount -ge 1 ]; then
25+
xmlstarlet ed -P -u "/rvd/videoSupport" -v "$1" "$RVD_XML_FILE" > ${RVD_XML_FILE}_tmp
26+
mv ${RVD_XML_FILE}_tmp ${RVD_XML_FILE}
27+
else
28+
xmlstarlet ed -P -s "/rvd" -t elem -n "videoSupport" -v "$1" "$RVD_XML_FILE" > ${RVD_XML_FILE}_tmp
29+
mv ${RVD_XML_FILE}_tmp ${RVD_XML_FILE}
30+
fi
31+
}
32+
33+
updateMaxMediaFileSize() {
34+
matchesCount=`xmlstarlet sel -t -v "count(/rvd/maxMediaFileSize)" "$RVD_XML_FILE"`
35+
if [ $matchesCount -ge 1 ]; then
36+
xmlstarlet ed -P -u "/rvd/maxMediaFileSize" -v "$1" "$RVD_XML_FILE" > ${RVD_XML_FILE}_tmp
37+
mv ${RVD_XML_FILE}_tmp ${RVD_XML_FILE}
38+
else
39+
xmlstarlet ed -P -s "/rvd" -t elem -n "maxMediaFileSize" -v "$1" "$RVD_XML_FILE" > ${RVD_XML_FILE}_tmp
40+
mv ${RVD_XML_FILE}_tmp ${RVD_XML_FILE}
41+
fi
42+
}
43+
44+
# MAIN
45+
46+
if [ -z "$RESTCOMM_HOME" ]
47+
then
48+
echo "RESTCOMM_HOME env variable not set. Aborting."
49+
exit 1
50+
fi
51+
if [ ! -f "$RVD_XML_FILE" ]
52+
then
53+
echo "rvd.xml not found. Aborting."
54+
return
55+
fi
56+
57+
echo "Configuring RVD"
58+
59+
if [ "$RVD_VIDEO_SUPPORT" = true || "$RVD_VIDEO_SUPPORT" = TRUE || "$RVD_VIDEO_SUPPORT" = True ] ; then
60+
updateVideoSupport true
61+
else
62+
updateVideoSupport false
63+
fi
64+
updateMaxMediaFileSize "$RVD_MAX_MEDIA_FILE_SIZE"
65+
echo "Updated rvd.xml"
66+

restcomm/restcomm.application/src/main/webapp/WEB-INF/conf/restcomm.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,19 @@
408408
</http-client>
409409

410410
<!-- Control notifications sent to rcmlserver (RVD)
411-
base-url: relative path or absolute url where rcmlserver it located.
411+
base-url: Base url where rcml server is located of the form scheme://host:port like 'http://rvdserver:8080'. Leave it empty when RVD is bundled together with restcomm.
412+
api-path: relative path where rcml server api listens under like '/restcomm-rvd/services
412413
notifications: should notifications be sent or not ? defaults to 'false'
413414
timeout: milis to wait response from rcmlserver before timing out when sending notifications. Defaults to 5000
414415
timeout-per-notification: if several notifications are sent in one step, timeout increase for each. Defaults to 500.
415416
-->
416-
<rcmlserver-api>
417-
<base-url>/restcomm-rvd/services</base-url>
417+
<rcmlserver>
418+
<base-url></base-url>
419+
<api-path>/restcomm-rvd/services</api-path>
418420
<notifications>true</notifications>
419421
<timeout>5000</timeout>
420422
<timeout-per-notification>500</timeout-per-notification>
421-
</rcmlserver-api>
423+
</rcmlserver>
422424

423425
<!-- The SMS aggregator is responsible for the handling of SMS messages
424426
inside of RestComm. Refer to the org.mobicents.servlet.sip.restcomm.SmsAggregator

restcomm/restcomm.application/src/main/webapp/WEB-INF/web.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
<servlet>
99
<servlet-name>Jersey</servlet-name>
1010
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
11+
<!-- Enable CORS request filter -->
12+
<init-param>
13+
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
14+
<param-value>org.restcomm.connect.http.cors.CorsFilter</param-value>
15+
</init-param>
1116
</servlet>
1217

1318
<context-param>
1419
<param-name>resteasy.scan</param-name>
1520
<param-value>false</param-value>
1621
</context-param>
17-
22+
1823
<context-param>
1924
<param-name>resteasy.scan.providers</param-name>
2025
<param-value>false</param-value>
@@ -24,12 +29,12 @@
2429
<param-name>resteasy.scan.resources</param-name>
2530
<param-value>false</param-value>
2631
</context-param>
27-
32+
2833
<servlet-mapping>
2934
<servlet-name>Jersey</servlet-name>
3035
<url-pattern>/2012-04-24/*</url-pattern>
3136
</servlet-mapping>
32-
37+
3338
<welcome-file-list>
3439
<welcome-file>index.html</welcome-file>
3540
</welcome-file-list>

restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/configuration/sets/RcmlserverConfigurationSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @author otsakir@gmail.com - Orestis Tsakiridis
2525
*/
2626
public interface RcmlserverConfigurationSet {
27+
String getApiPath();
2728
String getBaseUrl();
2829
Boolean getNotify();
2930
Integer getTimeout(); // how much to wait for response to a notification request before giving up

restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/configuration/sets/impl/RcmlserverConfigurationSetImpl.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
* @author otsakir@gmail.com - Orestis Tsakiridis
2929
*/
3030
public class RcmlserverConfigurationSetImpl extends ConfigurationSet implements RcmlserverConfigurationSet {
31-
private static final String BASE_URL_KEY = "rcmlserver-api.base-url";
32-
private static final String NOTIFY_KEY = "rcmlserver-api.notifications";
33-
private static final String TIMEOUT_KEY = "rcmlserver-api.timeout";
34-
private static final String TIMEOUT_PER_NOTIFICATION_KEY = "rcmlserver-api.timeout-per-notification";
31+
private static final String BASE_URL_KEY = "rcmlserver.base-url";
32+
private static final String API_PATH_KEY = "rcmlserver.api-path";
33+
private static final String NOTIFY_KEY = "rcmlserver.notifications";
34+
private static final String TIMEOUT_KEY = "rcmlserver.timeout";
35+
private static final String TIMEOUT_PER_NOTIFICATION_KEY = "rcmlserver.timeout-per-notification";
3536
private String baseUrl = null;
37+
private String apiPath = null;
3638
private Boolean notify = false;
3739
private Integer timeout = 5000;
3840
private Integer timeoutPerNotification = 500;
@@ -48,6 +50,14 @@ public RcmlserverConfigurationSetImpl(ConfigurationSource source) {
4850
this.baseUrl = value;
4951
}
5052

53+
value = source.getProperty(API_PATH_KEY);
54+
if ( !StringUtils.isEmpty(value) ) {
55+
value = value.trim();
56+
if (value.endsWith("/")) // remove trailing '/' if present
57+
value = value.substring(0,value.length()-2);
58+
this.apiPath = value;
59+
}
60+
5161
value = source.getProperty(NOTIFY_KEY);
5262
try {
5363
this.notify = Boolean.parseBoolean(value);
@@ -77,6 +87,11 @@ public String getBaseUrl() {
7787
return baseUrl;
7888
}
7989

90+
@Override
91+
public String getApiPath() {
92+
return apiPath;
93+
}
94+
8095
@Override
8196
public Boolean getNotify() {
8297
return notify;

restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ void init() {
108108
xstream.registerConverter(new AccountListConverter(runtimeConfiguration));
109109
xstream.registerConverter(new RestCommResponseConverter(runtimeConfiguration));
110110
// Make sure there is an authenticated account present when this endpoint is used
111-
checkAuthenticatedAccount();
112111
}
113112

114113
private Account createFrom(final Sid accountSid, final MultivaluedMap<String, String> data) throws PasswordTooWeak {
@@ -142,6 +141,7 @@ private Account createFrom(final Sid accountSid, final MultivaluedMap<String, St
142141
}
143142

144143
protected Response getAccount(final String accountSid, final MediaType responseType) {
144+
checkAuthenticatedAccount();
145145
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
146146
Account account = null;
147147
checkPermission("RestComm:Read:Accounts");
@@ -302,6 +302,7 @@ private void removeIncomingPhoneNumbers(Sid accountSid, IncomingPhoneNumbersDao
302302

303303

304304
protected Response getAccounts(final MediaType responseType) {
305+
checkAuthenticatedAccount();
305306
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
306307
checkPermission("RestComm:Read:Accounts");
307308
final Account account = userIdentityContext.getEffectiveAccount();
@@ -323,6 +324,7 @@ protected Response getAccounts(final MediaType responseType) {
323324
}
324325

325326
protected Response putAccount(final MultivaluedMap<String, String> data, final MediaType responseType) {
327+
checkAuthenticatedAccount();
326328
//First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO operations
327329
checkPermission("RestComm:Create:Accounts");
328330
// check account level depth. If we're already at third level no sub-accounts are allowed to be created
@@ -476,6 +478,7 @@ private Account prepareAccountForUpdate(final Account account, final Multivalued
476478

477479
protected Response updateAccount(final String identifier, final MultivaluedMap<String, String> data,
478480
final MediaType responseType) {
481+
checkAuthenticatedAccount();
479482
// First check if the account has the required permissions in general, this way we can fail fast and avoid expensive DAO
480483
// operations
481484
checkPermission("RestComm:Modify:Accounts");

restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsJsonEndpoint.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import javax.ws.rs.Consumes;
2525
import javax.ws.rs.GET;
26+
import javax.ws.rs.OPTIONS;
2627
import javax.ws.rs.POST;
2728
import javax.ws.rs.PUT;
2829
import javax.ws.rs.Path;
@@ -49,6 +50,13 @@ public Response getAccountAsJson(@PathParam("accountSid") final String accountSi
4950
return getAccount(accountSid, APPLICATION_JSON_TYPE);
5051
}
5152

53+
@Path("/{accountSid}")
54+
@OPTIONS
55+
public Response optionsAccount(@PathParam("accountSid") final String accountSid) {
56+
// no authentication here since this is a pre-flight request
57+
return Response.ok().build();
58+
}
59+
5260
@GET
5361
public Response getAccounts() {
5462
return getAccounts(APPLICATION_JSON_TYPE);

restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/client/rcmlserver/RcmlserverApi.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.google.gson.Gson;
2424
import com.google.gson.JsonObject;
25+
import org.apache.commons.lang.StringUtils;
2526
import org.apache.http.HttpResponse;
2627
import org.apache.http.client.HttpClient;
2728
import org.apache.http.client.methods.HttpPost;
@@ -59,8 +60,16 @@ enum NotificationType {
5960

6061
public RcmlserverApi(MainConfigurationSet mainConfig, RcmlserverConfigurationSet rcmlserverConfig) {
6162
try {
62-
// resolve() should be run lazily to work. Make sure this constructor is invoked after the JBoss connectors have been set up.
63-
apiUrl = UriUtils.resolve(new URI(rcmlserverConfig.getBaseUrl()));
63+
// if there is no baseUrl configured we use the resolver to guess the location of the rcml server and the path
64+
if ( StringUtils.isEmpty(rcmlserverConfig.getBaseUrl()) ) {
65+
// resolve() should be run lazily to work. Make sure this constructor is invoked after the JBoss connectors have been set up.
66+
apiUrl = UriUtils.resolve(new URI(rcmlserverConfig.getApiPath()));
67+
}
68+
// if baseUrl has been configured, concat baseUrl and path to find the location of rcml server. No resolving here.
69+
else {
70+
String path = rcmlserverConfig.getApiPath();
71+
apiUrl = new URI(rcmlserverConfig.getBaseUrl() + (path != null ? path : "") );
72+
}
6473
} catch (URISyntaxException e) {
6574
throw new RuntimeException(e);
6675
}

0 commit comments

Comments
 (0)