Skip to content

Commit 9363a6f

Browse files
author
maria-farooq
authored
Merge pull request #2870 from RestComm/restcomm1880
use proper scheme depending on runtime connector
2 parents 30a47a2 + ff27ad6 commit 9363a6f

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</init-param>
1717
<init-param>
1818
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
19-
<param-value>org.restcomm.connect.http.security.SecurityFilter;org.restcomm.connect.http.filters.BodyLengthFilter;org.restcomm.connect.http.filters.AcceptFilter</param-value>
19+
<param-value>org.restcomm.connect.http.security.SecurityFilter;org.restcomm.connect.http.filters.BodyLengthFilter;org.restcomm.connect.http.filters.AcceptFilter;org.restcomm.connect.http.filters.SchemeRewriteFilter</param-value>
2020
</init-param>
2121
<init-param>
2222
<param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* TeleStax, Open Source Cloud Communications
3+
* Copyright 2011-2014, Telestax Inc and individual contributors
4+
* by the @authors tag.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation; either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>
18+
*
19+
*/
20+
package org.restcomm.connect.http.filters;
21+
22+
import com.sun.jersey.spi.container.ContainerRequest;
23+
import com.sun.jersey.spi.container.ContainerRequestFilter;
24+
import com.sun.jersey.spi.container.ContainerResponseFilter;
25+
import com.sun.jersey.spi.container.ResourceFilter;
26+
import java.net.URI;
27+
import javax.ws.rs.ext.Provider;
28+
import org.apache.log4j.Logger;
29+
import org.restcomm.connect.commons.util.UriUtils;
30+
31+
/**
32+
* Ensures UriInfo builders build proper link scheme depending on container
33+
* connector (http/https)
34+
*
35+
* This will apply to any jaxrs endpoint trying to build uris later.
36+
*
37+
* UriUtils is used to discover connectors in runtime, and check the scheme.
38+
*
39+
*/
40+
@Provider
41+
public class SchemeRewriteFilter implements ResourceFilter, ContainerRequestFilter {
42+
43+
protected Logger logger = Logger.getLogger(SchemeRewriteFilter.class);
44+
45+
private static final String HTTPS_SCHEME = "https";
46+
47+
48+
@Override
49+
public ContainerRequest filter(ContainerRequest cr) {
50+
String connectorScheme = UriUtils.getHttpConnector().getScheme();
51+
if (connectorScheme.equalsIgnoreCase(HTTPS_SCHEME)) {
52+
URI newUri = cr.getRequestUriBuilder().scheme(HTTPS_SCHEME).build();
53+
URI baseUri = cr.getBaseUriBuilder().scheme(HTTPS_SCHEME).build();
54+
cr.setUris(baseUri, newUri);
55+
if (logger.isDebugEnabled()) {
56+
logger.debug("Detected https connector, rewriting URIs:" +
57+
newUri +
58+
"," +
59+
baseUri);
60+
}
61+
}
62+
return cr;
63+
}
64+
65+
@Override
66+
public ContainerRequestFilter getRequestFilter() {
67+
return this;
68+
}
69+
70+
@Override
71+
public ContainerResponseFilter getResponseFilter() {
72+
return null;
73+
}
74+
75+
}

0 commit comments

Comments
 (0)