我正在为较大的项目设置SOAP服务器。 我收到了一个wsdl文件,该文件仅指定xsd:any字段,而没有指定可以接收的对象类型。
为简化我的问题,我已更改了一个简单的helloworld应用程序。它与我正在使用的更复杂的服务器具有相同的错误: “ 1个IllegalAnnotationExceptions计数”
因此,在这里我创建了一个简单的wsdl文件,其中显示了具有字段的Person对象: - 名字 - 姓 -任何
任何人都可以,例如动物。
<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstName" type="xsd:string" />
<xsd:element name="lastName" type="xsd:string" />
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
我让jaxb生成类。 由于xsd:any对象可能是动物,所以我创建了动物类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"name" })
@XmlRootElement(name = "animal")
public class Animal
{
@XmlElement(name = "name")
protected String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
并且我已经将动物添加到了ObjectFactory:
@XmlElementDecl(name = "animal")
public Animal createAnimal()
{
return new Animal();
}
我的端点应该记录任何对象的类:
@Endpoint
public class HelloWorldEndpoint
{
private static final Logger LOGGER = LogManager.getLogger(HelloWorldEndpoint.class);
@PayloadRoot(namespace = "http://codenotfound.com/types/helloworld", localPart = "person")
@ResponsePayload
public Greeting sayHello(@RequestPayload Person request)
{
LOGGER.info("Endpoint received person[firstName={},lastName={}]", request.getFirstName(), request.getLastName());
LOGGER.info("Any Class = {} ", request.getAny().getClass());
//do stuff
return response
}
}
最后,我通过soapUI发送的肥皂消息:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://codenotfound.com/types/helloworld">
<soapenv:Header/>
<soapenv:Body>
<hel:person>
<hel:firstName>John</hel:firstName>
<hel:lastName>Doe</hel:lastName>
<animal>
<name>Elefant</name>
</animal>
</hel:person>
</soapenv:Body>
</soapenv:Envelope>