Added dispatch method with ServiceRequestEnvelope
diff --git a/src/main/java/de/pta/mics/home/common/BackendConfig.java b/src/main/java/de/pta/mics/home/common/BackendConfig.java
index 0d4530a..a1e63aa 100644
--- a/src/main/java/de/pta/mics/home/common/BackendConfig.java
+++ b/src/main/java/de/pta/mics/home/common/BackendConfig.java
@@ -10,6 +10,7 @@
private String micsCentralURL;
private String micsDistributionCluster;
private String micsHealthStateExtraPath;
+ private boolean micsCentralIsHttps;
private static BackendConfig instance;
@@ -42,6 +43,10 @@
return micsHealthStateExtraPath;
}
+ public boolean isMicsCentralIsHttps() {
+ return micsCentralIsHttps;
+ }
+
public static String getConfigFileName() {
return configFileName;
}
diff --git a/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java b/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java
index f473238..88a8133 100644
--- a/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java
+++ b/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java
@@ -17,6 +17,7 @@
import de.pta.mics.home.common.Globals;
+import javax.ws.rs.core.Response;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -54,7 +55,7 @@
return createJson(response);
}
- public String performPostRequest(String restFunctionWithParams, String data) throws HttpStatusException {
+ public Response performPostRequestWithResponse(String restFunctionWithParams, String data) throws HttpStatusException {
String completeRequest = baseURL + "/" + restFunctionWithParams;
// create HTTP Client
@@ -78,7 +79,13 @@
LOGGER.warn(errtext, e);
throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE);
}
- return createJson(response);
+ String ent = createJson(response);
+
+ Response.ResponseBuilder rb = Response.status(response.getStatusLine().getStatusCode());
+ if (ent != null) {
+ rb.entity(ent);
+ }
+ return rb.build();
}
private CloseableHttpClient createHttpsClient() throws HttpStatusException {
diff --git a/src/main/java/de/pta/mics/home/rest/BackendRestService.java b/src/main/java/de/pta/mics/home/rest/BackendRestService.java
index 644d49a..5c2ec74 100644
--- a/src/main/java/de/pta/mics/home/rest/BackendRestService.java
+++ b/src/main/java/de/pta/mics/home/rest/BackendRestService.java
@@ -1,6 +1,7 @@
package de.pta.mics.home.rest;
import de.pta.mics.home.common.JsonGeneratorBase;
+import de.pta.mics.home.communication.RestServiceWrapper;
import de.pta.mics.home.controller.BackendController;
import de.pta.mics.home.controller.CentralProxy;
import de.pta.mics.home.controller.ResponseBuilderWrapper;
@@ -59,6 +60,26 @@
}
}
+ @POST
+ @Path("/dispatch/")
+ @Produces("application/json")
+ public Response dispatch( String envelope ) {
+ try {
+ BackendConfig bc = BackendConfig.getInstance();
+ RestServiceWrapper restServiceWrapper = new RestServiceWrapper(bc.getMicsCentralURL(), bc.isMicsCentralIsHttps());
+ return restServiceWrapper.performPostRequestWithResponse(createDispatchURL(), envelope);
+ }
+ catch( Exception e) {
+ return responseFromException(e);
+
+ }
+ }
+
+ private String createDispatchURL() {
+ BackendConfig bc = BackendConfig.getInstance();
+ return "dispatch/"+bc.getMicsDistributionCluster();
+ }
+
private Response responseFromException(Exception e) {
int errcode;
diff --git a/src/main/java/de/pta/mics/home/viewmodel/ServiceRequestEnvelope.java b/src/main/java/de/pta/mics/home/viewmodel/ServiceRequestEnvelope.java
new file mode 100644
index 0000000..6dfff44
--- /dev/null
+++ b/src/main/java/de/pta/mics/home/viewmodel/ServiceRequestEnvelope.java
@@ -0,0 +1,93 @@
+package de.pta.mics.home.viewmodel;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class ServiceRequestEnvelope {
+ public static class HttpHeader {
+ private String attribute;
+ private String value;
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ public void setAttribute(String attribute) {
+ this.attribute = attribute;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+ private String serviceName;
+ private boolean isHttps;
+ private String method;
+ private String uriFragment;
+ private String payload;
+ private HttpHeader[] headers;
+
+ @JsonProperty
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ @JsonProperty
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ @JsonProperty
+ public boolean isHttps() {
+ return isHttps;
+ }
+
+ @JsonProperty
+ public void setHttps(boolean https) {
+ isHttps = https;
+ }
+
+ @JsonProperty
+ public String getMethod() {
+ return method;
+ }
+
+ @JsonProperty
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+ @JsonProperty
+ public String getUriFragment() {
+ return uriFragment;
+ }
+
+ @JsonProperty
+ public void setUriFragment(String uriFragment) {
+ this.uriFragment = uriFragment;
+ }
+
+ @JsonProperty
+ public String getPayload() {
+ return payload;
+ }
+
+ @JsonProperty
+ public void setPayload(String payload) {
+ this.payload = payload;
+ }
+
+ @JsonProperty
+ public HttpHeader[] getHeaders() {
+ return headers;
+ }
+
+ @JsonProperty
+ public void setHeaders(HttpHeader[] headers) {
+ this.headers = headers;
+ }
+}
diff --git a/src/main/resources/backendConfigCustom.json b/src/main/resources/backendConfigCustom.json
index 5d4e7f1..498bd18 100644
--- a/src/main/resources/backendConfigCustom.json
+++ b/src/main/resources/backendConfigCustom.json
@@ -1,5 +1,6 @@
{
"micsDistributionCluster" : "elogbook.openK",
"micsCentralURL" : "http://localhost:9010/mics/central",
- "micsHealthStateExtraPath" : "healthcheck?pretty=true"
+ "micsHealthStateExtraPath" : "healthcheck?pretty=true",
+ "micsCentralIsHttps" : false
}
diff --git a/src/main/resources/backendConfigDevLocal.json b/src/main/resources/backendConfigDevLocal.json
index 5d4e7f1..498bd18 100644
--- a/src/main/resources/backendConfigDevLocal.json
+++ b/src/main/resources/backendConfigDevLocal.json
@@ -1,5 +1,6 @@
{
"micsDistributionCluster" : "elogbook.openK",
"micsCentralURL" : "http://localhost:9010/mics/central",
- "micsHealthStateExtraPath" : "healthcheck?pretty=true"
+ "micsHealthStateExtraPath" : "healthcheck?pretty=true",
+ "micsCentralIsHttps" : false
}
diff --git a/src/main/resources/backendConfigDevServer.json b/src/main/resources/backendConfigDevServer.json
index 8a5d25b..51774fc 100644
--- a/src/main/resources/backendConfigDevServer.json
+++ b/src/main/resources/backendConfigDevServer.json
@@ -1,5 +1,6 @@
{
"micsDistributionCluster" : "elogbook.openK",
"micsCentralURL" : "http://172.18.22.160:9010/mics/central",
- "micsHealthStateExtraPath" : "healthcheck?pretty=true"
+ "micsHealthStateExtraPath" : "healthcheck?pretty=true",
+ "micsCentralIsHttps" : false
}
diff --git a/src/main/resources/backendConfigDocker.json b/src/main/resources/backendConfigDocker.json
index f1f63e1..d762016 100644
--- a/src/main/resources/backendConfigDocker.json
+++ b/src/main/resources/backendConfigDocker.json
@@ -1,5 +1,6 @@
{
"micsDistributionCluster" : "elogbook.openK",
"micsCentralURL" : "http://172.25.0.54:9010/mics/central",
- "micsHealthStateExtraPath" : "healthcheck?pretty=true"
+ "micsHealthStateExtraPath" : "healthcheck?pretty=true",
+ "micsCentralIsHttps" : false
}
diff --git a/src/main/resources/backendConfigProduction.json b/src/main/resources/backendConfigProduction.json
index aeb4d00..c5096ed 100644
--- a/src/main/resources/backendConfigProduction.json
+++ b/src/main/resources/backendConfigProduction.json
@@ -1,5 +1,6 @@
{
"micsDistributionCluster" : "elogbook.openK",
"micsCentralURL" : "http://localhost:9010/mics/central",
- "micsHealthStateExtraPath" : "healthcheck?pretty=true"
+ "micsHealthStateExtraPath" : "healthcheck?pretty=true",
+ "micsCentralIsHttps" : false
}
\ No newline at end of file
diff --git a/src/test/java/de/pta/mics/home/viewmodel/ServiceRequestEnvelopeTest.java b/src/test/java/de/pta/mics/home/viewmodel/ServiceRequestEnvelopeTest.java
new file mode 100644
index 0000000..0de5b62
--- /dev/null
+++ b/src/test/java/de/pta/mics/home/viewmodel/ServiceRequestEnvelopeTest.java
@@ -0,0 +1,38 @@
+package de.pta.mics.home.viewmodel;
+
+
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class ServiceRequestEnvelopeTest {
+
+ @Test
+ public void testPojo() {
+ final String payload = "Testme Accurate";
+ ServiceRequestEnvelope env = new ServiceRequestEnvelope();
+ env.setHttps(true);
+ env.setMethod("POST");
+ env.setUriFragment("Fraggel");
+ env.setServiceName("Salve");
+
+ ServiceRequestEnvelope.HttpHeader[] headers = new ServiceRequestEnvelope.HttpHeader[2];
+ headers[0] = new ServiceRequestEnvelope.HttpHeader();
+ headers[0].setAttribute("1stAttr");
+ headers[0].setValue("1stValue");
+ headers[1] = new ServiceRequestEnvelope.HttpHeader();
+ headers[1].setAttribute("2ndAttr");
+ headers[1].setValue("2ndValue");
+ env.setHeaders(headers);
+
+ assertEquals(true, env.isHttps());
+ assertEquals("POST", env.getMethod());
+ env.setPayload(payload);
+ assertEquals(payload, env.getPayload());
+ assertEquals("Fraggel", env.getUriFragment());
+ assertEquals("Salve", env.getServiceName());
+ assertEquals(2, env.getHeaders().length);
+ assertEquals("2ndAttr", env.getHeaders()[1].getAttribute());
+ assertEquals("1stValue", env.getHeaders()[0].getValue());
+ }
+}
diff --git a/src/test/resources/serviceRequestEnvelope.json b/src/test/resources/serviceRequestEnvelope.json
new file mode 100644
index 0000000..9722f58
--- /dev/null
+++ b/src/test/resources/serviceRequestEnvelope.json
@@ -0,0 +1,17 @@
+{
+ "serviceName": "auth-n-auth.mics",
+ "isHttps": false,
+ "method": "GET",
+ "uriFragment": "versionInfo",
+ "payload": "eyAiYmFja2VuZFZlcnNpb24iOiAiMC4xLjMtU05BUFNIT1QifQ==",
+ "headers": [
+ {
+ "attribute": "Content-Type",
+ "value": "application/json"
+ },
+ {
+ "attribute": "accept",
+ "value": "application/json"
+ }
+ ]
+}
\ No newline at end of file