From f27ff5780d98e747742140c526fb1e3469bb5748 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 9 May 2019 15:41:19 +0200 Subject: 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 --- src/main/java/at/gv/egiz/moazs/config/App2MzsServiceConfig.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/java/at/gv/egiz/moazs/config') 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(); + } } -- cgit v1.2.3