java - Spring-WS 请求输入即将为空
问题描述
我正在使用 Spring WS 来生成 SOAP Web 服务。我的输入请求即将为空,请帮助我解决问题,因为试图找出问题已经被打击了几个小时。下面是我的代码的快照
wsdl:(子集)
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
targetNamespace="http://v4_0.webservice.commonuser.u90.org.com" xmlns:impl="http://v4_0.webservice.commonuser.u90.org.com" xmlns:intf="http://v4_0.webservice.commonuser.u90.org.com" xmlns:tns3="http://beans.v4_0.webservice.commonuser.u90.org.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://beans.v4_0.webservice.gsec.commonuser.u90.org.com">
<complexType name="User">
<sequence>
<element name="userId" nillable="true" type="xsd:string"/>
<element name="userType" nillable="true" type="xsd:string"/>
<element name="firstName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="GetPersonByUserIdIP">
<complexContent>
<extension base="tns3:AttributeRequest">
<sequence>
<element name="userId" nillable="true" type="xsd:string"/>
<element name="userType" nillable="true" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="GetPersonByUserIdOP">
<sequence>
<element name="user" nillable="true" type="tns3:User"/>
</sequence>
</complexType>
<element name="getPersonByUserId">
<complexType>
<sequence>
<element name="getPersonByUserIdIP" nillable="true" type="tns3:GetPersonByUserIdIP"/>
</sequence>
</complexType>
</element>
<element name="getPersonByUserIdResponse">
<complexType>
<sequence>
<element name="getPersonByUserIdReturn" nillable="true" type="tns3:GetPersonByUserIdOP"/>
</sequence>
</complexType>
</element>
<wsdl:message name="getPersonByUserIdRequest">
<wsdl:part element="impl:getPersonByUserId" name="parameters"/>
</wsdl:message>
<wsdl:message name="getOrganizationByUserIdRequest">
<wsdl:part element="impl:getOrganizationByUserId" name="parameters"/>
</wsdl:message>
<wsdl:message name="getPersonListResponse">
<wsdl:part element="impl:getPersonListResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getPersonByUserIdResponse">
<wsdl:part element="impl:getPersonByUserIdResponse" name="parameters"/
</wsdl:message>
<wsdl:operation name="getPersonByUserId">
<wsdl:input message="impl:getPersonByUserIdRequest" name="getPersonByUserIdRequest"/>
<wsdl:output message="impl:getPersonByUserIdResponse" name="getPersonByUserIdResponse"/>
</wsdl:operation>
GetPersonByUserId
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import com.org.u90.unifieduser.webservice.v4_0.beans.GetPersonByUserIdIP;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"getPersonByUserIdIP"
})
@XmlRootElement(name = "getPersonByUserId")
public class GetPersonByUserId
implements Serializable
{
@XmlElement(required = true, nillable = true)
protected GetPersonByUserIdIP getPersonByUserIdIP;
public GetPersonByUserIdIP getGetPersonByUserIdIP() {
return getPersonByUserIdIP;
}
public void setGetPersonByUserIdIP(GetPersonByUserIdIP value) {
this.getPersonByUserIdIP = value;
}
}
GetPersonByUseridIP:
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GetPersonByUserIdIP", propOrder = {
"userId",
"userType"
})
public class GetPersonByUserIdIP
extends AttributeRequest
implements Serializable
{
@XmlElement(required = true, nillable = true)
protected String userId;
@XmlElement(required = true, nillable = true)
protected String userType;
public String getUserId() {
return userId;
}
public void setUserId(String value) {
this.userId = value;
}
public String getUserType() {
return userType;
}
public void setUserType(String value) {
this.userType = value;
}
}
Spring WS-Config:(将 mvc 和 Ws 放在一起)
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
XmlWebApplicationContext rootContext = new XmlWebApplicationContext();
rootContext.setConfigLocation("classpath*:config/spring/applicationContext.xml");
servletContext.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(WebConfigurer.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
"Component-dispatcherServlet", new DispatcherServlet(dispatcherContext));
dispatcher.addMapping("/web/*");
MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
messageDispatcherServlet.setApplicationContext(rootContext);
messageDispatcherServlet.setTransformWsdlLocations(true);
ServletRegistration.Dynamic dessageDispatcher = servletContext.addServlet("MessageDispatcherServlet",
messageDispatcherServlet);
dessageDispatcher.addMapping("/WS/40/*");
}
}
@Bean(name="cus")
public Wsdl11Definition defaultWsdl11Definition() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("/WEB-INF/wsdl/CommonUserWS.wsdl"));
return wsdl11Definition;
}
服务等级:
@Endpoint
public class CommonUserWS {
private static final String NAMESPACE_URI = "http://v4_0.webservice.commonuser.u90.org.com";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getPersonByUserId")
@ResponsePayload
public JAXBElement<GetPersonByUserIdOP> getPersonByUserId(@RequestPayload GetPersonByUserIdIP getPersonByUserIdIP)
throws ContextException {
final GetPersonByUserIdOP output = new GetPersonByUserIdOP();
JAXBElement<GetPersonByUserIdOP> jaxbElement = null;
try {
String userType = getPersonByUserIdIP.getUserType();
String userId = getPersonByUserIdIP.getUserId();
// impl logic
QName qname = new QName("getPersonByUserId");
jaxbElement = new JAXBElement<GetPersonByUserIdOP>(qname, GetPersonByUserIdOP.class, output);
} catch (ContextException e) {
throw e;
}
return jaxbElement;
}
}
来自 GetPersonByUserIdIP 的上述类 - requestpayload 即将为空
以下是我发送的示例请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v4="http://v4_0.webservice.commonuser.u90.org.com" xmlns:bean="http://beans.v4_0.webservice.commonuser.u90.org.com">
<soapenv:Header/>
<soapenv:Body>
<bean:getPersonByUserId>
<bean:getPersonByUserIdIP>
<!--1 or more repetitions:-->
<bean:attribute>name</bean:attribute>
<bean:attribute>address</bean:attribute>
<bean:userId>hx52301</bean:userId>
<bean:userType/>
</bean:getPersonByUserIdIP>
</bean:getPersonByUserId>
</soapenv:Body>
</soapenv:Envelope>
我收到以下错误:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>UserId is null.</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
感谢您的关注,非常感谢您的帮助。
解决方案
通过查看您的@RequestPayload,正文应该以 getPersonByUserIdIP 而不是 getPersonByUserId 开头?
<soapenv:Body>
<bean:getPersonByUserIdIP>
<bean:attribute>name</bean:attribute>
<bean:attribute>address</bean:attribute>
<bean:userId>hx52301</bean:userId>
<bean:userType/>
</bean:getPersonByUserIdIP>
</soapenv:Body>`
推荐阅读
- r - 如何使用 for 循环将多参数函数应用于基于分组变量的数据框?
- php - 运行木材启动器主题时未找到“木材”类
- go - 通过网络的 TCP 连接传输目录内容
- node.js - NodeJS readFileSync 和 Regex 得到的文本
- git - 当我在这里尝试在 git bash 中 git push heroku 时出错
- javascript - 尝试运行 AudioContext.createMediaElementSource() 时如何解决“Audio 无法识别调用'connect'的对象”错误?
- javascript - Javascript ES5/ES6 类和错误处理
- c++ - 依赖于 C++ 的编译器优化
- wordpress - 如何实现多开发环境/工作流程?
- mongodb - 查找是否 field="x" 或注意?MongoDB数据库