From 9a038cf18d6ebd4c68218c20ebc174b779afa7fa Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Mon, 29 Apr 2019 14:28:48 +0200 Subject: Make JAXB Objects Immutable and Add Builder Utility - Use Immutable-XJC from https://github.com/sabomichal/immutable-xjc - Update existing JAXB-object manipulations to use the Builder - Remove jaxbMarshallerTest (as it relies on mutable JAXB interfaces) Reason for making JAXB objects immutable: I put JAXB objects in the repository. Depending on the configuration, the repository can be a simple hashmap; in that case I might end up sharing JAXB objects between threads. Immutable shared object should make life a little simpler. --- src/main/java/at/gv/egiz/moazs/App2MzsService.java | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java index 8626c24..66ab795 100644 --- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java @@ -1,9 +1,16 @@ package at.gv.egiz.moazs; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryAnswerType; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryAnswerType.DeliveryAnswerTypeBuilder; import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType.DeliveryRequestStatusTypeBuilder; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType.Error.ErrorBuilder; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ErrorInfoType; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ErrorInfoType.ErrorInfoTypeBuilder; import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory; import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs.App2MzsPortType; import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType.DeliveryRequestTypeBuilder; import at.gv.egiz.moazs.pipeline.DeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; import org.slf4j.Logger; @@ -66,32 +73,30 @@ public class App2MzsService implements App2MzsPortType { private DeliveryRequestStatusType generatePartialSuccessResponse(String appDeliveryId, String message) { - var partialSuccess = objectFactory.createDeliveryAnswerType(); - partialSuccess.setAppDeliveryID(appDeliveryId); + var answer = new DeliveryAnswerTypeBuilder() + .withAppDeliveryID(appDeliveryId) + .build(); - var response = objectFactory.createDeliveryRequestStatusType(); - response.setPartialSuccess(partialSuccess); - - response.setSignature(null); - - return response; + return new DeliveryRequestStatusTypeBuilder() + .withPartialSuccess(answer) + .build(); } private DeliveryRequestStatusType generateErrorResponse(String appDeliveryId, String message) { - var error = objectFactory.createDeliveryRequestStatusTypeError(); - error.setAppDeliveryID(appDeliveryId); - - var info = objectFactory.createErrorInfoType(); - info.setCode("500"); - info.setText(message); - error.setErrorInfo(info); + var info = new ErrorInfoTypeBuilder() + .withCode("500") + .withText(message) + .build(); - var response = objectFactory.createDeliveryRequestStatusType(); - response.setError(error); - response.setSignature(null); + var error = new ErrorBuilder() + .withAppDeliveryID(appDeliveryId) + .withErrorInfo(info) + .build(); - return response; + return new DeliveryRequestStatusTypeBuilder() + .withError(error) + .build(); } private DeliveryRequestStatusType process(DeliveryRequestType deliveryRequest) throws RuntimeException { -- cgit v1.2.3