0
我想創建一個帶兩個端點的Spring Boot ws應用程序,但我需要一個啓用了MTOM(對於較新的客戶端),另一個禁用MTOM(適用於較老的客戶)。 這兩個端點應該以任何其他方式相同。Spring引導ws:2個端點,其中一個啓用了MTOM,一個禁用了MTOM
請告訴我,如果這是可能的,如果是的話,給我任何提示如何做到這一點。
在此先感謝
我想創建一個帶兩個端點的Spring Boot ws應用程序,但我需要一個啓用了MTOM(對於較新的客戶端),另一個禁用MTOM(適用於較老的客戶)。 這兩個端點應該以任何其他方式相同。Spring引導ws:2個端點,其中一個啓用了MTOM,一個禁用了MTOM
請告訴我,如果這是可能的,如果是的話,給我任何提示如何做到這一點。
在此先感謝
爲此,您可以簡單地複製你的模式和端點使用下面的配置(僅命名空間應該有所不同)。唯一的限制是,這兩個端點共享同一個URI(主機 /ws/NotMtomServices.wsdl和主機 /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"));
}
}