Spring - WS-запрос на вход обнуляется - PullRequest
0 голосов
/ 27 августа 2018

Я использую Spring WS для создания веб-службы SOAP.Мой запрос на ввод данных становится пустым, и просьба помочь мне в устранении проблемы, поскольку в течение нескольких часов я пытался ее выяснить. Ниже приведен снимок моего кода

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>

спасибо за внимание, и любая помощь очень ценится.

1 Ответ

0 голосов
/ 27 августа 2018

При просмотре @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>`
...