首页 > 解决方案 > SOAP 请求由两个 XSD 模式组成

问题描述

我创建了一个 Spring SOAP 控制器,它成功地在 SOAPUI 中获取我的请求。不幸的是,虽然主 Request 对象是绑定的,但 Request 对象的其余部分却不是。

Request 对象本身在 XSD 中定义,然后 Request 对象中的各种字段由另一个 XSD 定义。我猜它要么是一些 Spring 配置,要么是 XSD 生成的 Java 对象的某种命名空间问题。但是我没有东西可以尝试,已经两天了。

请求 XSD 生成的 Java 对象(PO​​M XJC 创建):

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Request", propOrder = {
"customerInfo"
})
public class Request {

@XmlElement()
protected CustomerInfoType customerInfo;
@XmlAttribute(name = "schemaVersion")
protected String schemaVersion;
}

我可以将任何我想要的东西放入 schemaVersion 中,当我在控制器中调试时,我会看到我在 SOAPUI 中为它放入的任何东西。

CustomerInfoType XSD 生成的 Java 对象(PO​​M XJC 创建):

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CustomerInfoType", propOrder = {
"accountNumber",

})

public class CustomerInfoType {

protected BigInteger accountNumber;
}

Request 在 Request.xsd 中,CustomerInfoType 是 CommonTypes.xsd

这是相对的 Spring Config:

@Bean(name = "RequestyDefinition")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchemaCollection requestSchemaCollection) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("RequestPort");
    wsdl11Definition.setLocationUri("/ws");
    wsdl11Definition.setTargetNamespace("http://services.com/");
    wsdl11Definition.setSchemaCollection(requestSchemaCollection);
    return wsdl11Definition;
}

@Bean
public XsdSchemaCollection requestSchemaCollection(XsdSchema request, XsdSchema commonTypes) {
    return new XsdSchemaCollection() {

        public XsdSchema[] getXsdSchemas() {
            return new XsdSchema[]{request, commonTypes};
        }

        public XmlValidator createValidator() {
            throw new UnsupportedOperationException();
        }
    };
}

@Bean(name = "request")
public XsdSchema requestSchema()
{
    return new SimpleXsdSchema(new ClassPathResource("Request.xsd"));
}

@Bean(name = "commonTypes")
public XsdSchema commonTypesSchema()
{
    return new SimpleXsdSchema(new ClassPathResource("CommonTypes.xsd"));
}

我收到一个 CustomerInfoType 的请求,但请求属性的值为空......

标签: spring-bootsoapmaven-3spring-wsxjc

解决方案


所以我的@PayloadRoot 命名空间是错误的,因为我通常对 SOAP 感到困惑。

wsdl11Definition.setTargetNamespace("http://services.com/");

是正确的,但我在控制器中的命名空间也是这样,它需要是 XSD 的命名空间:services.types.com

因为它是在 SOAPUI 中 SOAP 请求的命名空间中定义的。


推荐阅读