aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/scheme
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-17 13:17:21 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-17 13:27:40 +0200
commitf2e1263702901581512131ea587fad7a2ba45baa (patch)
treeb92a38f758fecb039de184963116017921d2e314 /src/main/java/at/gv/egiz/moazs/scheme
parent896195cc9b287a3f41008cc85997b9c2209120b8 (diff)
downloadmoa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.gz
moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.bz2
moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.zip
Put MoaZSException on Diet & Handle Edge Cases
Reason: MoaZSException (and: its builder) were used to collect intermediary results while stepping through the delivery request backend. These results were needed to generate meaningful responses towards the sender application in case of error. However, the builder sprawled over too many interfaces (e.g. DeliveryRequestBackend and TNVZHelper) and it became difficult to understand from where intermediary results originated. Solution: Put MoaZSException on diet: - Remove all DeliveryAnswer fields from MoaZSException and refactor code base to ensure that the removed fields get sourced by other means. - Remove Builder since amount of parameters is manageable. Refactor DeliveryRequestBackend: - Instead of passing down the builder and using MoaZSException as the only source for intermediary results, we collect available results at the outermost stack frame (DeliveryRequestBackend.accept) and only retrieve results via exception if those results appear somewhere down the stack frame (E.g. PredviceNoteSent). We collect available results with the "fallbackAnswerBuilder" and switch to the msg client response, once received. Refactor MsgResponseBackend: - Handle cases (response missing, binary response missing) properly. - Integrate changes from MsgResponse.generateError() Refactor TVNZHelper: - Remove MoaZSExceptionBuilder from all interfaces. Refactor MsgResponse.generateError: - Change interface such that it's more intuitive. - Implement NotificationResponse.generateError. - Implement RequestStatusResponse.generateError. Others: - Replace all invocations against MoaZSException.Builder.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/scheme')
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java10
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java1
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java26
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java56
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java6
5 files changed, 67 insertions, 32 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java b/src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java
index 8bd88d9..c4fd0b7 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java
@@ -1,6 +1,5 @@
package at.gv.egiz.moazs.scheme;
-import at.gv.egiz.moazs.MoaZSException;
import at.gv.zustellung.app2mzs.xsd.Mzs2AppPortType;
import at.gv.zustellung.msg.xsd.DeliveryAnswerType;
@@ -33,7 +32,14 @@ public abstract class MsgResponse <T> {
public abstract String getAppDeliveryID();
public abstract String getZSDeliveryID();
public abstract DeliveryAnswerType getAnswer();
- public abstract MsgResponse<T> generateError(MoaZSException exception);
+
+ /**
+ * Create an error response that is based on the current response.
+ * @param text describes the error.
+ * @param code contains an error code.
+ * @return Deep Copy of response but of "error" type
+ */
+ public abstract MsgResponse<T> generateError(String text, String code);
public abstract CompletableFuture<Void> sendToMzsClient(Msg2MzsConverter converter, Optional<byte[]> signedStatus, Mzs2AppPortType client);
}
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java b/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java
index bb7f621..6b6f34a 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/NameSpace.java
@@ -16,5 +16,6 @@ public class NameSpace {
public static final String MSG_DELIVERY_REQUEST_STATUS = MSG_FACTORY.createDeliveryRequestStatus(null).getName().getLocalPart();
public static final String MSG_DELIVERY_NOTIFICATION = MSG_FACTORY.createDeliveryNotification(null).getName().getLocalPart();
+ public static final String MSG_APP_DELIVERY_ID = MSG_FACTORY.createAppDeliveryID("").getName().getLocalPart();
}
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java b/src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java
index 21e00a1..4e7abae 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java
@@ -1,16 +1,17 @@
package at.gv.egiz.moazs.scheme;
-import at.gv.egiz.moazs.MoaZSException;
import at.gv.zustellung.app2mzs.xsd.Mzs2AppPortType;
import at.gv.zustellung.msg.xsd.DeliveryAnswerType;
import at.gv.zustellung.msg.xsd.DeliveryNotificationType;
+import at.gv.zustellung.msg.xsd.ErrorInfoType;
import at.gv.zustellung.msg.xsd.ObjectFactory;
import javax.xml.bind.JAXBElement;
-
+import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import static at.gv.zustellung.msg.xsd.DeliveryErrorType.deliveryErrorTypeBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryNotificationType.deliveryNotificationTypeBuilder;
public class NotificationResponse extends MsgResponse<DeliveryNotificationType> {
@@ -54,14 +55,19 @@ public class NotificationResponse extends MsgResponse<DeliveryNotificationType>
}
@Override
- public NotificationResponse generateError(MoaZSException exception) {
-
- //TODO: use copy constructor?
- var notificationType = deliveryNotificationTypeBuilder()
- .withAppDeliveryID(exception.getAppDeliveryID())
- .withDeliverySystem(exception.getDeliverySystem())
- .withGZ(exception.getGz())
- .withZSDeliveryID(exception.getZsDeliveryID())
+ public NotificationResponse generateError(String text, String code) {
+
+ var info = ErrorInfoType.errorInfoTypeBuilder()
+ .withCode(code)
+ .withText(text)
+ .build();
+
+ var error = deliveryErrorTypeBuilder()
+ .withErrorInfo(info)
+ .build();
+
+ var notificationType = deliveryNotificationTypeBuilder(notification)
+ .withAnswer(List.of(factory.createAnswer(error)))
.build();
return new NotificationResponse(notificationType);
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java b/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java
index 14e22ad..8a4b590 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/RequestStatusResponse.java
@@ -6,11 +6,13 @@ import at.gv.zustellung.msg.xsd.DeliveryAnswerType;
import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType;
import at.gv.zustellung.msg.xsd.ErrorInfoType;
import at.gv.zustellung.msg.xsd.ObjectFactory;
+import org.springframework.lang.Nullable;
import javax.xml.bind.JAXBElement;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.egiz.moazs.util.NullCoalesce.coalesce;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Error.errorBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
@@ -26,10 +28,19 @@ public class RequestStatusResponse extends MsgResponse<DeliveryRequestStatusType
public RequestStatusResponse(DeliveryRequestStatusType status) {
this.status = status;
- this.answer = coalesce(status.getSuccess(), status.getPartialSuccess(), status.getError()).get();
+ this.answer = getAnswer(status);
super.id = createResponseId(answer.getAppDeliveryID(), ID_SUFFIX);
}
+ /**
+ * Convenience method to access DeliveryAnswerType's base fields of Success, PartialSuccess or Error.
+ * @param status
+ * @return Success, PartialSuccess, or Error casted to DeliveryAnswerType
+ */
+ public static DeliveryAnswerType getAnswer(DeliveryRequestStatusType status) {
+ return coalesce(status.getSuccess(), status.getPartialSuccess(), status.getError()).get();
+ }
+
public static String getResponseID(String appDeliveryID) {
return appDeliveryID + ID_SUFFIX;
}
@@ -60,31 +71,42 @@ public class RequestStatusResponse extends MsgResponse<DeliveryRequestStatusType
}
@Override
- public MsgResponse<DeliveryRequestStatusType> generateError(MoaZSException exception) {
- return generateErrorFromException(exception);
+ public MsgResponse<DeliveryRequestStatusType> generateError(String text, String code) {
+ var auxException = moaZSException(text, code);
+ return generateError(auxException, answer);
}
- public static MsgResponse<DeliveryRequestStatusType> generateErrorFromException(MoaZSException exception) {
+ /**
+ * Creates A MsgResponse with a DeliveryRequestStatus of type error and merges fields from
+ * {@code exception} and {@code answer}
+ * @param exception
+ * @param answer
+ * @return
+ */
+ public static MsgResponse<DeliveryRequestStatusType> generateError(MoaZSException exception,
+ @Nullable DeliveryAnswerType answer) {
ErrorInfoType info = errorInfoTypeBuilder()
.withText(exception.getMessage())
- .withCode(exception.getErrorCode())
+ .withCode(exception.getCode())
.build();
- DeliveryRequestStatusType.Error error = errorBuilder()
- .withErrorInfo(info)
- .withAppDeliveryID(exception.getAppDeliveryID())
- .withDeliverySystem(exception.getDeliverySystem())
- .withGZ(exception.getGz())
+ var errorBuilder = errorBuilder()
.withPreAdviceNoteSent(exception.getPreAdviceNoteSent())
- .withZSDeliveryID(exception.getZsDeliveryID())
- .build();
-
- var status = deliveryRequestStatusTypeBuilder()
- .withError(error)
- .withVersion(NameSpace.MSG_VERSION)
+ .withErrorInfo(info);
+
+ if (answer != null) {
+ errorBuilder
+ .withAppDeliveryID(answer.getAppDeliveryID())
+ .withDeliverySystem(answer.getDeliverySystem())
+ .withZSDeliveryID(answer.getZSDeliveryID())
+ .withGZ(answer.getGZ());
+ }
+
+ var errorStatus = deliveryRequestStatusTypeBuilder()
+ .withError(errorBuilder.build())
.build();
- return new RequestStatusResponse(status);
+ return new RequestStatusResponse(errorStatus);
}
@Override
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java b/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java
index 8b8219a..6e96a6b 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/SOAPUtils.java
@@ -1,6 +1,7 @@
package at.gv.egiz.moazs.scheme;
import at.gv.egiz.eaaf.core.impl.utils.DOMUtils;
+import at.gv.egiz.moazs.MoaZSException;
import org.apache.cxf.binding.soap.Soap11;
import org.springframework.stereotype.Component;
import org.w3c.dom.Element;
@@ -12,7 +13,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder;
@Component
public class SOAPUtils {
@@ -31,12 +31,12 @@ public class SOAPUtils {
.getBytes(StandardCharsets.UTF_8);
} catch (IOException | TransformerException e) {
- throw moaZSExceptionBuilder("Error while parsing message. ").withCause(e).build();
+ throw MoaZSException.moaZSException("Error while parsing message. ", e);
}
}
public String getAppDeliveryIDFrom(Element document) {
- var elements = document.getElementsByTagNameNS(NameSpace.MSG, "AppDeliveryID");
+ var elements = document.getElementsByTagNameNS(NameSpace.MSG, NameSpace.MSG_APP_DELIVERY_ID);
var appDeliveryIdElement = elements.item(0).getFirstChild();