空格修剪在 SOAP 请求中不起作用

Trimming of spaces does not work in SOAP request

wsdl 是自上而下实现的。 java 类 是使用 cxf-codegen-plugin.

生成的

它有一个定义为

的简单类型
<xsd:simpleType name="DescriptionType">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="512" />
        <xsd:minLength value="1"/>
        <xsd:whiteSpace value="collapse"/>
    </xsd:restriction>
</xsd:simpleType>

我试图将 " description" 放入请求中,但它没有 trim space。 “折叠”选项应该可以做到这一点。

这是 wsdl:

<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions name="foo"
    xmlns="http://xmlns.ec.eu/DataService/foo/V2.2"
    targetNamespace="http://xmlns.ec.eu/DataService/foo/V2.2"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
>
    <wsdl:import namespace="http://xmlns.ec.eu/DataService/foo/V2.2"
        location="fooAbstract.wsdl">
    </wsdl:import>

    <wsdl:binding name="fooSoapBinding" type="foo">
    
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        
        <wsdl:operation name="Insert">
            <soap:operation soapAction="urn:foo1Insert" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
            <wsdl:fault name="ServiceFault">
                <soap:fault name="ServiceFault" use="literal" />
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="foo">
        <wsdl:port name="foo" binding="fooSoapBinding">
            <soap:address location="http://xmlns.ec.eu/DataService/foo/V2" />
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

这是服务实现:

@Stateless
@WebService(portName = "foo",
        serviceName = "foo",
        targetNamespace = "http://xmlns.ec.eu/DataService/foo/V2.2",
        wsdlLocation = "/META-INF/resources/wsdl/DataService/foo/V2.2/fooConcrete.wsdl",
        endpointInterface = "foo.package")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@SchemaValidation(inbound = true, outbound = false, handler = SchemaValidationHandler.class)
@HandlerChain(file = "../../../../../../../META-INF/handler-chain.xml")
@DeclareRoles({READ_ROLE, WRITE_ROLE})
public class FooService implements Foo {

改用 xs:token 类型,确实有效。

它会自动删除空格并生成以下注释:

@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "token")

https://www.w3schools.com/XML/schema_dtypes_string.asp

https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/adapters/CollapsedStringAdapter.html