abderrahim_05
abderrahim_05

Reputation: 465

How to use a custom marshaller in spring WS

I created a SOAP Webservice using spring-ws.

Here is my config Class :

@EnableWs
@Configuration
public class EmutationSOAPConfig extends WsConfigurerAdapter {

    @Autowired
    LoggingInterceptor loggingInterceptor;

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }

    @Bean(name="emutationService")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/emutation-fc1.wsdl"));
        return wsdl11Definition;
    }
// ....
}

And here is my EndPoint class :


@Endpoint
public class EmutationServiceEndpoint {
    
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "ConsultationFibres" )
    @ResponsePayload
    public ConsultationFibresResponse consultationFibres(@RequestPayload ConsultationFibres request) throws SoapFaultClientException, EmutationDefaultFaultMessage, EmutationTechnicalFaultMessage {
        ObjectFactory factory = new ObjectFactory();
        ConsultationFibresResponse response =factory.createConsultationFibresResponse();
        // ....
        return response;
    }


}

the types ConsultationFibresResponse and ConsultationFibres were generated from a WSDL that cannot be changed. here is the WSDL part that describe ConsultationFibres :

             <xsd:element name="ConsultationFibres">
                <xsd:complexType>
                    <xsd:sequence>
                        <!-- .... -->
                        <xsd:element minOccurs="0" name="offset" type="xsd:int"/>
                        <xsd:element minOccurs="0" name="limit" type="xsd:int"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

the problem is that the elements offset and limit are unmarshalled as 0 when they are empty in xml SOAP request :

    <ns2:offset></ns2:offset>
    <ns2:limit></ns2:limit>

i want them to be null instead without modifying the WSDL or the generated classes.

I want to use the javax.xml.bind.annotation.adapters.XmlAdapter to define how to define how to convert string to integer.

but i don't know how to override the marshaller/unlarshaller used by spring.

please help me.

Upvotes: 2

Views: 610

Answers (0)

Related Questions