aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-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;
}