首页 > 解决方案 > 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>

请求有效负载中的值始终为空,我错过了什么?

标签: spring-bootweb-servicessoapendpointcdata

解决方案


推荐阅读