Publish Static WSDLs and Related XSD Schemas Using Spring WS

I have one module where I have XSD schemes, where one scheme can refer to another using the relative path at the location of the scheme:

<xs:import namespace="http://my.namespace.org" schemaLocation="../mypackage/my.xsd"/> 

Here I also use xjc to generate Jaxb beans from these xsd schemas.

Now I have a module where my web service is implemented using spring-ws (2.0.4). And I want to use static WSDL and publish it using xsd schemes, where the scheme locations will be converted to URLs, for example "http://myerver.url.com/my.xsd".

The question is how to elegantly achieve this?

(Alternatively combine XSD in one circuit and in WSDL)

(Theoretically, I could convert these XSDs using a script and add them to resources (xsd and wsdl) in a servlet (spring dispatcher), but this is not very convenient for me)

+6
source share
3 answers

Spring A web service has a way to do this really elegantly. All you have to do is define a SimpleXsdSchema bean with the correct id (which will be used as the xsd name without .xsd) in the bean definition XML file, something like below

 <bean id="my" class="org.springframework.xml.xsd.SimpleXsdSchema"> <property name="xsd" value="/mypackage/my.xsd"> </property> </bean> 

More information (including an example) can be found at the following link: Static WSDL with imported XML schema in Spring web service

+10
source

Below is the JAva configuration to demonstrate the circuit. It worked for me. Note that the schema name must match the name of the Bean name and method. This is very important for this. So I saved the XSD name and Bean name as "CustomerDetailsSchema" and make sure the constructor for getCustomerDetails also matches the name

 @Bean(name = "customerDetails") public DefaultWsdl11Definition getCustomerDetails(XsdSchema CustomerDetailsSchema) { DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); wsdl11Definition.setPortTypeName("..."); wsdl11Definition.setServiceName("..."); wsdl11Definition.setLocationUri("/webservice"); wsdl11Definition.setTargetNamespace("..."); wsdl11Definition.setSchema(CustomerDetailsSchema); return wsdl11Definition; } @Bean(name = "CustomerDetailsSchema") public XsdSchema CustomerDetailsSchema() { return new SimpleXsdSchema(new ClassPathResource("schemas/CustomerDetailsSchema.xsd")); } 
+1
source

Here is my solution for static WSDL and XSD

 @Bean(name = "OpportunityAttachmentService") public Wsdl11Definition getOpportunityAttachmentServiceDefinition() { SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition(); wsdl11Definition.setWsdl( new ClassPathResource( "wsdl/getOpportunityAttachment/BeP_getOpportunityAttachment_cuContract.wsdl")); return wsdl11Definition; } @Bean(name = "getOpportunityAttachment_Request_CRM") public XsdSchema getOpportunityAttachmentServiceRequestXsd() { return new SimpleXsdSchema( new ClassPathResource("wsdl/getOpportunityAttachment/getOpportunityAttachment_Request_CRM.xsd")); } @Bean(name = "getOpportunityAttachment_Response_CRM") public XsdSchema getOpportunityAttachmentServiceResponseXsd() { return new SimpleXsdSchema( new ClassPathResource("wsdl/getOpportunityAttachment/getOpportunityAttachment_Response_CRM.xsd")); } 
0
source

Source: https://habr.com/ru/post/909810/


All Articles