JAX-WS 空参数

JAX-WS null arguments

我已经根据 WSDL 定义(契约优先方法)制作了一个 WS 服务器。 我已经使用 wsimport 生成了 Java 工件并测试了该服务。 现在我遇到了问题。操作请求的一些(不是全部)参数被解组为空! Web 服务是基于 SOAP 的。 wsdl 遵循文档文字约定。 所以,这是 AbstractFDSInfo.wsdl:

导入的模式
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
        xmlns:tns="http://www.example.com/FDSControl"
        xmlns:com="http://www.example.com/FDSCommon"
        targetNamespace="http://www.example.com/FDSControl" 
        elementFormDefault="qualified">
  <import namespace="http://www.example.com/FDSCommon" schemaLocation="FDSCommon.xsd"/>

  <complexType name="PassengerList">
    <sequence>
      <element ref="com:Passenger" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
  </complexType>

  <complexType name="FlightInstanceStatusList">
    <sequence>
      <element type="com:flightInstanceStatus" name="Status" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
  </complexType>

  <!-- other operation types here -->

  <element name="setPassengerBoarded">
    <complexType>
      <sequence>
        <element ref="com:FlightInstanceId"/>
        <element type="string" name="Passenger"/>
      </sequence>
    </complexType>
  </element>
  <element name="setPassengerBoardedResponse">
    <complexType/>
  </element>
  <element name="passengerBoardingException">
    <complexType>
        <sequence>
          <element type="token" name="Reason"/>
          <element type="string" name="Detail"/>
        </sequence>
    </complexType>
  </element>

  <!-- Other operation types here --->

这里是 FDSControlAbstract.wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="FDSControlAbstract"  
             xmlns:tns="http://www.example.com/FDSControl.wsdl"
             xmlns:con="http://www.example.com/FDSControl"
             xmlns:com="http://www.example.com/FDSCommon"
             xmlns="http://schemas.xmlsoap.org/wsdl/"  
             targetNamespace="http://www.example.com/FDSControl.wsdl">
  <types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import namespace="http://www.example.com/FDSCommon" schemaLocation="FDSCommon.xsd"/>
      <xsd:import namespace="http://www.example.com/FDSControl" schemaLocation="FDSControl.xsd"/>
    </xsd:schema>
  </types>

  <message name="setPassengerBoardedRequest">
    <part element="con:setPassengerBoarded" name="Params"/>
  </message>
  <message name="setPassengerBoardedResponse">
    <part element="con:setPassengerBoardedResponse" name="Params"/>
  </message>
  <message name="passengerBoardingException">
    <part element="con:passengerBoardingException" name="Params"/>
  </message>

  <!-- other messages here -->

  <portType name="FDSBoardingPortType">

    <!-- other operations here -->

    <operation name="setPassengerBoarded">
      <documentation>
        Sets a passenger as boarded. If the passenger is already boarded, 
        or the flight instance is not in the boarding status, an exception
        is returned.
      </documentation>
      <input message="tns:setPassengerBoardedRequest"/>
      <output message="tns:setPassengerBoardedResponse"/>
      <fault message="tns:flightInstanceNotFoundException"
             name="flightInstanceNotFoundException"/>
      <fault message="tns:passengerBoardingException"
             name="passengerBoardingException"/>
      <fault message="tns:flightStatusException"
             name="flightStatusException"/>
    </operation>
  </portType>

 <!-- other port types here -->

</definitions>

这里是 FDSControl.wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="FDSControl"  
             xmlns:tns="http://www.example.com/FDSControl.wsdl"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns="http://schemas.xmlsoap.org/wsdl/"  
             targetNamespace="http://www.example.com/FDSControl.wsdl"
             elementFormDefault="qualified">
  <import namespace="http://www.example.com/FDSControl.wsdl" location="FDSControlAbstract.wsdl"/>

  <!-- other bindings here-->

  <binding name="FDSBoardingSOAP" type="tns:FDSBoardingPortType">

    <!-- other operations here -->

    <operation name="setPassengerBoarded">
      <soap:operation soapAction="http://www.example.com/FDSControl/setPassengerBoarded"/>
      <input> <soap:body use="literal"/> </input>
      <output> <soap:body use="literal"/> </output>
      <fault name="flightInstanceNotFoundException">
        <soap:fault name="flightInstanceNotFoundException" use="literal"/>
      </fault>
      <fault name="passengerBoardingException">
        <soap:fault name="passengerBoardingException" use="literal"/>
      </fault>
      <fault name="flightStatusException">
        <soap:fault name="flightStatusException" use="literal"/>
      </fault>
    </operation> 
  </binding>

  <service name="FDSBoardingSOAPService">
    <port name="FDSBoardingPortType" binding="tns:FDSBoardingSOAP">
      <soap:address location="http://localhost:7070/fdscontrol"/>
    </port>
  </service>

</definitions>

下面是实现网络服务的 java class 的定义:

@WebService(name="FDSBoarding",
        endpointInterface="it.polito.dp2.FDS.lab4.server.gen.FDSBoardingPortType",
        wsdlLocation="META-INF/FDSControl.wsdl",
        portName="FDSBoardingPortType",
        serviceName="FDSBoardingSOAPService",
        targetNamespace="http://www.example.com/FDSControl.wsdl")
})
public class FDSControlImpl implements FDSBoardingPortType {
    private FlightManager manager;

    public FDSControlImpl(FlightManager manager) {
        this.manager = manager;
    }

    //other methods here

    @Override
    public SetPassengerBoardedResponse setPassengerBoarded(SetPassengerBoarded params)
    throws FlightInstanceNotFoundException_Exception, FlightStatusException_Exception, PassengerBoardingException_Exception {
        return manager.setPassengerBoarded(params);
    }

}

你可以看到我将参数包裹在一个 class 中。 现在的问题是,每当我发送 setPassengerBoarded() 请求时,服务器 returns null as params.getPassenger() 我的 structure/definitions 有问题吗?

我没有评论权限。我建议首先通过 SOAP UI 测试 Web 服务。 然后您将确定该服务是否按您预期的那样工作,或者某些参数是否需要更改。 如果您的测试成功,则尝试在代理中设置相同的参数。

我正在将两个不同的 WSDL 编译到同一个包中。我将生成的代码分成两个包,问题就消失了,尽管现在我有重复的 类,因此我需要在这些代码之间来回转换...