Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 3021d4f

Browse files
authored
SORMAS-Foundation#3605 added proxy support for hotfix (SORMAS-Foundation#3713)
1 parent 1e58338 commit 3021d4f

5 files changed

Lines changed: 74 additions & 9 deletions

File tree

SERVER_CUSTOMIZATION.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,14 @@ The following features are currently configurable:
8888
* **Case Follow-Up** `CASE_FOLLOWUP`: Enables the contact follow-up module for cases as well to allow a more detailed daily documentation of symptoms.
8989
* **Line Listing** `LINE_LISTING`: Whether or not using line listing for case entry is enabled in the specified jurisdiction for the specified disease. Configurable from the UI, no database interaction needed.
9090
* **Documents** `DOCUMENTS`: Enables document storage.
91+
92+
## Proxy Settings
93+
Some SORMAS integrations support proxy settings:
94+
* **Patient diary interface**
95+
* **Geocoding**
96+
* **SORMAS 2 SORMAS**
97+
98+
The proxy can be configured through the following system properties which can be passed as JVM arguments to the server:
99+
* `org.jboss.resteasy.jaxrs.client.proxy.host`
100+
* `org.jboss.resteasy.jaxrs.client.proxy.port`
101+
* `org.jboss.resteasy.jaxrs.client.proxy.scheme`

sormas-backend/src/main/java/de/symeda/sormas/backend/externaljournal/ExternalJournalService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import javax.ejb.LocalBean;
1414
import javax.ejb.Stateless;
1515
import javax.ws.rs.client.Client;
16-
import javax.ws.rs.client.ClientBuilder;
1716
import javax.ws.rs.client.Entity;
1817
import javax.ws.rs.client.Invocation;
1918
import javax.ws.rs.client.WebTarget;
2019
import javax.ws.rs.core.MediaType;
2120
import javax.ws.rs.core.Response;
2221

22+
import de.symeda.sormas.backend.util.ClientHelper;
2323
import org.apache.commons.lang3.ObjectUtils;
2424
import org.apache.commons.lang3.StringUtils;
2525
import org.apache.commons.validator.routines.EmailValidator;
@@ -99,7 +99,7 @@ private String getSymptomJournalAuthTokenInternal() {
9999
throw new IllegalArgumentException("Property interface.symptomjournal.secret is not defined");
100100
}
101101
try {
102-
Client client = ClientBuilder.newClient();
102+
Client client = ClientHelper.newBuilderWithProxy().build();
103103
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(clientId, secret);
104104
client.register(feature);
105105
WebTarget webTarget = client.target(authenticationUrl);
@@ -146,7 +146,7 @@ private String getPatientDiaryAuthTokenInternal() {
146146
}
147147

148148
try {
149-
Client client = ClientBuilder.newClient();
149+
Client client = ClientHelper.newBuilderWithProxy().build();
150150
WebTarget webTarget = client.target(authenticationUrl);
151151
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
152152
Response response = invocationBuilder.post(Entity.json(ImmutableMap.of("email", email, "password", pass)));
@@ -315,7 +315,7 @@ public PatientDiaryRegisterResult registerPatientDiaryPerson(PersonDto person) {
315315

316316
private Invocation.Builder getExternalDataPersonInvocationBuilder(String personUuid) {
317317
String externalDataUrl = configFacade.getPatientDiaryConfig().getProbandsUrl() + "/external-data/" + personUuid;
318-
Client client = ClientBuilder.newClient();
318+
Client client = ClientHelper.newBuilderWithProxy().build();
319319
return client.target(externalDataUrl).request(MediaType.APPLICATION_JSON).header("x-access-token", getPatientDiaryAuthToken());
320320
}
321321

@@ -389,7 +389,7 @@ public Optional<PatientDiaryPersonQueryResponse> queryPatientDiary(String key, S
389389
String queryParam = "\"" + key + "\" = \"" + value + "\"";
390390
String encodedParams = URLEncoder.encode(queryParam, StandardCharsets.UTF_8.toString());
391391
String fullUrl = probandsUrl + "?q=" + encodedParams;
392-
Client client = ClientBuilder.newClient();
392+
Client client = ClientHelper.newBuilderWithProxy().build();
393393
Response response = client.target(fullUrl).request(MediaType.APPLICATION_JSON).header("x-access-token", getPatientDiaryAuthToken()).get();
394394
if (response.getStatus() == NOT_FOUND_STATUS) {
395395
return Optional.empty();

sormas-backend/src/main/java/de/symeda/sormas/backend/geocoding/GeocodingService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import javax.ejb.LocalBean;
3030
import javax.ejb.Stateless;
3131
import javax.ws.rs.client.Client;
32-
import javax.ws.rs.client.ClientBuilder;
3332
import javax.ws.rs.client.WebTarget;
3433
import javax.ws.rs.core.MediaType;
3534
import javax.ws.rs.core.Response;
3635
import javax.ws.rs.core.Response.Status.Family;
3736

37+
import de.symeda.sormas.backend.util.ClientHelper;
3838
import org.apache.commons.text.StringSubstitutor;
3939
import org.apache.http.client.utils.URIBuilder;
4040
import org.slf4j.Logger;
@@ -90,7 +90,7 @@ private GeoLatLon getLatLon(LocationQuery query, String urlTemplate) {
9090
throw new IllegalArgumentException(e);
9191
}
9292

93-
Client client = ClientBuilder.newBuilder().connectTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).build();
93+
Client client = ClientHelper.newBuilderWithProxy().connectTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).build();
9494
WebTarget target = client.target(targetUrl);
9595
Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();
9696
String responseText = readResponseAsText(response);

sormas-backend/src/main/java/de/symeda/sormas/backend/sormastosormas/SormasToSormasRestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import javax.enterprise.inject.Alternative;
2121
import javax.ws.rs.ProcessingException;
22-
import javax.ws.rs.client.ClientBuilder;
2322
import javax.ws.rs.client.Entity;
2423
import javax.ws.rs.client.Invocation;
2524
import javax.ws.rs.core.MediaType;
@@ -29,6 +28,7 @@
2928
import com.fasterxml.jackson.annotation.PropertyAccessor;
3029
import com.fasterxml.jackson.core.JsonProcessingException;
3130
import com.fasterxml.jackson.databind.ObjectMapper;
31+
import de.symeda.sormas.backend.util.ClientHelper;
3232

3333
@Alternative
3434
public class SormasToSormasRestClient {
@@ -54,7 +54,7 @@ public Response put(String host, String endpoint, String authToken, Object entit
5454
}
5555

5656
private Invocation.Builder buildRestClient(String host, String endpoint, String authToken) {
57-
return ClientBuilder.newBuilder()
57+
return ClientHelper.newBuilderWithProxy()
5858
.build()
5959
.target(String.format(SORMAS_REST_URL_TEMPLATE, host, endpoint))
6060
.request()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
3+
* Copyright © 2016-2020 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package de.symeda.sormas.backend.util;
20+
21+
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
22+
23+
import javax.ws.rs.client.ClientBuilder;
24+
import java.util.Arrays;
25+
import java.util.List;
26+
27+
/**
28+
* Helper class for creating REST clients injects supported properties from system properties.
29+
*
30+
* @author Alex Vidrean
31+
* @since 04-Nov-20
32+
*/
33+
public class ClientHelper {
34+
35+
public static final List<String> SUPPORTED_PROXY_PROPERTIES = Arrays.asList(
36+
ResteasyClientBuilder.PROPERTY_PROXY_HOST,
37+
ResteasyClientBuilder.PROPERTY_PROXY_PORT,
38+
ResteasyClientBuilder.PROPERTY_PROXY_SCHEME);
39+
40+
public static ClientBuilder newBuilderWithProxy() {
41+
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
42+
43+
if (clientBuilder instanceof ResteasyClientBuilder) {
44+
System.getProperties()
45+
.entrySet()
46+
.stream()
47+
.filter(property -> SUPPORTED_PROXY_PROPERTIES.contains(property.getKey().toString()))
48+
.forEach(property -> clientBuilder.property(property.getKey().toString(), property.getValue()));
49+
50+
}
51+
return clientBuilder;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)