diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-05-09 15:41:19 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-05-09 16:13:54 +0200 |
commit | f27ff5780d98e747742140c526fb1e3469bb5748 (patch) | |
tree | 3787b02d2f4a4442d745632cc64259dd4954c47f /src/main/java | |
parent | 4aed369467b2c6486de69ac767475fd305e0e068 (diff) | |
download | moa-zs-f27ff5780d98e747742140c526fb1e3469bb5748.tar.gz moa-zs-f27ff5780d98e747742140c526fb1e3469bb5748.tar.bz2 moa-zs-f27ff5780d98e747742140c526fb1e3469bb5748.zip |
Fix: Enable ApacheCXF's Automated Schema Validation
Problem: Apache CXF does not validate incoming mzs:DeliveryRequests
automatically. Per default, validation is off (performs better).
However, (1) we need to validate incoming requests, and (2)
automated CXF validation requires less maintenance and is
expected to be more stable than manual validation.
Solution:
- Add @SchemaValidation annotation to @Service.
- Endpoint Configuration: set WsdlLocation and ServiceName (needed
to prevent parser errors; see [1]).
Without those, CXF validates against generated classes and not
against the WSDL spec, and generated classes do not contain format
restrictions.
Add a testcase with an invalid delivery request ("rejectBothProfile-
AndCorporateBody") to ensure that the validator works.
[1] https://stackoverflow.com/questions/2231779/cxf-and-validation-schema-restrictions-ignored
Diffstat (limited to 'src/main/java')
3 files changed, 14 insertions, 42 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java index d61bafd..090bad3 100644 --- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java @@ -5,9 +5,8 @@ import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.zustellung.app2mzs.xsd.App2MzsPortType; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.DeliveryAnswerType; -import at.gv.zustellung.msg.xsd.DeliveryAnswerType.DeliveryAnswerTypeBuilder; import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; -import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.DeliveryRequestStatusTypeBuilder; +import org.apache.cxf.annotations.SchemaValidation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -17,10 +16,13 @@ import javax.jws.WebParam; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static at.gv.zustellung.msg.xsd.DeliveryAnswerType.deliveryAnswerTypeBuilder; +import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder; import static java.text.MessageFormat.format; import static java.util.concurrent.CompletableFuture.supplyAsync; @Service +@SchemaValidation public class App2MzsService implements App2MzsPortType { private static final Logger logger = LoggerFactory.getLogger(App2MzsService.class); @@ -84,11 +86,11 @@ public class App2MzsService implements App2MzsPortType { private DeliveryRequestStatusType generatePartialSuccessResponse(String appDeliveryId) { - var answer = new DeliveryAnswerTypeBuilder() + var answer = deliveryAnswerTypeBuilder() .withAppDeliveryID(appDeliveryId) .build(); - return new DeliveryRequestStatusTypeBuilder() + return deliveryRequestStatusTypeBuilder() .withPartialSuccess(answer) .build(); } diff --git a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java index 4b62164..5f75750 100644 --- a/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java +++ b/src/main/java/at/gv/egiz/moazs/DeliveryPreprocessor.java @@ -26,50 +26,13 @@ public class DeliveryPreprocessor { */ public DeliveryRequestType preProcess(DeliveryRequestType request) { - validate(request); + //validate(request); return new DeliveryRequestTypeBuilder(request) .withConfig(coalesce(request.getConfig(), initDefaultConfig()).get()) .build(); } - private void validate(DeliveryRequestType request) { - validate(request.getSender()); - - notNull(request.getReceiver(), "Receiver is missing."); - notNull(request.getPayload(), "Payloads are missing."); - notNull(request.getMetaData(), "Metadata is missing."); - notNull(request.getMetaData().getAppDeliveryID(), "AppDeliveryID is missing."); - - } - - private void validate(DeliveryRequestType.Sender sender) { - notNull(sender, "Sender is missing."); - - isTrue(sender.getSenderProfile() != null ^ sender.getCorporateBody() != null , - "Either SenderProfile or CorporateBody (but not both) need to be defined."); - - if(sender.getSenderProfile() != null) - validate(sender.getSenderProfile()); - else - validate(sender.getCorporateBody()); - } - - private void validate(SenderProfile profile) { - notNull(profile.getProfileID(), "ProfileID is missing."); - } - - private void validate(CorporateBodyType body) { - notNull(body.getIdentification(), "Identification is missing."); - notNull(body.getFullName(), "FullName is missing."); - isTrue(body.getIdentification().size() > 0, "No Identification provided."); - isTrue(body.getIdentification().size() <= 1, "Too many means of Identification were provided."); - - var id = body.getIdentification().get(0); - notNull(id.getType(), "Identification Type is missing"); - notNull(id.getValue(), "Identification Value is missing"); - } - private ConfigType initDefaultConfig() { return configTypeBuilder() .withPerformQueryPersonRequest(false) diff --git a/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java b/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java index c4c720d..ab097cb 100644 --- a/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java +++ b/src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java @@ -1,6 +1,7 @@ package at.gv.egiz.moazs.config; import at.gv.egiz.moazs.App2MzsService; +import at.gv.zustellung.app2mzs.xsd.App2Mzs; import org.apache.cxf.Bus; import org.apache.cxf.jaxws.EndpointImpl; import org.springframework.beans.factory.annotation.Autowired; @@ -22,7 +23,13 @@ public class App2MzsServiceConfig { public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(bus, app2mzsService); endpoint.setAddress("/"); + endpoint.setServiceName(app2mzs().getServiceName()); + endpoint.setWsdlLocation("src/main/resources/mzs/app2mzs.wsdl"); endpoint.publish(); return endpoint; } + + @Bean public App2Mzs app2mzs() { + return new App2Mzs(); + } } |