aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/service')
-rw-r--r--src/main/java/at/gv/egiz/moazs/service/MzsService.java58
1 files changed, 54 insertions, 4 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/service/MzsService.java b/src/main/java/at/gv/egiz/moazs/service/MzsService.java
index 565e374..a2af4f1 100644
--- a/src/main/java/at/gv/egiz/moazs/service/MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/service/MzsService.java
@@ -46,6 +46,9 @@ import java.util.function.Consumer;
import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.zustellung.app2mzs.xsd.PartialSuccessType.partialSuccessTypeBuilder;
+import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Error.errorBuilder;
+import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
+import static at.gv.zustellung.msg.xsd.ErrorInfoType.errorInfoTypeBuilder;
import static java.lang.String.format;
import static java.lang.Thread.currentThread;
import static java.util.concurrent.CompletableFuture.supplyAsync;
@@ -149,15 +152,62 @@ public class MzsService implements App2MzsPortType {
log.info(SERVICE_TIME_OUT_REACHED_MSG, appDeliveryID);
var sinkParams = request.getConfig().getMsgResponseSinks();
- requestProcessed.thenCompose(response -> hub.applySinks(response, sinkParams));
+ requestProcessed
+ .exceptionally(e -> logErrorAndConvert(e, request))
+ .thenCompose(response -> hub.applySinks(response, sinkParams));
- return generatePartialSuccessResponse(appDeliveryID);
+ var deliverySystem = request.getConfig().getMSGClient().getURL();
+ return generatePartialSuccessResponse(appDeliveryID, deliverySystem);
}
- private DeliveryResponseType generatePartialSuccessResponse(String appDeliveryId) {
+ private RequestStatusResponse logErrorAndConvert(Throwable exception, DeliveryRequestType request) {
+
+ var appDeliveryID = request.getMetaData().getAppDeliveryID();
+ var errorMessage = format(MZS_SERVICE_ERROR_MSG, appDeliveryID);
+ log.error(errorMessage, exception);
+
+ var explanation = generateExplanation(exception);
+ var text = format("%s Reason: %s", errorMessage, explanation);
+
+ var errorInfo = errorInfoTypeBuilder()
+ .withCode("500")
+ .withText(text)
+ .build();
+
+ var deliverySystem = request.getConfig().getMSGClient().getURL();
+ var zsDeliveryID = "unknown";
+ var error = errorBuilder()
+ .withErrorInfo(errorInfo)
+ .withDeliverySystem(deliverySystem)
+ .withZSDeliveryID(zsDeliveryID)
+ .withAppDeliveryID(appDeliveryID)
+ .build();
+
+ var status = deliveryRequestStatusTypeBuilder()
+ .withError(error)
+ .build();
+
+ return new RequestStatusResponse(status);
+ }
+
+ private String generateExplanation(Throwable exception) {
+
+ StringBuilder s = new StringBuilder(exception.toString());
+ Throwable cause = exception.getCause();
+
+ while (cause != null && cause != cause.getCause()) {
+ s.append("; Reason: ").append(cause.toString());
+ cause = cause.getCause();
+ }
+
+ return s.toString();
+ }
+
+ private DeliveryResponseType generatePartialSuccessResponse(String appDeliveryID, String deliverySystem) {
var partial = partialSuccessTypeBuilder()
- .withAppDeliveryID(appDeliveryId)
+ .withAppDeliveryID(appDeliveryID)
+ .withDeliverySystem(deliverySystem)
.build();
return DeliveryResponseType.deliveryResponseTypeBuilder()