编程语言
首页 > 编程语言> > 试图找出为什么这两个SOAP请求之一不起作用(java.lang.IllegalArgumentException)

试图找出为什么这两个SOAP请求之一不起作用(java.lang.IllegalArgumentException)

作者:互联网

我有一个正在运行的JAX-WS Web服务,该服务已经有一些正常工作的端点.现在,我遇到以下问题:

我在这里有两个不同的SOAP请求,但我不明白为什么第一个有效,而第二个无效.

请求中唯一明显的不同是,第一个请求在< Envelope>中指定了一个名称空间.标签,而第二个在调用方法< getMoldDataHistory>时指定它.

SOAP请求1-不起作用(在方法调用中指定了名称空间)

<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
>
    <s:Body
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >
        <getMoldDataHistory
            xmlns="http://history.production.soap.webservices.product.company.at/">
            <machineId>92623-15853588</machineId>
            <start>0</start>
            <end>0</end>
        </getMoldDataHistory>
    </s:Body>
</s:Envelope>

SOAP请求2-工作(在< Envelope>标签中指定了名称空间)

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:his="http://history.production.soap.webservices.product.company.at/">

   <soapenv:Header/>

   <soapenv:Body>
      <his:getMoldDataHistory>
         <machineId>92623-15853588</machineId>
         <start>0</start>
         <end>0</end>
      </his:getMoldDataHistory>
   </soapenv:Body>
</soapenv:Envelope>

发出第一个(不起作用)请求时收到的SOAP错误消息.

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
         <faultcode>S:Server</faultcode>
         <faultstring>java.lang.IllegalArgumentException</faultstring>
      </S:Fault>
   </S:Body>
</S:Envelope>

接收第一个SOAP请求时从服务器引发的异常的stacktrace.

java.lang.IllegalArgumentException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.reflect.misc.Trampoline.invoke(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.xml.internal.ws.api.server.MethodUtil.invoke(Unknown Source)
    at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
    at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

所以我基本上是想弄清楚为什么第一个请求尽管是有效的SOAP请求却无法正常工作.我需要在服务器上进行配置以允许此类请求吗?

编辑:

经过更多测试后,我发现如果我调用的方法具有0个参数,则名称空间声明的位置无关紧要.一旦需要参数,它将停止工作.

编辑2:

现在我绊倒了this thread here.我有同样的问题.发出请求的C#客户端未在TAG方法中使用命名空间.添加后,它可以工作.

我仍然如何告诉JAX-WS处理此问题.

不起作用:

<getMoldDataHistory xmlns="http://history.production.soap.webservices.product.company.at/">

作品:

<his:getMoldDataHistory xmlns:his="http://history.production.soap.webservices.product.company.at/">

解决方法:

当使用绑定到名称空间的前缀时,例如

<his:getMoldDataHistory xmlns:his="http://history.production.soap.webservices.product.company.at/">
    <machineId>92623-15853588</machineId>
    <start>0</start>
    <end>0</end>
</his:getMoldDataHistory>

然后仅将元素getMoldDataHistory放入指定的名称空间.原因是语法xmlns:his =“ …”仅声明前缀.然后,必须在要包含在指定名称空间中的所有元素上使用此元素.在此代码段中,唯一的元素是getMoldDataHistory.

使用xmlns =“ …”语法,例如

<getMoldDataHistory xmlns="http://history.production.soap.webservices.product.company.at/">
    <machineId>92623-15853588</machineId>
    <start>0</start>
    <end>0</end>
</getMoldDataHistory>

不仅声明了名称空间,而且还将关联的元素和所有子元素放入此名称空间.

结论:这两个XML代码段在语义上并不等效.

如果存在“扩展元素名称”语法之类的问题,那么这些XML代码段将看起来像…

第一:

<{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>
    <{}machineId>92623-15853588</{}machineId>
    <{}start>0</{}start>
    <{}end>0</{}end>
</{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>

第二个:

<{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>
    <{http://history.production.soap.webservices.product.company.at/}machineId>92623-15853588</{http://history.production.soap.webservices.product.company.at/}machineId>
    <{http://history.production.soap.webservices.product.company.at/}start>0</{http://history.production.soap.webservices.product.company.at/}start>
    <{http://history.production.soap.webservices.product.company.at/}end>0<{/http://history.production.soap.webservices.product.company.at/}end>
</{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>

标签:java,jax-ws,web-services,soap
来源: https://codeday.me/bug/20191011/1891741.html