spring-boot - Spring Endpoint - 从soap请求中获取CDATA内容
问题描述
我是网络服务的新手。
从我得到的文档中,我应该创建 SpringWeb 服务端点,它需要使用 CDATA 中的内容来使用有效负载:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:res="http://xxx/result">
<soapenv:Header/>
<soapenv:Body>
<res:ResultMsg>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<result xmlns="http://xxx/result">
<Param1>1</Param1>
<Param2>2</Param2>
</result>
</xml>]]>
</res:ResultMsg>
</soapenv:Body>
</soapenv:Envelope>
我生成了 Result 对象。我的端点看起来:
@Endpoint
@RequiredArgsConstructor
@Slf4j
public class ResultEndpoint {
private static final String NAMESPACE_URI = "http://xxx/result";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "ResultMsg")
public void resultReceived(@RequestPayload Result result) {
log.info("Web Service result", result);
}
}
WebServiceConfig 看起来:
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/endpoint");
}
@Bean(name = "result")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema resultSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("PortName"); //Not sure if its ok
wsdl11Definition.setLocationUri("/ws/endpoint");
wsdl11Definition.setTargetNamespace("http://xxx/result");
wsdl11Definition.setSchema(resultSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("path_to_xsd.xsd"));
}
}
XSD架构也是:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:res="http://xxx/result" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://api-v1.gen.mm.vodafone.com/mminterface/result" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="Result">
<xs:sequence>
<xs:element name="Param1" type="xs:integer" minOccurs="0" nillable="true">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Param2">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="result" type="res:Result"></xs:element>
</xs:schema>
请求有效负载中的值始终为空,我错过了什么?
解决方案
推荐阅读
- php - 如何在 Datatable 中搜索具有多条记录的“子”数据?
- python - python中从web到sqlite的返回值问题
- ios - 如何通过在 iOS12 的应用程序中设置来调用屏幕时间
- python - 如何使用 django 将会话存储存储到 redis?
- java - 约束布局未正确显示
- python - 如何在 Python 的并行进程中运行 2 个 while 循环
- java - 如何在 Geonetwork 中更改 Z39.50 端口以修复错误“地址已在使用中”?
- java - 创建可执行jar时,如何引用本地文件并将其包含在我的maven程序集中?
- oracle - 防止在远程数据库中插入重复项
- express - 在loopback4中表现得像response.redirect的代码?