Web服务不接受在Glassfish中指定名称空间的xml元素

时间:2018-12-14 14:57:24

标签: java xml soap glassfish

我正在将Web服务从Weblogic迁移到Glassfish,并且遇到了非常奇怪的行为。以前,当我将此xml发送给服务时,它已正确解析:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:NS1="http://croc/WS_get_ota_info_for_K2.wsdl">
    <soapenv:Body>
        <NS1:courses >
            <NS1:String_1>filter value</NS1:String_1>
        </NS1:courses>
    </soapenv:Body>
</soapenv:Envelope>

但是在我从元素String_1迁移到Glassfish 4.1.2之后,未将其值用作方法参数。传递了空值而不是“过滤器值”。但是当我将xml更改为此

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:NS1="http://croc/WS_get_ota_info_for_K2.wsdl">
    <soapenv:Body>
        <NS1:courses >
            <String_1>filter value</String_1>
        </NS1:courses>
    </soapenv:Body>
</soapenv:Envelope>

一切恢复正常。该xml对在Weblogic上运行的服务的先前版本也有效。

这种行为的原因是什么? WSDL并未更改,因此我希望我的服务在两个Web服务器上都能以相同的方式工作。

这是我的WSDL:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
     name="WS_get_ota_info_for_K2"
     targetNamespace="http://croc/WS_get_ota_info_for_K2.wsdl"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:tns="http://croc/WS_get_ota_info_for_K2.wsdl"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
    <wsdl:types>
    </wsdl:types>
    <wsdl:message name="WS_get_ota_info_for_K2_courses">
        <wsdl:part name="String_1" type="xsd:string"/>
    </wsdl:message>
    <wsdl:message name="WS_get_ota_info_for_K2_coursesResponse">
        <wsdl:part name="result" type="xsd:string"/>
    </wsdl:message>
    <wsdl:portType name="WS_get_ota_info_for_K2">
        <wsdl:operation name="courses" parameterOrder="String_1">
            <wsdl:input message="tns:WS_get_ota_info_for_K2_courses"/>
            <wsdl:output message="tns:WS_get_ota_info_for_K2_coursesResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="WS_get_ota_info_for_K2" type="tns:WS_get_ota_info_for_K2">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="courses">
            <soap:operation soapAction="http://croc/WS_get_ota_info_for_K2.wsdl/courses"/>
            <wsdl:input>
                <soap:body use="literal" namespace="http://croc/WS_get_ota_info_for_K2.wsdl" parts="String_1"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" namespace="http://croc/WS_get_ota_info_for_K2.wsdl" parts="result"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WS_get_ota_info_for_K2">
        <wsdl:port name="WS_get_ota_info_for_K2Port" binding="tns:WS_get_ota_info_for_K2">
            <soap:address location="http://localhost:7101/WS_get_ota_info_for_K2/WS_get_ota_info_for_K2Port"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

和Java类

import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;

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

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.sql.DataSource;

@SOAPBinding(style = SOAPBinding.Style.RPC)
@WebService(name = "WS_get_ota_info_for_K2", serviceName = "WS_get_ota_info_for_K2",
            targetNamespace = "http://croc/WS_get_ota_info_for_K2.wsdl", portName = "WS_get_ota_info_for_K2Port",
            wsdlLocation = "WEB-INF/wsdl/WS_get_ota_info_for_K2.wsdl")
public class WSGetOtaInfoForK2Impl {
    private static final String DATA_SOURCE = "jdbc/mainDS";
    protected DataSource __dataSource = null;

    public WSGetOtaInfoForK2Impl() throws NamingException {
        Context ctx = new InitialContext();
        __dataSource = (DataSource) ctx.lookup(DATA_SOURCE);
    }

    @WebResult(name = "result", partName = "result")
    @WebMethod(action = "http://croc/WS_get_ota_info_for_K2.wsdl/courses")
    public String courses(@WebParam(name = "String_1", partName = "String_1") String string1) throws SQLException {
        String response = calculateSomething(string1);
        return response;
    }
}

0 个答案:

没有答案