aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-03 10:29:21 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-03 10:29:21 +0200
commitf26318e8ff806f845125a58ef0803a96f9f00ce0 (patch)
treee7b997ecf944724ca59d7261b8a810ea4a06b0af /src/main/java/at/gv/egiz
parentf704c3ca51c7023128d3dc124f803884ca2cee6f (diff)
downloadmoa-zs-f26318e8ff806f845125a58ef0803a96f9f00ce0.tar.gz
moa-zs-f26318e8ff806f845125a58ef0803a96f9f00ce0.tar.bz2
moa-zs-f26318e8ff806f845125a58ef0803a96f9f00ce0.zip
Init: Add Timeout to Delivery Request Handler
Diffstat (limited to 'src/main/java/at/gv/egiz')
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsService.java66
1 files changed, 54 insertions, 12 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
index ccca4f5..c6a15a5 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
@@ -1,30 +1,72 @@
package at.gv.egiz.moazs;
import at.gv.e_government.reference.namespace.app2mzs.App2MzsPortType;
-import at.gv.e_government.reference.namespace.moazs10.app2mzs_.DeliveryRequestType;
-import at.gv.e_government.reference.namespace.moazs10.app2mzs_.DeliveryResponseType;
-import at.gv.e_government.reference.namespace.moazs10.app2mzs_.ObjectFactory;
-import at.gv.e_government.reference.namespace.moazs10.app2mzs_.SuccessType;
+import at.gv.e_government.reference.namespace.moazs10.app2mzs_.*;
+import org.springframework.beans.factory.annotation.Autowired;
import javax.jws.WebParam;
+import java.math.BigInteger;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static java.util.concurrent.CompletableFuture.supplyAsync;
public class App2MzsService implements App2MzsPortType {
+ //TODO move timeout to config
+ private final int timeoutForAnwser = 10;
+ private final String MZSTNS = "http://reference.e-government.gv.at/namespace/moazs10/app2mzs#";
+
+ @Autowired
+ private DeliveryRequestHandler deliveryRequestHandler;
+
+ @Autowired
+ private Mzs2AppClient appClient;
+
+ @Autowired
+ private ObjectFactory objectFactory;
+
@Override
public DeliveryResponseType app2Mzs(
@WebParam(partName = "DeliveryRequest",
name = "DeliveryRequest",
- targetNamespace = "http://reference.e-government.gv.at/namespace/moazs10/app2mzs#")
+ targetNamespace = MZSTNS)
DeliveryRequestType deliveryRequest) {
- System.out.println("app2mzs got called");
- ObjectFactory factory = new ObjectFactory();
- DeliveryResponseType response = factory.createDeliveryResponseType();
+ var future = supplyAsync(() -> deliveryRequestHandler.apply(deliveryRequest));
+
+ try {
+ return future.get(timeoutForAnwser, TimeUnit.SECONDS);
+
+ } catch (InterruptedException | ExecutionException e) {
+ return generateErrorResponse();
+
+ } catch (TimeoutException e) {
+ future.thenAccept(appClient::sendNotification);
+ return generatePartialSuccessResponse(deliveryRequest);
+ }
+ }
+
+ private DeliveryResponseType generatePartialSuccessResponse(DeliveryRequestType deliveryRequest) {
+
+ var partialSuccess = objectFactory.createPartialSuccessType();
+ partialSuccess.setAppDeliveryID(deliveryRequest.getMetaData().getAppDeliveryID());
+
+ var response = objectFactory.createDeliveryResponseType();
+ response.setPartialSuccess(partialSuccess);
+
+ return response;
+ }
+
+ private DeliveryResponseType generateErrorResponse() {
+
+ var error = objectFactory.createErrorType();
+ error.setText("Error Occurred");
+ error.setCode(BigInteger.valueOf(500));
- SuccessType success = factory.createSuccessType();
- success.setAppDeliveryID("12345");
- success.setMZSDeliveryID("12345");
- response.setSuccess(success);
+ var response = objectFactory.createDeliveryResponseType();
+ response.setError(error);
return response;
}