16

我有一个服务器端 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>

以下错误被写入控制台:

[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)
...

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) {
    }
}

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

根据堆栈跟踪,我查看了 的源代码JAXWSMessageReceiver,它看起来像在幕后,Axis2 正在寻找一个 CauseByException,但在这种情况下当然没有。

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

4

5 回答 5

7

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

在 WAS 开发者控制台上

https://<yourhost>/<yourport>/ibm/console/login.do

按照此处所述进行操作(对于 WAS8):

单击服务器 > 服务器类型。,以及 WebSphere 应用程序服务器 > server_name 或 WebSphere 代理服务器 > server_name。接下来,在 Server Infrastructure 部分中,单击 Java and process management > Process definition ,然后选择 Control、Servant 或 Adjunct。然后单击 Java 虚拟机 > 自定义属性。

在那里,添加一个新属性webservices.unify.faults并将值设置为false

在此处输入图像描述

于 2015-08-19T09:27:15.343 回答
3

实际问题不是异常导致的丢失,而是websphere中统一的故障处理:

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

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

于 2012-11-20T13:01:15.753 回答
2

从版本 8 开始的 WebSphere 具有默认启用的安全特性,只是返回消息“内部错误”。这样做是为了“防止将有关入站消息处理失败原因的详细信息返回给消息发送者”。搜索“webservices.unify.faults”

要禁用此功能,请将 -Dwebservices.unify.faults=false 添加到您的 JVM 定制属性中。

于 2014-02-11T13:58:33.530 回答
0

可以通过禁用 IBM Websphere Application Server 上的通用故障处理功能来解决此错误。

要禁用此属性,请导航到管理控制台 > 服务器 > 应用程序服务器 > > 进程定义 > Java 虚拟机 > 自定义属性。

将密钥输入为“webservice.unify.faults”,将值输入为“false”。

更新后重新启动服务器并安装 EAR 以获取 SOAP 事务的自定义 WSDL 错误。

于 2016-05-20T05:02:27.103 回答
0

将 WAS FP 8.5.5.10升级到8.5.5.12后,我遇到了同样的问题。我们有两个方法名称完全相同但targetNameSpace不同的服务,例如 DomainService1 有'get'方法,而 DomainService2 也有'get'方法,但是 WAS 8.5.5.12抛出此异常并且没有提供任何线索来找到根本原因。显然,在最近的版本中,WAS 对方法的命名更加严格。

这是异常: org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperException:发生内部断言错误。com.xxx.web.myapp.services.jaxws.GetResponse JAXB 对象没有 xxxxxStatus xml

更改特定于每个服务“getABC”和“getPQR”的方法名称后,它起作用了!!!

希望这有效!

于 2017-12-06T23:11:34.777 回答