我已经创建了一个Spring SOAP Controller,它在SOAPUI中成功获取了我的请求。不幸的是,虽然主要的Request对象是绑定,但Request属性的其余部分却没有。
Request对象本身在XSD中定义,然后Request对象中的各个字段由另一个XSD定义。我猜它是一些Spring配置或者是由XSD生成的Java对象的某种命名空间问题。但是我没有尝试过,而且已经有两天了。
请求XSD生成Java对象(POM 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对象(POM XJC Creation):
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CustomerInfoType", propOrder = {
"accountNumber",
})
public class CustomerInfoType {
protected BigInteger accountNumber;
}
请求位于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获取一个null请求,但是Request属性的值为....
所以我的@PayloadRoot命名空间是错误的,因为我通常对SOAP感到困惑。
wsdl11Definition.setTargetNamespace("http://services.com/");
是正确的,但我在控制器中的名称空间也是如此,它需要是XSD的名称空间:services.types.com
因为它是在SOAPUI中SOAP请求的命名空间中定义的。