Publishing Static WSDL and related XSD schemas using Spring WS
Asked Answered
J

3

9

I have one module where I have my XSD schemas, where one schema can reference an other using relative path within schema location:

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

Here I'm also using xjc to generate Jaxb beans from these xsd schemas.

Now I have a module where is my web-service is implemetented, using spring-ws (2.0.4). And I want to use static WSDL and publish it with the xsd schemas, where the schema locations will be transformed to URL like 'http://myerver.url.com/my.xsd'.

The question is how to elegantly achieve this?

(Alternatively combine the XSDs into one schema and that to WSDL)

(In theory I could transform these XSD using a script and add them to resources (xsd and wsdl) to a (spring dispatcher) servlet but it doesn't seems to me very comfortable)

Jael answered 2/3, 2012 at 9:52 Comment(3)
Quick comment... you won't be able to combine the XSDs into one since you're using an &lt;xs:import/> statement; you can only have one target namespace per XSD file. You could, however, inline all XSDs, no matter namespaces, under the wsdl:types section - in which case all your imports should drop the schemaLocation attributes. More later...Parotic
Hi, what I dont want to do is this manual inlineing . So this solution is if it could be done without much trouble, like using a general lib that does it to me.Jael
Finally solved it by an own servlet implementation.Jael
B
12

Spring web service has a way to do it elegantly actually. All you need to do is to define a SimpleXsdSchema bean with the right 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

Botnick answered 3/10, 2012 at 2:15 Comment(0)
D
6

Here is my solution for static WSDL and XSDs

@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"));
}
Duotone answered 12/7, 2019 at 11:18 Comment(1)
It works, but is there a possiblity to use XsdSchemaCollection to publish all XSDs once?Angy
P
2

Below is the Java config for exposing the schema. This worked for me. Please note that the schema name should match the Bean name and method name. This is very key for this to work. So I kept 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"));
}
Pinnatiped answered 10/3, 2017 at 17:41 Comment(1)
This uses a dynamically generated wsdl rather than a static wsdl as in the question.Selectman

© 2022 - 2024 — McMap. All rights reserved.