简体   繁体   中英

Spring boot ws: 2 endpoints, one with MTOM enabled, one with MTOM disabled

I'd like to create a Spring Boot ws application with two endpoints, but I need one with MTOM enabled (for newer clients) and the other with MTOM disabled (for older clients). The two endpoints should be the same in any other way.

Please, tell me if this is possible, and if yes, give me any hints how to do it.

Thanks in advance

You can do this simply duplicating your schema and endpoint (only the namespace should differ) using the configuration below. The only limitations are that the two endpoints share the same uri ( host /ws/NotMtomServices.wsdl and host /ws/MtomServices.wsdl)

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurationSupport {

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

    @Bean(name = "NotMtomServices")
    public DefaultWsdl11Definition defaultWsdl11DefinitionILServices(XsdSchema notMtomServicesSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("ILPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace(NotMtomServices.NAMESPACE_URI);
        wsdl11Definition.setSchema(notMtomServicesSchema);
        return wsdl11Definition;
    }

    @Bean(name = "MtomServices")
    public DefaultWsdl11Definition defaultWsdl11DefinitionILServicesMTOM(XsdSchema mtomServicesSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("ILPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace(MtomServices.NAMESPACE_URI);
        wsdl11Definition.setSchema(mtomServicesSchema);
        return wsdl11Definition;
    }

    @Bean
    @Override
    public DefaultMethodEndpointAdapter defaultMethodEndpointAdapter() {
        List<MethodArgumentResolver> argumentResolvers = new ArrayList<MethodArgumentResolver>();
        argumentResolvers.addAll(methodProcessors());

        List<MethodReturnValueHandler> returnValueHandlers = new ArrayList<MethodReturnValueHandler>();
        returnValueHandlers.addAll(methodProcessors());

        DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
        adapter.setMethodArgumentResolvers(argumentResolvers);
        adapter.setMethodReturnValueHandlers(returnValueHandlers);

        return adapter;
    }

    @Bean
    public List<MarshallingPayloadMethodProcessor> methodProcessors() {
        List<MarshallingPayloadMethodProcessor> retVal = new ArrayList<MarshallingPayloadMethodProcessor>();
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath(NotMtomServices.NAMESPACE_URI);
        marshaller.setMtomEnabled(false);
        retVal.add(new MarshallingPayloadMethodProcessor(marshaller));

        Jaxb2Marshaller marshallerMTOM = new Jaxb2Marshaller();
        marshallerMTOM.setContextPath(MtomServices.NAMESPACE_URI);
        marshallerMTOM.setMtomEnabled(true);
        retVal.add(new MarshallingPayloadMethodProcessor(marshallerMTOM));

        return retVal;
    }

    @Bean(name="notMtomServicesSchema")
    public XsdSchema ServicesSchema() {
        return new SimpleXsdSchema(new ClassPathResource("not_mtom_services.xsd"));
    }

    @Bean(name="mtomServicesSchema")
    public XsdSchema ServicesSchemaMTOM() {
        return new SimpleXsdSchema(new ClassPathResource("mtom_services.xsd"));
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM