gpt4 book ai didi

java - 具有一个 namespace 和localpart的多个SOAP端点

转载 作者:行者123 更新时间:2023-12-02 02:54:52 25 4
gpt4 key购买 nike

我使用SpringBoot创建了SOAP Web服务服务器,并且能够成功创建一个端点。
但是,我无法创建多个端点并使用不同的URL访问它们。
我想通过URL处理该过程以进行访问。

每个端点接收的SOAP消息具有相同的架构。 (名称空间和localpart相同!!!)
而且我不想公开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>


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>


源代码如下。

@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/*");
}
}


我想访问 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
}
}


我想访问 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
}
}


谢谢。

于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));
}
}


高温超导

关于java - 具有一个 namespace 和localpart的多个SOAP端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57901622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com