返回错误的JAX-WS服务器端SOAPHandler在WebSphere v8上获得"内部错误"

use*_*528 15 websphere soap jax-ws websphere-8

我有一个服务器端JAX-WS SOAPHandler(在WebSphere v8上),在某些情况下需要使用它在String变量中的SOAP响应来响应客户端(让我们调用它responseXml).

responseXml包含成功(即非故障)SOAP消息时,JAX-WS会正确地将响应发送到客户端.但是,当responseXml包含SOAP错误消息时,会发生"内部错误",并且客户端获得的错误响应与其中的不同responseXml,如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <soapenv:Fault xmlns:axis2ns1="http://schemas.xmlsoap.org/soap/envelope/">
         <faultcode>axis2ns1:Server</faultcode>
         <faultstring>Internal Error</faultstring>
         <detail/>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

将以下错误写入控制台:

[10/9/12 12:21:04:177 EDT] 00000025 AxisEngine    E org.apache.axis2.engine.AxisEngine receive An error was detected during JAXWS processing
                             org.apache.axis2.AxisFault: An error was detected during JAXWS processing
at org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:208)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:198)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1466)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
...
Run Code Online (Sandbox Code Playgroud)

这是一个简化SOAPHandler,说明了这个问题.(请注意,responseXml这里显示的值只是一个示例.在我的实际中SOAPHandler,响应不是硬编码的,而是从数据库中读取的.我只是想尽可能地展示最简单的示例代码.)

package simplified.demo;

import java.io.ByteArrayInputStream;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class FaultyHandler implements SOAPHandler<SOAPMessageContext> {

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (!outbound) {
            String responseXml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header></soapenv:Header><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>ORA-01031: insufficient privileges</faultstring><detail/></soapenv:Fault></soapenv:Body></soapenv:Envelope>";
            try {
                SOAPMessage newMsg = createSOAPMessage(responseXml);
                context.setMessage(newMsg);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        return (outbound);
    }

    private SOAPMessage createSOAPMessage(String responseXml) {
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(responseXml.getBytes());
            MessageFactory messageFactory = MessageFactory.newInstance();
            return messageFactory.createMessage(null, in);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        return true;
    }

    @Override
    public Set<QName> getHeaders() {
        return null;
    }

    @Override
    public void close(MessageContext context) {
    }
}
Run Code Online (Sandbox Code Playgroud)

当我编码SOAPHandler创建一个SOAPFault对象(使用a SOAPFactory)并将其抛出时,我得到了完全相同的错误SOAPFaultException.

基于堆栈跟踪,我查看了源代码JAXWSMessageReceiver,看起来好像在底层,Axis2正在寻找一个causeByException,但当然在这种情况下没有一个.

有谁知道为什么会发生这种情况或如何解决?谢谢!

sch*_*rer 6

我遇到了同样的问题,并且能够通过禁用统一的错误处理来解决它(这不是错误,而是功能!)。

在WAS Developer控制台上

https://<yourhost>/<yourport>/ibm/console/login.do
Run Code Online (Sandbox Code Playgroud)

按照此处所述(针对WAS8)执行操作:

单击服务器>服务器类型。,以及WebSphere Application Server> server_name或WebSphere代理服务器> server_name。接下来,在“服务器基础结构”部分中,单击“ Java和流程管理”>“流程定义”,然后选择“控件”,“仆人”或“附件”。然后单击Java虚拟机>定制属性。

在此处添加新属性webservices.unify.faults,并将值设置为false

在此处输入图片说明


小智 3

实际问题并不是异常导致的缺失,而是websphere中统一的错误处理:

http://www-01.ibm.com/support/docview.wss?uid=swg1PM58524

使用所描述的解决方法或安装至少 8.0.0.4