diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-06-19 13:19:21 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-06-19 13:19:21 +0200 |
commit | 6044145569bdc0e86d2c1831fa50051227822864 (patch) | |
tree | 8fd7c020c7bf5826a4a78f3edd2ee67f5cbf946e /src/main/java/at/gv/egiz/moazs/pipeline | |
parent | a867ca9950c6bf670407b366ee2980eb747358f2 (diff) | |
download | moa-zs-6044145569bdc0e86d2c1831fa50051227822864.tar.gz moa-zs-6044145569bdc0e86d2c1831fa50051227822864.tar.bz2 moa-zs-6044145569bdc0e86d2c1831fa50051227822864.zip |
Refactor DeliveryPipeline
- Resolve nested try-catch blocks
- Log error if error occurs
- MoaSPSSSignatureVerifier: Replace string concatenation with format strings
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/pipeline')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java b/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java index 920e90d..f264e52 100644 --- a/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java +++ b/src/main/java/at/gv/egiz/moazs/pipeline/SameThreadDeliveryPipeline.java @@ -14,6 +14,7 @@ import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.DeliveryAnswerType; import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; import at.gv.zustellung.tnvz.xsd.PersonResultType; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -23,11 +24,14 @@ 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; import static at.gv.zustellung.msg.xsd.ErrorInfoType.errorInfoTypeBuilder; +import static java.lang.String.format; @Component @Profile("!cluster") public class SameThreadDeliveryPipeline implements DeliveryPipeline { + private static final Logger log = Logger.getLogger(SameThreadDeliveryPipeline.class); + private final DeliveryRepository repository; private final TnvzClient tnvzClient; private final TnvzResultVerifier tnvzVerifier; @@ -57,46 +61,56 @@ public class SameThreadDeliveryPipeline implements DeliveryPipeline { @Override public void processRequest(String appDeliveryId) { - DeliveryRequestType mzsRequest; - PersonResultType tnvzResult = null; - at.gv.zustellung.msg.xsd.DeliveryRequestType msgRequest; - DeliveryRequestStatusType status; + var exceptionBuilder = moaZSExceptionBuilder(""); try { - mzsRequest = repository.getDeliveryRequest(appDeliveryId).orElseThrow(); + var mzsRequest = repository.getDeliveryRequest(appDeliveryId).orElseThrow(); + exceptionBuilder.withMzsRequest(mzsRequest); + + at.gv.zustellung.msg.xsd.DeliveryRequestType msgRequest; if (mzsRequest.getConfig().isPerformQueryPersonRequest()) { - tnvzResult = performTnvzQuery(mzsRequest); + var tnvzResult = performTnvzQuery(mzsRequest); + exceptionBuilder.withTnvzResult(tnvzResult); + msgRequest = converter.convert(mzsRequest, tnvzResult.getSuccess().getIdentification()); } else { msgRequest = converter.convert(mzsRequest); } - status = msgClientFactory.create(msgRequest, mzsRequest.getConfig(), interceptor).send(); + exceptionBuilder.withMsgRequest(msgRequest); - var signedStatus = repository.getSignedDeliveryRequestStatus(appDeliveryId).get(); + var status = msgClientFactory.create(msgRequest, mzsRequest.getConfig(), interceptor).send(); + exceptionBuilder.withMsgResult(status); - try { - verifier.verify(signedStatus); - } catch (Exception ex) { - throw moaZSExceptionBuilder("Signature of DeliveryRequestStatus with AppDeliveryId={} " + - " is not valid.", appDeliveryId) - .withErrorCode(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID) - .withMzsRequest(mzsRequest) - .withTnvzResult(tnvzResult) - .withMsgRequest(msgRequest) - .withMsgResult(status) - .build(); - } + verifyStatus(appDeliveryId, exceptionBuilder); repository.add(status); } catch (MoaZSException exception) { + + log.error(format("An error occured while processing the DeliveryRequest with AppDeliveryID = %s. ", + appDeliveryId), exception); + var errorStatus = generateErrorStatus(exception, appDeliveryId); repository.add(errorStatus); } } + private void verifyStatus(String appDeliveryId, MoaZSException.Builder exceptionBuilder) throws MoaZSException { + + try { + var signedStatus = repository.getSignedDeliveryRequestStatus(appDeliveryId).get(); + verifier.verify(signedStatus); + } catch (Exception ex) { + throw exceptionBuilder.withMessage(format("Signature of DeliveryRequestStatus with AppDeliveryId={} " + + " is not valid.", appDeliveryId)) + .withErrorCode(MoaZSException.ERROR_MOASP_SIGNATURE_INVALID) + .withCause(ex) + .build(); + } + } + private PersonResultType performTnvzQuery(DeliveryRequestType request) { var result = tnvzClient.query(request.getSender(), request.getReceiver()); tnvzVerifier.verify(request, result); |