From c1a1a5130a4ecf755da72941ad3525beb919447f Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Mon, 8 Jul 2019 18:02:37 +0200 Subject: Implement Zuse2App Services - Add zuse2app.wsdl contract. - Add MsgResponse as an type-agnostic view for DeliveryRequestStatus and DeliveryNotification messages. Reason: Both DeliveryNotification and DeliveryRequestStatus messages have similar fields and need to be treated similarly (e.g.: receive from msg service, store to repository, verify signature, store to file...). In order to prevent duplicated code, the wrapper interface provides a type-agnostic view onto these messages for depending components to operate on. - Add MsgResponseHandler interface; decides how to process MsgResponse. Also implement this handler with a multi-threaded single-node implementation. - Add MsgResponseSink interface; decides how to archive MsgResponse. - Implement and test SafeResponseToFileSink. Change Identifier for MsgResponses: - Before, DeliveryRequestStatus and DeliveryNotifications had their own repositories. Now, both types are stored in the same repository (the MsgResponse repository) to streamline the handling of MsgResponses. We need to change the identification of MsgReponses, otherwise the identifiers (AppDeliveryID) clash. - MsgResponses are not identified by: + - Rewrite StoreSOAPInterceptor to accommodate fact that, both DeliveryRequestStatus and DeliveryNotification messages have different IDs upon storage / retrieval. Restructure packages and components as follows: - client: All components that are involved when consuming a web service. - process: "fabric" of MoaZS; contains business logic that orchestrates back-end tasks of MoaZS's operational services, e.g.: by processing a delivery request. - service: Implementation of MoaZS's front-end services. Refactoring: - MoaZSException: Remove unused fields. Before: Store mzsrequest, tnvzresult, msgrequest and msgresult as members. Now: Only keep the fields that are needed later, e.g for generating a msg:DeliveryRequestStatus element. Add copy constructor to Builder. - Put storage of byte[] into a dedicated "BinaryRepository". Reason: This was useful in a former design. Now it's not really needed anymore. - Put "create Endpoint" code into EndpointFactory. Reason: Eliminate duplicated code when configuring a service. Testing: - Activate Stacktraces in surefire. --- .../egiz/moazs/repository/DeliveryRepository.java | 10 +++--- .../repository/InMemoryDeliveryRepository.java | 37 ++++++---------------- .../moazs/repository/RedisDeliveryRepository.java | 16 +++------- 3 files changed, 18 insertions(+), 45 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/repository') 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 be61d1e..d0a8148 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java @@ -1,6 +1,8 @@ package at.gv.egiz.moazs.repository; +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 org.springframework.stereotype.Repository; @@ -13,13 +15,9 @@ public interface DeliveryRepository { Optional getDeliveryRequest(String appDeliveryID); - void add(DeliveryRequestStatusType status); + void add(MsgResponse response); - Optional getDeliveryRequestStatus(String appDeliveryID); - - void addSignedDeliveryRequestStatus(byte[] bytes, String appDeliveryId); - - Optional getSignedDeliveryRequestStatus(String appDeliveryID); + Optional getResponse(String id); } 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 58ec92c..d9abb7b 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java @@ -1,36 +1,27 @@ package at.gv.egiz.moazs.repository; +import at.gv.egiz.moazs.scheme.MsgResponse; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; -import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.concurrent.TimeUnit; -import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; import static java.util.Optional.ofNullable; @Repository @Profile("!cluster") public class InMemoryDeliveryRepository implements DeliveryRepository { - private static final Logger logger = LoggerFactory.getLogger(InMemoryDeliveryRepository.class); - - private static final Cache requestRepository = CacheBuilder.newBuilder() + private final Cache requestRepository = CacheBuilder.newBuilder() .expireAfterWrite(30, TimeUnit.MINUTES) .build(); - private static final Cache statusRepository = CacheBuilder.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .build(); - - private static final Cache signedStatusRepository = CacheBuilder.newBuilder() + private final Cache responseRepository = CacheBuilder.newBuilder() .expireAfterWrite(30, TimeUnit.MINUTES) .build(); @@ -46,24 +37,14 @@ public class InMemoryDeliveryRepository implements DeliveryRepository { } @Override - public void add(DeliveryRequestStatusType status) { - var key = coalesce(status.getSuccess(), status.getPartialSuccess(), status.getError()) - .get().getAppDeliveryID(); - statusRepository.put(key, status); - } - - @Override - public Optional getDeliveryRequestStatus(String appDeliveryID) { - return ofNullable(statusRepository.getIfPresent(appDeliveryID)); - } - - @Override - public void addSignedDeliveryRequestStatus(byte[] bytes, String appDeliveryId) { - signedStatusRepository.put(appDeliveryId, bytes); + public void add(MsgResponse response) { + String key = response.getResponseID(); + System.out.println("storing with response id " + key); + responseRepository.put(key, response); } @Override - public Optional getSignedDeliveryRequestStatus(String appDeliveryID) { - return ofNullable(signedStatusRepository.getIfPresent(appDeliveryID)); + public Optional getResponse(String id) { + return ofNullable(responseRepository.getIfPresent(id)); } } 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 9b7aefd..7ccd236 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java @@ -1,7 +1,9 @@ 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; @@ -50,7 +52,7 @@ public class RedisDeliveryRepository implements DeliveryRepository { @Override public Optional getDeliveryRequest(String appDeliveryID) { - var serializedRequest = hashOperations.get(KEY, appDeliveryID); + String serializedRequest = hashOperations.get(KEY, appDeliveryID); if (serializedRequest == null) { return Optional.empty(); @@ -62,22 +64,14 @@ public class RedisDeliveryRepository implements DeliveryRepository { } @Override - public void add(DeliveryRequestStatusType status) { + public void add(MsgResponse notification) { throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE); - } - @Override - public Optional getDeliveryRequestStatus(String appDeliveryID) { - throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE); } @Override - public void addSignedDeliveryRequestStatus(byte[] bytes, String appDeliveryId) { + public Optional getResponse(String id) { throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE); } - @Override - public Optional getSignedDeliveryRequestStatus(String appDeliveryID) { - return Optional.empty(); - } } -- cgit v1.2.3