aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/pipeline
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-09 10:32:54 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-09 10:32:54 +0200
commitd8c668bbca31a835c387a3d52293c9938c424f58 (patch)
tree819c44930a05071e8f8645a1427f9485a79da664 /src/main/java/at/gv/egiz/moazs/pipeline
parentc1a1a5130a4ecf755da72941ad3525beb919447f (diff)
downloadmoa-zs-d8c668bbca31a835c387a3d52293c9938c424f58.tar.gz
moa-zs-d8c668bbca31a835c387a3d52293c9938c424f58.tar.bz2
moa-zs-d8c668bbca31a835c387a3d52293c9938c424f58.zip
Refactor MsgResponse and its IDs
StoreSOAPBodyBinaryInRepositoryInterceptor: - Replace "generate body's id via concatenation" with "give the right generator function the app delivery id and let the generator function do the work". Reason: Prevent the logistics of deriving IDs to spill into unrelated components. MsgResponse refactor: - Make MsgResponse an abstract class. - Derive ResponseID's ONLY in MsgResponse::createResponseID. Others: - Ensure that all invocations to DeliveryRepository.getResponse and BinaryRepository.get use "responseID" instead of ambiguous "id" or incorrect "appDeliveryID". - Move SingleThreadedDeliveryPipeline into process package.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/pipeline')
-rw-r--r--src/main/java/at/gv/egiz/moazs/pipeline/SingleThreadedDeliveryPipeline.java107
1 files changed, 0 insertions, 107 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/pipeline/SingleThreadedDeliveryPipeline.java b/src/main/java/at/gv/egiz/moazs/pipeline/SingleThreadedDeliveryPipeline.java
deleted file mode 100644
index 69065d7..0000000
--- a/src/main/java/at/gv/egiz/moazs/pipeline/SingleThreadedDeliveryPipeline.java
+++ /dev/null
@@ -1,107 +0,0 @@
-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;
-import at.gv.egiz.moazs.verify.MsgResponseVerifier;
-import at.gv.egiz.moazs.verify.SignatureVerifier;
-import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
-import at.gv.zustellung.msg.xsd.App2ZusePort;
-import at.gv.zustellung.tnvz.xsd.TNVZServicePort;
-import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Profile;
-import org.springframework.stereotype.Component;
-
-import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder;
-import static at.gv.egiz.moazs.scheme.RequestStatusResponse.generateErrorFromException;
-import static java.lang.String.format;
-
-@Component
-@Profile("!cluster")
-public class SingleThreadedDeliveryPipeline implements DeliveryPipeline {
-
- private static final Logger log = Logger.getLogger(SingleThreadedDeliveryPipeline.class);
- private static final String MZS_PIPELINE_ERROR_MSG =
- "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;
- private final SignatureVerifier verifier;
-
- @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;
- this.verifier = verifier;
- }
-
- @Override
- public void processRequest(String appDeliveryId) {
-
- var exceptionBuilder = moaZSExceptionBuilder();
-
- try {
- var mzsRequest = repository.getDeliveryRequest(appDeliveryId).orElseThrow();
- exceptionBuilder.withDeliverySystem(mzsRequest);
-
- at.gv.zustellung.msg.xsd.DeliveryRequestType msgRequest = buildMsgRequest(mzsRequest, exceptionBuilder);
-
- var msgClientParams = mzsRequest.getConfig().getMSGClient();
- App2ZusePort client = clientFactory.create(msgClientParams, App2ZusePort.class);
- var status = client.delivery(msgRequest);
-
- var response = new RequestStatusResponse(status);
- exceptionBuilder.withAllParametersInAnswer(response.getAnswer());
-
- verifySignedStatus(response.getResponseID(), exceptionBuilder);
- repository.add(response);
-
- } catch (MoaZSException exception) {
- log.error(format(MZS_PIPELINE_ERROR_MSG, appDeliveryId), exception);
- var errorResponse = generateErrorFromException(exception);
- repository.add(errorResponse);
- }
- }
-
- private void verifySignedStatus(String appDeliveryId, MoaZSException.Builder exceptionBuilder) throws MoaZSException {
- try {
- var signedStatus = binaryRepository.get(appDeliveryId).get();
- verifier.verify(signedStatus);
- } catch (MoaZSException ex) {
- throw exceptionBuilder.withMessage(format(MsgResponseVerifier.MOASP_SIGNATURE_INVALID_ERROR_MSG, appDeliveryId))
- .withErrorCode(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID)
- .withCause(ex)
- .build();
- }
- }
-
- private at.gv.zustellung.msg.xsd.DeliveryRequestType buildMsgRequest(DeliveryRequestType mzsRequest,
- MoaZSException.Builder exceptionBuilder) throws MoaZSException {
- if (mzsRequest.getConfig().isPerformQueryPersonRequest()) {
- var tnvzClientParams = mzsRequest.getConfig().getTNVZClient();
- TNVZServicePort tvnzPort = clientFactory.create(tnvzClientParams, TNVZServicePort.class);
- var identification = tnvzHelper.performQueryPersonRequest(mzsRequest, tvnzPort, exceptionBuilder);
- return converter.convert(mzsRequest, identification);
- } else {
- return converter.convert(mzsRequest);
- }
- }
-
-}