aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-10 11:44:24 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-10 11:44:24 +0200
commit5538f843ea7ffb214e6f63b46c3a37e3dde75f36 (patch)
tree681bb0e48263bf2039804ea584dfd707e30176e3
parent45852c07dae33ed430a9b92be9b06ec675f68322 (diff)
downloadmoa-zs-5538f843ea7ffb214e6f63b46c3a37e3dde75f36.tar.gz
moa-zs-5538f843ea7ffb214e6f63b46c3a37e3dde75f36.tar.bz2
moa-zs-5538f843ea7ffb214e6f63b46c3a37e3dde75f36.zip
Refactor Exception Handling in App2Mzs
- Define dedicated runtime exception - Put AppDeliveryId in exception message
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsService.java12
-rw-r--r--src/main/java/at/gv/egiz/moazs/MoaZSException.java16
2 files changed, 23 insertions, 5 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
index 23cc0aa..09bcc63 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
@@ -15,6 +15,7 @@ import javax.jws.WebParam;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.zustellung.msg.xsd.DeliveryAnswerType.deliveryAnswerTypeBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
import static java.text.MessageFormat.format;
@@ -48,6 +49,8 @@ public class App2MzsService implements App2MzsPortType {
name = "DeliveryRequest")
DeliveryRequestType deliveryRequest) {
+ var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID();
+
var future = supplyAsync(() -> augmenter.augment(deliveryRequest))
.thenApply(this::process);
@@ -56,14 +59,13 @@ public class App2MzsService implements App2MzsPortType {
} catch (TimeoutException e) {
future.thenAccept(appClient::sendNotification);
logger.info("Answer Timed Out", e);
-
- var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID();
return generatePartialSuccessResponse(appDeliveryID);
} catch (Exception e ) {
logger.error("Could not deliver request.", e);
- var message = format("An error occurred while processing DeliveryRequest");
- throw new RuntimeException(message, e);
+ var message = format("An error occurred while processing DeliveryRequest with AppDeliveryID={0}. ", appDeliveryID);
+ throw new MoaZSException(message, e);
+
}
}
@@ -77,7 +79,7 @@ public class App2MzsService implements App2MzsPortType {
pipeline.processRequest(appDeliveryID);
return repository.getDeliveryRequestStatus(appDeliveryID)
- .orElseThrow(() -> new RuntimeException("Could not get a response for appDeliveryId = " + appDeliveryID));
+ .orElseThrow(() -> moaZSException("Could not get a response for AppDeliveryID={0}", appDeliveryID));
}
diff --git a/src/main/java/at/gv/egiz/moazs/MoaZSException.java b/src/main/java/at/gv/egiz/moazs/MoaZSException.java
new file mode 100644
index 0000000..ad211bd
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/MoaZSException.java
@@ -0,0 +1,16 @@
+package at.gv.egiz.moazs;
+
+public class MoaZSException extends RuntimeException {
+ public MoaZSException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
+
+ public MoaZSException(String s) {
+ super(s);
+ }
+
+ public static MoaZSException moaZSException(String formatString, Object... objects) {
+ return new MoaZSException(String.format(formatString, objects));
+ }
+
+}