aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv')
-rw-r--r--src/main/java/at/gv/egiz/moazs/MoaZSException.java25
-rw-r--r--src/main/java/at/gv/egiz/moazs/client/ClientFactory.java (renamed from src/main/java/at/gv/egiz/moazs/util/ClientFactory.java)0
-rw-r--r--src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java (renamed from src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java)0
-rw-r--r--src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java1
-rw-r--r--src/main/java/at/gv/egiz/moazs/process/SaveResponseToFileSink.java (renamed from src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java)33
-rw-r--r--src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java2
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java10
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java6
8 files changed, 36 insertions, 41 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/MoaZSException.java b/src/main/java/at/gv/egiz/moazs/MoaZSException.java
index 1e86c22..dbb2894 100644
--- a/src/main/java/at/gv/egiz/moazs/MoaZSException.java
+++ b/src/main/java/at/gv/egiz/moazs/MoaZSException.java
@@ -5,9 +5,6 @@ import at.gv.zustellung.msg.xsd.PreAdviceNoteSentType;
import at.gv.zustellung.tnvz.xsd.PersonResultType;
import org.springframework.lang.Nullable;
-import java.util.concurrent.ExecutorService;
-
-
public class MoaZSException extends RuntimeException {
public static final String ERROR_MZS_MIMETYPE_MISSMATCH = "8001";
@@ -27,19 +24,16 @@ public class MoaZSException extends RuntimeException {
@Nullable
private final String appDeliveryID;
- private MoaZSException(String message, @Nullable Throwable cause, @Nullable String errorCode, @Nullable PreAdviceNoteSentType preAdviceNoteSent,
- @Nullable String deliverySystem, @Nullable String gz, @Nullable String zsDeliveryID,
- @Nullable String appDeliveryID) {
- super(message, cause);
- this.errorCode = errorCode;
- this.preAdviceNoteSent = preAdviceNoteSent;
- this.deliverySystem = deliverySystem;
- this.gz = gz;
- this.zsDeliveryID = zsDeliveryID;
- this.appDeliveryID = appDeliveryID;
+ private MoaZSException(Builder builder) {
+ super(builder.message, builder.cause);
+ this.errorCode = builder.errorCode;
+ this.preAdviceNoteSent = builder.preAdviceNoteSent;
+ this.deliverySystem = builder.deliverySystem;
+ this.gz = builder.gz;
+ this.zsDeliveryID = builder.zsDeliveryID;
+ this.appDeliveryID = builder.appDeliveryID;
}
-
public static MoaZSException moaZSException(String message, Throwable cause) {
return moaZSExceptionBuilder(message).withCause(cause).build();
}
@@ -166,8 +160,7 @@ public class MoaZSException extends RuntimeException {
}
public MoaZSException build() {
- return new MoaZSException(message, cause, errorCode, preAdviceNoteSent, deliverySystem, gz,
- zsDeliveryID, appDeliveryID);
+ return new MoaZSException(this);
}
}
diff --git a/src/main/java/at/gv/egiz/moazs/util/ClientFactory.java b/src/main/java/at/gv/egiz/moazs/client/ClientFactory.java
index d0a445b..d0a445b 100644
--- a/src/main/java/at/gv/egiz/moazs/util/ClientFactory.java
+++ b/src/main/java/at/gv/egiz/moazs/client/ClientFactory.java
diff --git a/src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java b/src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java
index 8fb5d80..8fb5d80 100644
--- a/src/main/java/at/gv/egiz/moazs/util/SSLContextCreator.java
+++ b/src/main/java/at/gv/egiz/moazs/client/SSLContextCreator.java
diff --git a/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java b/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java
index 8e354ab..42019b1 100644
--- a/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/config/ServicesConfig.java
@@ -3,7 +3,6 @@ package at.gv.egiz.moazs.config;
import at.gv.egiz.moazs.service.MsgService;
import at.gv.egiz.moazs.service.MzsService;
import at.gv.egiz.moazs.util.EndpointFactory;
-import at.gv.egiz.moazs.util.StoreSOAPBodyBinaryInRepositoryInterceptor;
import at.gv.zustellung.app2mzs.xsd.App2Mzs;
import at.gv.zustellung.msg.xsd.Zuse2AppPortService;
import org.apache.cxf.interceptor.Interceptor;
diff --git a/src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java b/src/main/java/at/gv/egiz/moazs/process/SaveResponseToFileSink.java
index 12a9fe3..09d8570 100644
--- a/src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java
+++ b/src/main/java/at/gv/egiz/moazs/process/SaveResponseToFileSink.java
@@ -16,27 +16,28 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CompletableFuture;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static java.lang.String.format;
import static java.util.concurrent.CompletableFuture.allOf;
import static java.util.concurrent.CompletableFuture.supplyAsync;
@Component
-public class SafeResponseToFileSink implements MsgResponseSink {
+public class SaveResponseToFileSink implements MsgResponseSink {
- private static final Logger log = LoggerFactory.getLogger(SafeResponseToFileSink.class);
- private static final String SAFING_FAILED_MSG = "Could not save response with AppDeliveryId=%s.";
- private static final SimpleDateFormat ISO_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ private static final Logger log = LoggerFactory.getLogger(SaveResponseToFileSink.class);
+ private static final String SAVING_FAILED_MSG = "Could not save response with AppDeliveryId=%s.";
+ private final SimpleDateFormat isoFormatter;
private final Marshaller msgMarshaller;
- private final DeliveryRepository respository;
+ private final DeliveryRepository repository;
private final String root;
-
@Autowired
- public SafeResponseToFileSink(Marshaller msgMarshaller, DeliveryRepository binaryRepository, String root) {
+ public SaveResponseToFileSink(Marshaller msgMarshaller, DeliveryRepository repository, String root) {
this.msgMarshaller = msgMarshaller;
- this.respository = binaryRepository;
+ this.repository = repository;
this.root = root;
+ this.isoFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
}
@Override
@@ -48,12 +49,12 @@ public class SafeResponseToFileSink implements MsgResponseSink {
var storeResponseToFileSystemFuture = supplyAsync(() -> msgMarshaller.marshallXml(response.getResponse()))
.thenApply(responseString -> responseString.getBytes(StandardCharsets.UTF_8))
.thenAccept(responseByteArray -> storeToFile(responsePath, responseByteArray))
- .exceptionally((ex) -> logException(ex, responseID));
+ .exceptionally(ex -> logException(ex, responseID));
var binaryResponsePath = generatePath(responseID, "binary.xml");
- var storeBinaryResponseToFileSystemFuture = supplyAsync(() -> respository.retrieveBinaryResponse(responseID).get())
+ var storeBinaryResponseToFileSystemFuture = supplyAsync(() -> repository.retrieveBinaryResponse(responseID).get())
.thenAccept(binaryResponseByteArray -> storeToFile(binaryResponsePath, binaryResponseByteArray))
- .exceptionally((ex) -> logException(ex, responseID));
+ .exceptionally(ex -> logException(ex, responseID));
return allOf(storeResponseToFileSystemFuture, storeBinaryResponseToFileSystemFuture);
@@ -61,8 +62,8 @@ public class SafeResponseToFileSink implements MsgResponseSink {
private String generatePath(String id, String suffix) {
var folder = sanitizeFileString(id);
- var iso8601_now = ISO_FORMATTER.format(new Date());
- return format("%s/%s/%s.%s", root, folder, iso8601_now, suffix);
+ var nowInIso8601 = isoFormatter.format(new Date());
+ return format("%s/%s/%s.%s", root, folder, nowInIso8601, suffix);
}
private String sanitizeFileString(String fileString) {
@@ -70,7 +71,9 @@ public class SafeResponseToFileSink implements MsgResponseSink {
}
private Void logException(Throwable ex, String appDeliveryID) {
- log.error(format(SAFING_FAILED_MSG, appDeliveryID), ex);
+ if(log.isErrorEnabled()) {
+ log.error(format(SAVING_FAILED_MSG, appDeliveryID), ex);
+ }
return null;
}
@@ -78,7 +81,7 @@ public class SafeResponseToFileSink implements MsgResponseSink {
try {
FileUtils.writeByteArrayToFile(new File(path), content);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw moaZSException(e.getMessage(), e);
}
}
}
diff --git a/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java b/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java
index b115e27..65f5eed 100644
--- a/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java
+++ b/src/main/java/at/gv/egiz/moazs/process/SingleNodeResponseHandler.java
@@ -21,6 +21,6 @@ public class SingleNodeResponseHandler implements MsgResponseHandler {
@Override
public void handle(String responseID) {
supplyAsync(() -> verifier.verify(responseID))
- .thenAcceptAsync((response) -> sink.handle(response));
+ .thenAcceptAsync(response -> sink.handle(response));
}
}
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 699819f..80e2059 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/MsgResponse.java
@@ -19,10 +19,10 @@ public abstract class MsgResponse <T> {
return id;
}
- abstract public T getResponse();
- abstract public String getAppDeliveryID();
- abstract public String getZSDeliveryID();
- abstract public DeliveryAnswerType getAnswer();
- abstract public MsgResponse<T> generateError(MoaZSException exception);
+ public abstract T getResponse();
+ public abstract String getAppDeliveryID();
+ public abstract String getZSDeliveryID();
+ public abstract DeliveryAnswerType getAnswer();
+ public abstract MsgResponse<T> generateError(MoaZSException exception);
}
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 7670ab7..de1fd38 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/NotificationResponse.java
@@ -9,7 +9,7 @@ import static at.gv.zustellung.msg.xsd.DeliveryNotificationType.deliveryNotifica
public class NotificationResponse extends MsgResponse<DeliveryNotificationType> {
private final DeliveryNotificationType notification;
- private final static String ID_SUFFIX = ".NO";
+ private static final String ID_SUFFIX = ".NO";
public NotificationResponse(DeliveryNotificationType notification) {
super.id = createResponseId(notification.getAppDeliveryID(), ID_SUFFIX);
@@ -44,14 +44,14 @@ public class NotificationResponse extends MsgResponse<DeliveryNotificationType>
public MsgResponse<DeliveryNotificationType> generateError(MoaZSException exception) {
//TODO: test this!
- var notification = deliveryNotificationTypeBuilder()
+ var notificationType = deliveryNotificationTypeBuilder()
.withAppDeliveryID(exception.getAppDeliveryID())
.withDeliverySystem(exception.getDeliverySystem())
.withGZ(exception.getGz())
.withZSDeliveryID(exception.getZsDeliveryID())
.build();
- return new NotificationResponse(notification);
+ return new NotificationResponse(notificationType);
}
}