Skip to content

Commit 3839dc3

Browse files
authored
Merge pull request #1527 from marklogic/feature/enhance-reverse-proxy
Added custom mappings to reverse proxy server
2 parents d69236e + ccfbd09 commit 3839dc3

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

test-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ task runBlockingReverseProxyServer(type: JavaExec) {
3434
"sudo ./gradlew runBlockingReverseProxyServer -PrpsHttpsPort=443 ."
3535
classpath = sourceSets.main.runtimeClasspath
3636
main = "com.marklogic.client.test.ReverseProxyServer"
37-
args = [rpsMarkLogicServer, rpsProxyServer, rpsHttpPort, rpsHttpsPort]
37+
args = [rpsMarkLogicServer, rpsProxyServer, rpsHttpPort, rpsHttpsPort, rpsCustomMappings]
3838
}

test-app/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ rpsMarkLogicServer=localhost
1111
rpsProxyServer=localhost
1212
rpsHttpPort=8020
1313
rpsHttpsPort=0
14+
# Comma-delimited sequence of path1,port1,path2,port2,etc
15+
# Example: rpsCustomMappings=/my/server,8005,/my/other/server,9090
16+
rpsCustomMappings=

test-app/src/main/java/com/marklogic/client/test/ReverseProxyServer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import java.net.URI;
3131
import java.nio.charset.Charset;
3232
import java.security.KeyStore;
33-
import java.util.Date;
33+
import java.util.ArrayList;
34+
import java.util.Arrays;
3435
import java.util.LinkedHashMap;
36+
import java.util.List;
3537
import java.util.Map;
3638
import java.util.concurrent.TimeUnit;
3739

@@ -73,6 +75,7 @@ public static void main(final String[] args) throws Exception {
7375
String serverHost = "localhost";
7476
int serverPort = 8020;
7577
int secureServerPort = 0;
78+
List<String> customMappings = new ArrayList<>();
7679

7780
if (args.length > 0) {
7881
markLogicHost = args[0];
@@ -82,15 +85,18 @@ public static void main(final String[] args) throws Exception {
8285
serverPort = Integer.parseInt(args[2]);
8386
if (args.length > 3) {
8487
secureServerPort = Integer.parseInt(args[3]);
88+
if (args.length > 4) {
89+
customMappings = Arrays.asList(args[4].split(","));
90+
}
8591
}
8692
}
8793
}
8894
}
8995

90-
new ReverseProxyServer(markLogicHost, serverHost, serverPort, secureServerPort);
96+
new ReverseProxyServer(markLogicHost, serverHost, serverPort, secureServerPort, customMappings);
9197
}
9298

93-
public ReverseProxyServer(String markLogicHost, String serverHost, int serverPort, int secureServerPort) throws Exception {
99+
public ReverseProxyServer(String markLogicHost, String serverHost, int serverPort, int secureServerPort, List<String> customMappings) throws Exception {
94100
logger.info("MarkLogic host: {}", markLogicHost);
95101
logger.info("Proxy server host: {}", serverHost);
96102
logger.info("Proxy server HTTP port: {}", serverPort);
@@ -118,6 +124,10 @@ public ReverseProxyServer(String markLogicHost, String serverHost, int serverPor
118124
// these requests in a suitable fashion for manual testing.
119125
mapping.put("/token", new URI(String.format("http://%s:8022", serverHost)));
120126

127+
for (int i = 0; i < customMappings.size(); i += 2) {
128+
mapping.put(customMappings.get(i), new URI(String.format("http://%s:%s", serverHost, customMappings.get(i + 1))));
129+
}
130+
121131
mapping.entrySet().forEach(entry -> {
122132
logger.info("Mapped: " + entry.getKey() + " : " + entry.getValue());
123133
});

0 commit comments

Comments
 (0)