ivoruJavaBoy
ivoruJavaBoy

Reputation: 1357

Spring 4, SOAP WS, XSD... Producing two different WSDL

second time I'm trying to ask this without any answer, though i don't think this should be an hard question for a good Spring developer..

I want to create a simple Spring 4 (Annotation driven) Application, this will use the maven-jaxb-plugin to generate every request response object factory and object mapping classes...

I want this application to produce 2 WSDL, so as my assumption, i started from two different XSD, and with two different SPRING WsConfigurerAdapter classes that configure both WSDL, and obviously, two different classes to manage Endpoints..

Everything work... But my question is:

I ve a bean shared between the two WSDL, and consequently between the two XSD, how to accomplish this? XSD and Maven Plugin side, everything keep working as well if i declare a complex type inside an XSD and than import or include it into the second one, but SPRING 4 side, when i just add the import and the bean, the WSDL with the import has not been resolved, something like unexpected end of file, it's obvious that i'm missing or making something wrong... but what?

The first XSD where the shared entity is declared..

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:usr="http://concretepage.com/soap/userManagement" targetNamespace="http://concretepage.com/soap/userManagement">

    <xs:element name="getUserRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="userId" type="xs:int" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="getUserResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="user" type="usr:user" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>  

    <!-- share bean -->
    <xs:complexType name="user">
        <xs:sequence>
            <xs:element name="userId" type="xs:int" />
            <xs:element name="userName" type="xs:string" />
            <xs:element name="age" type="xs:int" />
            <xs:element name="password" type="xs:string" />
            <xs:element name="passwordffd" type="xs:string" />
        </xs:sequence>
    </xs:complexType>

</xs:schema>

The second XSD, now the import is commented and everything works like this, but without the element User injected into the Job, if i enable it with the import, the jobManagement WSDL SOAP-UI load fails:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://concretepage.com/soap/jobManagement" targetNamespace="http://concretepage.com/soap/jobManagement"
    xmlns:usr="http://concretepage.com/soap/userManagement">
    <!-- import -->
    <!-- xs:import schemaLocation="userManagement.xsd"
        namespace="http://concretepage.com/soap/userManagement" / -->

    <xs:element name="getJobRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="jobId" type="xs:int" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="getJobResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="job" type="tns:job" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="job">
        <xs:sequence>
            <xs:element name="jobId" type="xs:int" />
            <xs:element name="jobName" type="xs:string" />
            <xs:element name="jobRole" type="xs:string" />
            <xs:element name="salary" type="xs:int" />
            **<!--  xs:element name="user" type="usr:user" /-->**
        </xs:sequence>
    </xs:complexType>
</xs:schema>

This is the Spring class to generate the WSDL that has the shared bean:

@Configuration
@EnableWs
@ComponentScan("com.concretepage")
public class JobConfig extends WsConfigurerAdapter {

    @Bean(name = "jobManagement")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema jobSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("jobManagementPort");
        wsdl11Definition.setLocationUri("/soapws/jobManagement/");
        wsdl11Definition.setTargetNamespace("http://localhost:8080/spring4soap/");
        wsdl11Definition.setSchema(jobSchema);

        return wsdl11Definition;
    }

    @Bean
    public XsdSchema jobSchema() {
        return new SimpleXsdSchema(new ClassPathResource("jobManagement.xsd"));
    }
}

Upvotes: 2

Views: 2289

Answers (1)

Kai
Kai

Reputation: 41

Okay, replace

wsdl11Definition.setSchema(jobSchema); 

by

wsdl11Definition.setSchemaCollection(mySchemaCollection());

Build your collection:

@Bean
public XsdSchemaCollection quotesSchemaCollection() {
    return new XsdSchemaCollection() {

        public XsdSchema[] getXsdSchemas() {
            return new XsdSchema[]{new SimpleXsdSchema(new ClassPathResource("a.xsd")), new SimpleXsdSchema(new ClassPathResource("b.xsd"))};
        }

        public XmlValidator createValidator() {
            throw new UnsupportedOperationException();
        }
    };
}

Source: Spring Doc -> spring.io

Upvotes: 1

Related Questions