2017-07-27 78 views
0

我试图找出JAX-WS在过去几天内的间隔行为。服务器上的有效JAX-WS请求参数为NULL

基本上我有两个不同的SOAP请求从两个不同的客户端生成,我无法对这些请求的创建方式进行任何更改。我仍然需要能够处理这两种类型的请求。

不幸的是,第二个请求的请求参数在服务器上设置为NULL,尽管我在请求中发送时有一个有效值。这意味着服务器无法正确解析此请求。我如何告诉我的JAX-WS服务器正确处理这两个请求?

工作要求

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <ns2:getMachine xmlns:ns2="http://machine.soap.webservices.product.company.at/"> 
      <machineId>92623-15853588</machineId> 
     </ns2:getMachine> 
    </S:Body> 
</S:Envelope> 

断请求(参数是在服务器端NULL)。

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <getMachine xmlns="http://machine.soap.webservices.product.company.at/"> 
      <machineId>92623-15853588</machineId> 
     </getMachine> 
    </S:Body> 
</S:Envelope> 

我似乎无法找到尽管这个问题似乎很长一段时间(See this 2 year old stackoverflow thread)被称为事实的任何解决这个问题。

为了完成,这里是我的WebService的实现。我试图将目标命名空间直接设置为@WebService@WebParam注释,但它没有效果。

package at.company.product.webservices.soap.machine; 


import javax.jws.WebMethod; 
import javax.jws.WebParam; 
import javax.jws.WebService; 
import javax.jws.soap.SOAPBinding; 

import at.company.product.core.ProductCorePlugin; 
import at.company.product.core.machine.IMachine; 
import at.company.product.webservices.soap.exceptions.InvalidIdException; 

@WebService 
@SOAPBinding(style = SOAPBinding.Style.RPC) 
public class WSMachineApi { 

    @WebMethod 
    public WSMachine getMachine(@WebParam(name = "machineId") String machineId) throws InvalidIdException{ 
     IMachine machine = getMachineById(machineId); 
     if (machine == null){ 
      throw new InvalidIdException(machineId); 
     } 

     return new WSMachine(getMachineById(machineId)); 
    } 

    private IMachine getMachineById(String id) { 
     return ProductCorePlugin.getDefault().getMachineHallAdmin().getMachineByID(id); 
    } 

} 

服务

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.4-b01. --> 
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://machine.soap.webservices.product.company.at/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://machine.soap.webservices.product.company.at/" name="WSMachineApiService"> 
    <types> 
    <xsd:schema> 
    <xsd:import namespace="http://machine.soap.webservices.product.company.at/" schemaLocation="http://someHostname:8080/services/Machines?xsd=1"></xsd:import> 
    </xsd:schema> 
    </types> 
    <message name="InvalidIdException"> 
    <part name="fault" element="tns:InvalidIdException"></part> 
    </message> 

    <message name="getMachine"> 
    <part name="machineId" type="xsd:string"></part> 
    </message> 
    <message name="getMachineResponse"> 
    <part name="return" type="tns:WSMachine"></part> 
    </message> 
    <portType name="WSMachineApi"> 
    <operation name="getMachine"> 
    <input wsam:Action="http://machine.soap.webservices.product.company.at/WSMachineApi/getMachineRequest" message="tns:getMachine"></input> 
    <output wsam:Action="http://machine.soap.webservices.product.company.at/WSMachineApi/getMachineResponse" message="tns:getMachineResponse"></output> 
    <fault message="tns:InvalidIdException" name="InvalidIdException" wsam:Action="http://machine.soap.webservices.product.company.at/WSMachineApi/getMachine/Fault/InvalidIdException"></fault> 
    </operation> 
    </portType> 
    <binding name="WSMachineApiPortBinding" type="tns:WSMachineApi"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding> 
    <operation name="getMachine"> 
    <soap:operation soapAction=""></soap:operation> 
    <input> 
    <soap:body use="literal" namespace="http://machine.soap.webservices.product.company.at/"></soap:body> 
    </input> 
    <output> 
    <soap:body use="literal" namespace="http://machine.soap.webservices.product.company.at/"></soap:body> 
    </output> 
    <fault name="InvalidIdException"> 
    <soap:fault name="InvalidIdException" use="literal"></soap:fault> 
    </fault> 
    </operation> 
    </binding> 
    <service name="WSMachineApiService"> 
    <port name="WSMachineApiPort" binding="tns:WSMachineApiPortBinding"> 
    <soap:address location="http://someHostname:8080/services/Machines"></soap:address> 
    </port> 
    </service> 
    </definitions> 

的XSD

<xs:schema xmlns:tns="http://machine.soap.webservices.product.company.at/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://machine.soap.webservices.product.company.at/"> 

    <xs:element name="InvalidIdException" type="tns:InvalidIdException"></xs:element> 


    <xs:complexType name="WSMachine"> 
    <xs:sequence> 
    <xs:element name="name" type="xs:string" minOccurs="0"></xs:element> 
    <xs:element name="id" type="xs:string" minOccurs="0"></xs:element> 
    <xs:element name="totalShots" type="xs:long"></xs:element> 
    <xs:element name="totalEvents" type="xs:long"></xs:element> 
    <xs:element name="actualData" type="tns:WSMachineActualData" minOccurs="0"></xs:element> 
    </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="WSMachineActualData"> 
    <xs:sequence> 
    <xs:element name="connected" type="xs:boolean"></xs:element> 
    <xs:element name="operationMode" type="xs:string" minOccurs="0"></xs:element> 
    </xs:sequence> 
    </xs:complexType> 


    <xs:complexType name="InvalidIdException"> 
    <xs:sequence> 
    <xs:element name="id" type="xs:string" minOccurs="0"></xs:element> 
    <xs:element name="message" type="xs:string" minOccurs="0"></xs:element> 
    </xs:sequence> 
    </xs:complexType> 


    </xs:schema> 
+1

请为此Web服务提供xsd(xml架构)。 –

+0

我添加了由我的webservice生成的WSDL。这是你的意思吗? – Markus

+1

发布一个在WSDL的'xsd:import'标记中指定的文件 - 'schemaLocation =“http:// someHostname:8080/services/Machines?xsd = 1” –

回答

2

你可能需要定制SOAPHandler利用的WSDL。示例显示为here。 使用自定义处理程序,您将能够轻松调试此问题。

+0

我来看看。感谢提示! – Markus

+0

我得出的结论是,唯一能够使用SOAPHandler的方法是使用SOAPHandler。 – Markus

相关问题