fsk*_*304 6 java spring soap web-services spring-boot
我使用 SpringBoot 创建了一个 SOAP Web 服务服务器,并且能够成功创建一个端点。但是,我无法创建多个端点并使用不同的 URL 访问它们。我想通过 URL 处理该过程以进行访问。
每个端点接收到的 SOAP 消息具有相同的模式。(命名空间和本地部分是相同的!!!)而且我不想公开 WSDL。
例如。
userA 将以下 SOAP 消息发送到以下 URL:http : //soap.example.com/ws/userA
<S:Envelope>
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<S:Body>
<testsoap:post
xmlns:testsoap="http://soap.example.com/">
<testsoap:message>
I am UserA
</testsoap:message>
</testsoap:post>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
userB 将以下 SOAP 消息发送到 URL:http : //soap.example.com/ws/userB
<S:Envelope>
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<S:Body>
<testsoap:post
xmlns:testsoap="http://soap.example.com/">
<testsoap:message>
I am UserB
</testsoap:message>
</testsoap:post>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
源代码如下。
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Autowired
CustomConfig customConfig;
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*");
}
}
Run Code Online (Sandbox Code Playgroud)
我想访问http://soap.example.com/ws/userA
@Endpoint
public class SoapRequestEndpoint {
private static final String NAMESPACE_URI = "http://soap.example.com/";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "post")
@ResponsePayload
public JAXBElement<PostResponse> postForA(MessageContext messageContext) {
// do something for userA
}
}
Run Code Online (Sandbox Code Playgroud)
我想访问http://soap.example.com/ws/userB
@Endpoint
public class SoapRequestEndpoint {
private static final String NAMESPACE_URI = "http://soap.example.com/";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "post")
@ResponsePayload
public JAXBElement<PostResponse> postForB(MessageContext messageContext) {
// do something for userB
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢。
2019年9月24日更新,
从那以后我一直在努力,但我还是不明白。我不认为它写在官方参考中。你有什么想法?
2019年10月3日更新
我还没解决。如果是这种情况,将很难工作。请帮助某人。
尝试在 WebServiceConfig 类中创建一个附加的 Wsdl11Definition 方法,并使用 @Bean(name = "UserB") 注释该方法。
您只显示了 WebServiceConfig 类中的一个片段,我假设该类中不存在该片段。
你的类应该类似于这样:
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Autowired
CustomConfig customConfig;
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*");
}
}
@Bean(name = "userA")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema [randomMethodSchema]) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("userAPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://soap.example.com/");
wsdl11Definition.setSchema([randomMethodSchema]);
return wsdl11Definition;
}
@Bean(name = "userB")
public DefaultWsdl11Definition defaultWsdl11Definition2(XsdSchema [randomMethodSchema]) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("userBPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://soap.example.com/");
wsdl11Definition.setSchema([randomMethodSchema]);
return wsdl11Definition;
}
@Bean
public XsdSchema [randomMethodSchema]() {
return new SimpleXsdSchema(new ClassPathResource([schema name].xsd));
}
}
Run Code Online (Sandbox Code Playgroud)
华泰
| 归档时间: |
|
| 查看次数: |
3500 次 |
| 最近记录: |