aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/gv/egiz/moazs/config/RepositoryConfig.java10
-rw-r--r--src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java20
-rw-r--r--src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java22
-rw-r--r--src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java12
-rw-r--r--src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java37
-rw-r--r--src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java20
-rw-r--r--src/main/java/at/gv/egiz/moazs/service/MsgService.java2
-rw-r--r--src/main/java/at/gv/egiz/moazs/service/MzsService.java11
-rw-r--r--src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java10
-rw-r--r--src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java15
10 files changed, 84 insertions, 75 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/config/RepositoryConfig.java b/src/main/java/at/gv/egiz/moazs/config/RepositoryConfig.java
index 01a4cc3..59bfb88 100644
--- a/src/main/java/at/gv/egiz/moazs/config/RepositoryConfig.java
+++ b/src/main/java/at/gv/egiz/moazs/config/RepositoryConfig.java
@@ -1,7 +1,5 @@
package at.gv.egiz.moazs.config;
-import at.gv.egiz.moazs.repository.BinaryRepository;
-import at.gv.egiz.moazs.repository.InMemoryBinaryRepository;
import at.gv.egiz.moazs.scheme.NameSpace;
import at.gv.egiz.moazs.scheme.NotificationResponse;
import at.gv.egiz.moazs.scheme.RequestStatusResponse;
@@ -17,17 +15,13 @@ import java.util.function.Function;
@Profile("!cluster")
public class RepositoryConfig {
- @Value("${repository.expiresAfterWrite}")
- private int expiresAfterWrite;
-
@Bean
- public BinaryRepository binaryRepository() {
- return new InMemoryBinaryRepository(expiresAfterWrite);
+ public int expiresAfterWrite(@Value("${repository.expiresAfterWrite}") int exp) {
+ return exp;
}
@Bean
public Map<String, Function<String, String>> idGenerators() {
-
return Map.of(NameSpace.MSG_DELIVERY_REQUEST_STATUS, RequestStatusResponse::getResponseID,
NameSpace.MSG_DELIVERY_NOTIFICATION, NotificationResponse::getResponseID);
}
diff --git a/src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java b/src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java
index ee32768..12a9fe3 100644
--- a/src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java
+++ b/src/main/java/at/gv/egiz/moazs/process/SafeResponseToFileSink.java
@@ -1,6 +1,6 @@
package at.gv.egiz.moazs.process;
-import at.gv.egiz.moazs.repository.BinaryRepository;
+import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.Marshaller;
import at.gv.egiz.moazs.scheme.MsgResponse;
import org.apache.commons.io.FileUtils;
@@ -28,32 +28,32 @@ public class SafeResponseToFileSink implements MsgResponseSink {
private static final SimpleDateFormat ISO_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private final Marshaller msgMarshaller;
- private final BinaryRepository binaryRepository;
+ private final DeliveryRepository respository;
private final String root;
@Autowired
- public SafeResponseToFileSink(Marshaller msgMarshaller, BinaryRepository binaryRepository, String root) {
+ public SafeResponseToFileSink(Marshaller msgMarshaller, DeliveryRepository binaryRepository, String root) {
this.msgMarshaller = msgMarshaller;
- this.binaryRepository = binaryRepository;
+ this.respository = binaryRepository;
this.root = root;
}
@Override
public CompletableFuture<Void> handle(MsgResponse response) {
- var responseId = response.getResponseID();
+ var responseID = response.getResponseID();
- var responsePath = generatePath(responseId, "xml");
+ var responsePath = generatePath(responseID, "xml");
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(() -> binaryRepository.get(responseId).get())
+ var binaryResponsePath = generatePath(responseID, "binary.xml");
+ var storeBinaryResponseToFileSystemFuture = supplyAsync(() -> respository.retrieveBinaryResponse(responseID).get())
.thenAccept(binaryResponseByteArray -> storeToFile(binaryResponsePath, binaryResponseByteArray))
- .exceptionally((ex) -> logException(ex, responseId));
+ .exceptionally((ex) -> logException(ex, responseID));
return allOf(storeResponseToFileSystemFuture, storeBinaryResponseToFileSystemFuture);
diff --git a/src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java b/src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java
index 69065d7..445f386 100644
--- a/src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java
+++ b/src/main/java/at/gv/egiz/moazs/process/SingleThreadedDeliveryPipeline.java
@@ -4,7 +4,6 @@ package at.gv.egiz.moazs.process;
import at.gv.egiz.moazs.MoaZSException;
import at.gv.egiz.moazs.client.ClientFactory;
import at.gv.egiz.moazs.client.TnvzHelper;
-import at.gv.egiz.moazs.repository.BinaryRepository;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.Mzs2MsgConverter;
import at.gv.egiz.moazs.scheme.RequestStatusResponse;
@@ -31,7 +30,6 @@ public class SingleThreadedDeliveryPipeline implements DeliveryPipeline {
"An error occured while processing the DeliveryRequest with AppDeliveryID=%s. ";
private final DeliveryRepository repository;
- private final BinaryRepository binaryRepository;
private final TnvzHelper tnvzHelper;
private final Mzs2MsgConverter converter;
private final ClientFactory clientFactory;
@@ -39,13 +37,11 @@ public class SingleThreadedDeliveryPipeline implements DeliveryPipeline {
@Autowired
public SingleThreadedDeliveryPipeline(DeliveryRepository repository,
- BinaryRepository binaryStatusRepository,
TnvzHelper tnvzHelper,
Mzs2MsgConverter converter,
ClientFactory clientFactory,
SignatureVerifier verifier) {
this.repository = repository;
- this.binaryRepository = binaryStatusRepository;
this.tnvzHelper = tnvzHelper;
this.converter = converter;
this.clientFactory = clientFactory;
@@ -53,12 +49,12 @@ public class SingleThreadedDeliveryPipeline implements DeliveryPipeline {
}
@Override
- public void processRequest(String appDeliveryId) {
+ public void processRequest(String appDeliveryID) {
var exceptionBuilder = moaZSExceptionBuilder();
try {
- var mzsRequest = repository.getDeliveryRequest(appDeliveryId).orElseThrow();
+ var mzsRequest = repository.retrieveDeliveryRequest(appDeliveryID).orElseThrow();
exceptionBuilder.withDeliverySystem(mzsRequest);
at.gv.zustellung.msg.xsd.DeliveryRequestType msgRequest = buildMsgRequest(mzsRequest, exceptionBuilder);
@@ -70,22 +66,22 @@ public class SingleThreadedDeliveryPipeline implements DeliveryPipeline {
var response = new RequestStatusResponse(status);
exceptionBuilder.withAllParametersInAnswer(response.getAnswer());
- verifySignedStatus(response.getResponseID(), exceptionBuilder);
- repository.add(response);
+ verifySignedStatus(response.getResponseID(), appDeliveryID, exceptionBuilder);
+ repository.store(response);
} catch (MoaZSException exception) {
- log.error(format(MZS_PIPELINE_ERROR_MSG, appDeliveryId), exception);
+ log.error(format(MZS_PIPELINE_ERROR_MSG, appDeliveryID), exception);
var errorResponse = generateErrorFromException(exception);
- repository.add(errorResponse);
+ repository.store(errorResponse);
}
}
- private void verifySignedStatus(String appDeliveryId, MoaZSException.Builder exceptionBuilder) throws MoaZSException {
+ private void verifySignedStatus(String responseID, String appDeliveryID, MoaZSException.Builder exceptionBuilder) throws MoaZSException {
try {
- var signedStatus = binaryRepository.get(appDeliveryId).get();
+ var signedStatus = repository.retrieveBinaryResponse(responseID).get();
verifier.verify(signedStatus);
} catch (MoaZSException ex) {
- throw exceptionBuilder.withMessage(format(MsgResponseVerifier.MOASP_SIGNATURE_INVALID_ERROR_MSG, appDeliveryId))
+ throw exceptionBuilder.withMessage(format(MsgResponseVerifier.MOASP_SIGNATURE_INVALID_ERROR_MSG, appDeliveryID))
.withErrorCode(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID)
.withCause(ex)
.build();
diff --git a/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java b/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java
index 57d2d07..e9b0466 100644
--- a/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java
+++ b/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java
@@ -11,13 +11,17 @@ import java.util.Optional;
@Repository
public interface DeliveryRepository {
- void add(DeliveryRequestType request);
+ void store(DeliveryRequestType request);
- Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID);
+ Optional<DeliveryRequestType> retrieveDeliveryRequest(String appDeliveryID);
- void add(MsgResponse response);
+ void store(MsgResponse response);
- Optional<MsgResponse> getResponse(String responseID);
+ Optional<MsgResponse> retrieveResponse(String responseID);
+
+ void store(String responseID, byte[] data);
+
+ Optional<byte[]> retrieveBinaryResponse(String responseID);
}
diff --git a/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java b/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java
index 3b5a020..41b742b 100644
--- a/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java
+++ b/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java
@@ -4,46 +4,61 @@ package at.gv.egiz.moazs.repository;
import at.gv.egiz.moazs.scheme.MsgResponse;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Repository;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
+import static com.google.common.cache.CacheBuilder.newBuilder;
import static java.util.Optional.ofNullable;
@Repository
@Profile("!cluster")
public class InMemoryDeliveryRepository implements DeliveryRepository {
- private final Cache<String, DeliveryRequestType> requestRepository = CacheBuilder.newBuilder()
- .expireAfterWrite(30, TimeUnit.MINUTES)
- .build();
+ private final Cache<String, DeliveryRequestType> requestRepository;
+ private final Cache<String, MsgResponse> responseRepository;
+ private final Cache<String, byte[]> binaryResponseRepository;
- private final Cache<String, MsgResponse> responseRepository = CacheBuilder.newBuilder()
- .expireAfterWrite(30, TimeUnit.MINUTES)
- .build();
+ public InMemoryDeliveryRepository(int expiresAfterWrite) {
+ var builder = newBuilder().expireAfterWrite(expiresAfterWrite, TimeUnit.MINUTES);
+ this.requestRepository = builder.build();
+ this.responseRepository = builder.build();
+ this.binaryResponseRepository = builder.build();
+ }
@Override
- public void add(DeliveryRequestType request) {
+ public void store(DeliveryRequestType request) {
var key = request.getMetaData().getAppDeliveryID();
requestRepository.put(key, request);
}
@Override
- public Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID) {
+ public Optional<DeliveryRequestType> retrieveDeliveryRequest(String appDeliveryID) {
return ofNullable(requestRepository.getIfPresent(appDeliveryID));
}
@Override
- public void add(MsgResponse response) {
+ public void store(MsgResponse response) {
String key = response.getResponseID();
responseRepository.put(key, response);
}
@Override
- public Optional<MsgResponse> getResponse(String responseID) {
+ public Optional<MsgResponse> retrieveResponse(String responseID) {
return ofNullable(responseRepository.getIfPresent(responseID));
}
+
+ @Override
+ public void store(String id, byte[] data) {
+ binaryResponseRepository.put(id, data);
+
+ }
+
+ @Override
+ public Optional<byte[]> retrieveBinaryResponse(String responseID) {
+ return ofNullable(binaryResponseRepository.getIfPresent(responseID));
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java b/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java
index 7ccd236..68e96d9 100644
--- a/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java
+++ b/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java
@@ -3,8 +3,6 @@ package at.gv.egiz.moazs.repository;
import at.gv.egiz.moazs.scheme.Marshaller;
import at.gv.egiz.moazs.scheme.MsgResponse;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
-import at.gv.zustellung.msg.xsd.DeliveryNotificationType;
-import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType;
import at.gv.zustellung.app2mzs.xsd.ObjectFactory;
import org.apache.tools.ant.filters.StringInputStream;
import org.slf4j.Logger;
@@ -42,7 +40,7 @@ public class RedisDeliveryRepository implements DeliveryRepository {
}
@Override
- public void add(DeliveryRequestType request) {
+ public void store(DeliveryRequestType request) {
var hashKey = request.getMetaData().getAppDeliveryID();
var serializedRequest = marshaller.marshallXml(factory.createDeliveryRequest(request));
@@ -51,7 +49,7 @@ public class RedisDeliveryRepository implements DeliveryRepository {
}
@Override
- public Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID) {
+ public Optional<DeliveryRequestType> retrieveDeliveryRequest(String appDeliveryID) {
String serializedRequest = hashOperations.get(KEY, appDeliveryID);
if (serializedRequest == null) {
@@ -64,14 +62,24 @@ public class RedisDeliveryRepository implements DeliveryRepository {
}
@Override
- public void add(MsgResponse notification) {
+ public void store(MsgResponse notification) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE);
}
@Override
- public Optional<MsgResponse> getResponse(String id) {
+ public Optional<MsgResponse> retrieveResponse(String id) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE);
}
+ @Override
+ public void store(String responseID, byte[] data) {
+
+ }
+
+ @Override
+ public Optional<byte[]> retrieveBinaryResponse(String responseID) {
+ return Optional.empty();
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/moazs/service/MsgService.java b/src/main/java/at/gv/egiz/moazs/service/MsgService.java
index 93f1ed5..87644a0 100644
--- a/src/main/java/at/gv/egiz/moazs/service/MsgService.java
+++ b/src/main/java/at/gv/egiz/moazs/service/MsgService.java
@@ -58,7 +58,7 @@ public class MsgService implements Zuse2AppPort {
}
private void sendToWork(MsgResponse response) {
- runAsync(() -> repository.add(response))
+ runAsync(() -> repository.store(response))
.thenRunAsync(() -> handler.handle(response.getResponseID()));
}
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 c41740f..2755a37 100644
--- a/src/main/java/at/gv/egiz/moazs/service/MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/service/MzsService.java
@@ -2,7 +2,6 @@ package at.gv.egiz.moazs.service;
import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter;
import at.gv.egiz.moazs.process.DeliveryPipeline;
-import at.gv.egiz.moazs.repository.BinaryRepository;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.Msg2MzsConverter;
import at.gv.egiz.moazs.client.MzsClient;
@@ -41,17 +40,15 @@ public class MzsService implements App2MzsPortType {
private final MzsClient appClient;
private final DeliveryRequestAugmenter augmenter;
private final Msg2MzsConverter converter;
- private final BinaryRepository binaryStatusRepository;
@Autowired
public MzsService(DeliveryRepository repository, DeliveryPipeline pipeline, MzsClient appClient,
- DeliveryRequestAugmenter augmenter, Msg2MzsConverter converter, BinaryRepository binaryStatusRepository) {
+ DeliveryRequestAugmenter augmenter, Msg2MzsConverter converter) {
this.repository = repository;
this.pipeline = pipeline;
this.appClient = appClient;
this.augmenter = augmenter;
this.converter = converter;
- this.binaryStatusRepository = binaryStatusRepository;
}
@Override
@@ -65,7 +62,7 @@ public class MzsService implements App2MzsPortType {
var future = supplyAsync(() -> augmenter.augment(deliveryRequest))
.thenApply(this::process)
- .thenApply(status -> converter.convert(status, binaryStatusRepository.get(responseID)));
+ .thenApply(status -> converter.convert(status, repository.retrieveBinaryResponse(responseID)));
try {
return future.get(TIMEOUT_FOR_ANWSER, TimeUnit.SECONDS);
@@ -89,11 +86,11 @@ public class MzsService implements App2MzsPortType {
var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID();
logger.info("Receive request with appDeliveryID = {}.", appDeliveryID);
- repository.add(deliveryRequest);
+ repository.store(deliveryRequest);
pipeline.processRequest(appDeliveryID);
var statusId = RequestStatusResponse.getResponseID(appDeliveryID);
- var response = repository.getResponse(statusId)
+ var response = repository.retrieveResponse(statusId)
.orElseThrow(() -> moaZSException("Could not get a response for AppDeliveryID=%s.", appDeliveryID));
return (DeliveryRequestStatusType) response.getResponse();
}
diff --git a/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java b/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java
index 39566fe..88ab7e0 100644
--- a/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java
+++ b/src/main/java/at/gv/egiz/moazs/util/StoreSOAPBodyBinaryInRepositoryInterceptor.java
@@ -1,6 +1,6 @@
package at.gv.egiz.moazs.util;
-import at.gv.egiz.moazs.repository.BinaryRepository;
+import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.SOAPUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -28,12 +28,12 @@ public class StoreSOAPBodyBinaryInRepositoryInterceptor extends AbstractPhaseInt
private final CXFMessageUtils messageUtils;
private final SOAPUtils soapUtils;
private final Map<String, Function<String, String>> idGenerators;
- private final BinaryRepository repository;
+ private final DeliveryRepository repository;
@Autowired
public StoreSOAPBodyBinaryInRepositoryInterceptor(CXFMessageUtils extractor, SOAPUtils soapUtils,
Map<String, Function<String, String>> idGenerators,
- BinaryRepository repository) {
+ DeliveryRepository repository) {
super(Phase.RECEIVE);
this.messageUtils = extractor;
this.soapUtils = soapUtils;
@@ -60,12 +60,12 @@ public class StoreSOAPBodyBinaryInRepositoryInterceptor extends AbstractPhaseInt
String rootTag = document.getTagName();
if (!idGenerators.containsKey(rootTag)) {
- log.trace("Will not add message of type {}. ", rootTag);
+ log.trace("Will not store message of type {}. ", rootTag);
return;
}
var id = idGenerators.get(rootTag).apply(appDeliveryID);
- repository.add(id, response);
+ repository.store(id, response);
if(log.isTraceEnabled()) {
log.trace("Msg Response with AppDeliveryID={} unwrapped and stored: {}. ",
diff --git a/src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java b/src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java
index 6b4ef7a..9c8b17c 100644
--- a/src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java
+++ b/src/main/java/at/gv/egiz/moazs/verify/MsgResponseVerifier.java
@@ -1,7 +1,6 @@
package at.gv.egiz.moazs.verify;
import at.gv.egiz.moazs.MoaZSException;
-import at.gv.egiz.moazs.repository.BinaryRepository;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.MsgResponse;
import at.gv.egiz.moazs.service.MsgService;
@@ -20,25 +19,21 @@ public class MsgResponseVerifier {
public static final String MOASP_SIGNATURE_INVALID_ERROR_MSG = "Signature of Msg Response " +
"with AppDeliveryID=%s is not valid.";
- private final DeliveryRepository repo;
- private final BinaryRepository binaryRepo;
+ private final DeliveryRepository repository;
private final SignatureVerifier verifier;
@Autowired
- public MsgResponseVerifier(DeliveryRepository repo,
- BinaryRepository binaryStatusRepository,
- SignatureVerifier verifier) {
- this.repo = repo;
- this.binaryRepo = binaryStatusRepository;
+ public MsgResponseVerifier(DeliveryRepository repository, SignatureVerifier verifier) {
+ this.repository = repository;
this.verifier = verifier;
}
public MsgResponse verify(String responseID) {
- var response = repo.getResponse(responseID).get();
+ var response = repository.retrieveResponse(responseID).get();
var builder = moaZSExceptionBuilder().withAllParametersInAnswer(response.getAnswer());
- var binaryResponse = binaryRepo.get(responseID).get();
+ var binaryResponse = repository.retrieveBinaryResponse(responseID).get();
try {
verifier.verify(binaryResponse);