Lod*_*ger 8 spring web-services spring-ws
我已经像这样配置了我的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>
Run Code Online (Sandbox Code Playgroud)
注意:Interceptor在启动时加载,但是如果请求进来,则不会写任何内容.
我有一个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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改我的方法参数,如下所示(因此应该使用spring-ws的自动编组),request.getFirstName()将打印null.(JAXB2在类路径上).
Person-class使用@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;
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
通过soapUI发送的测试请求(从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>
Run Code Online (Sandbox Code Playgroud)
你提到编组正在工作,我不明白为什么解组不起作用,你是否单独测试过编组和解组?
只是为了确保肥皂请求是好的,您可以添加日志拦截器并打印来自访问 Web 服务的客户端的实际请求,将此代码段添加到您的上下文文件中
<sws:interceptors>
<bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor">
<property name="logRequest" value="true"></property>
<property name="logResponse" value="true"></property>
</bean>
</sws:interceptors>
Run Code Online (Sandbox Code Playgroud)
您应该看到这样的日志消息,其中包含整个肥皂请求,我正在将来自 saop UI 的日志消息请求添加到
DEBUG [http-8080-2]:endpoint.interceptor.SoapEnvelopeLoggingInterceptor.logMessage - Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://hoost:port/context/patient/schemas">
<soapenv:Header/>
<soapenv:Body>
<sch:addRequest>
<sch:patient>
<sch:id>?</sch:id>
<sch:lastname>Joe</sch:lastname>
</sch:patient>
</sch:addRequest>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
答案更新
可能是你的肥皂要求,但不确定
<sch:FirstName>firstname</sch:FirstName> (this should be)
<sch:firstName>firstname</sch:firstName>
Run Code Online (Sandbox Code Playgroud)
另一个更新
例外是由于您定义端点的方式造成的,在您的soap请求(sch:AddPersonRequest)中,您发送的是addPersonRequest而不是Person作为有效负载,因此更改端点以反映这一点,@RequestPayload应该是AddPersonRequest而不是Person
@PayloadRoot(namespace = "http://www.example.org/person/schema", localPart = "AddPersonRequest")
@ResponsePayload
public AddPersonRequest addPersonRequest(@RequestPayload AddPersonRequest request, SoapHeader header) {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10748 次 |
| 最近记录: |