1 year ago

#306192

test-img

Mark116

Spring WS hide soap 1.1 and force name of bingind element

I must prepare a webservice to accept anan already defined wsdl structure. I followed the tutorial found here, with source code for the test project downloadable here.

This is my configuration class:

@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setTransformWsdlLocations(true);
    return new ServletRegistrationBean<>(servlet, "/MY-WS/*");
}

@Bean(name = "xxx")
public CustomWsdl11Definition defaultWsdl11Definition(XsdSchema mySchema) {
    CustomWsdl11Definition wsdl11Definition = new CustomWsdl11Definition();
    wsdl11Definition.setPortTypeName("xxx");
    wsdl11Definition.setServiceName("xxx");
    wsdl11Definition.setLocationUri("/MY-WS");
    wsdl11Definition.setCreateSoap12Binding(true);
    wsdl11Definition.setRequestSuffix("");
    wsdl11Definition.setTargetNamespace(Constants.WS_NAMESPACE);
    wsdl11Definition.setSchema(mySchema);
    return wsdl11Definition;
}

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

@Bean
public SaajSoapMessageFactory messageFactory() {
    SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
    messageFactory.setSoapVersion(SoapVersion.SOAP_12);
    return messageFactory;
}

And this is my WSDL:

/**/
<wsdl:binding name="xxxSoap11" type="tns:xxx">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="NotifyUpdateLimits">
        <soap:operation soapAction=""/>
        <wsdl:input name="NotifyUpdateLimits">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="NotifyUpdateLimitsResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="CheckStatus">
        <soap:operation soapAction=""/>
        <wsdl:input name="CheckStatus">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="CheckStatusResponse">
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:binding name="xxxSoap12" type="tns:xxx">
    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="NotifyUpdateLimits">
        <soap12:operation soapAction=""/>
        <wsdl:input name="NotifyUpdateLimits">
            <soap12:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="NotifyUpdateLimitsResponse">
            <soap12:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="CheckStatus">
        <soap12:operation soapAction=""/>
        <wsdl:input name="CheckStatus">
            <soap12:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="CheckStatusResponse">
            <soap12:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="xxx">
    <wsdl:port binding="tns:xxxSoap12" name="xxxSoap12">
        <soap12:address location="http://localhost:8080/MY-WS"/>
    </wsdl:port>
    <wsdl:port binding="tns:xxxSoap11" name="xxxSoap11">
        <soap:address location="http://localhost:8080/MY-WS"/>
    </wsdl:port>
</wsdl:service>

</wsdl:definitions>

I just have to exhibit SOAP 1.2 protocol, how can I hide the first one? Later, I need to force the name of binding element (<wsdl:binding name="xxxSoap12" type="tns:xxx">) and the name of port in service (<wsdl:port binding="tns:xxxSoap12" name="xxxSoap12">), it is possible?

EDIT: Follow M. Deinum's advice, I've changed my configuration class:

@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setTransformWsdlLocations(true);
    return new ServletRegistrationBean<>(servlet, "/MY-WS/*");
}

@Bean(name = "xxx")
public Wsdl11Definition defaultWsdl11Definition() {
    SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
    wsdl11Definition.setWsdl(new ClassPathResource("MyServiceWS.xml"));
    return wsdl11Definition;
}

Now, I've this error while calling: Cannot create message: incorrect content-type for SOAP version. Got: application/soap+xml; charset=UTF-8 Expected: text/xml

Maybe it's using soap 1.1 instead of 1.2?

java

spring

wsdl

spring-ws

0 Answers

Your Answer

Accepted video resources