Я настроил свой WebService следующим образом:
applicationContext:
<sws:annotation-driven />
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" >
<property name="interceptors">
<list>
<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
</list>
</property>
Примечание: перехватчик загружается при запуске, но ничего не пишет, если поступает запрос.
У меня есть класс PersonServiceImpl с методом addPersonRequest(). Все работает, если я использую org.dom4j.Element в качестве параметра метода;
@Endpoint
public class PersonServiceImpl {
@PayloadRoot(namespace = "http://www.example.org/person/schema", localPart = "AddPersonRequest")
@ResponsePayload
public AddPersonRequest addPersonRequest(@RequestPayload Element element) {
System.out.println(element.asXML());
Person response = new Person();
response.setId(2);
response.setFirstName("Mad");
response.setLastName("Mike");
return response;
}
}
Но если я изменяю параметры метода, как показано ниже (так что должно использоваться автомаршалинг spring-ws), request.getFirstName() выводит null. (JAXB2 находится в classpath).
Класс Person аннотирован @XMLType и @XMLRootElement.
Примечание: маршалинг работает нормально.
@Endpoint
public class PersonServiceImpl {
@PayloadRoot(namespace = "http://www.example.org/person/schema", localPart = "AddPersonRequest")
@ResponsePayload
public AddPersonRequest addPersonRequest(@RequestPayload Person request, SoapHeader header) {
System.out.println(header.getName());
System.out.println(request.getFirstName());
Person response = new Person();
response.setId(2);
response.setFirstName("Mad");
response.setLastName("Mike");
return response;
}
}
Person.java:
@XmlType
@XmlRootElement(namespace="http://www.example.org/person/schema", name="Person")
public class Person implements Serializable {
private int id;
private String firstName;
private String lastName;
@XmlElement
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@XmlElement
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@XmlAttribute
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Test-Request sent via soapUI (generated from wsdl):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.example.org/person/schema">
<soapenv:Header/>
<soapenv:Body>
<sch:AddPersonRequest>
<sch:Person sch:Id="1">
<sch:FirstName>firstname</sch:FirstName>
<sch:LastName>lastname</sch:LastName>
</sch:Person>
</sch:AddPersonRequest>
</soapenv:Body>
</soapenv:Envelope>