gpt4 book ai didi

soap - 返回错误的 JAX-WS 服务器端 SOAPHandler 在 WebSphere v8 上获取 "Internal Error"

转载 作者:行者123 更新时间:2023-12-03 20:51:39 27 4
gpt4 key购买 nike

我有一个服务器端 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对象(使用 SOAPFactory )并将其扔进 SOAPFaultException .

基于堆栈跟踪,我查看了 JAXWSMessageReceiver 的源代码,而且看起来在幕后,Axis2 正在寻找一个causeByException,但当然在这种情况下没有。

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

最佳答案

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

在 WAS Developer 控制台上

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

按照描述做 here (对于 WAS8):

Click Servers > Server Types. , and either WebSphere application servers > server_name or WebSphere proxy servers > server_name. Next, in the Server Infrastructure section, click Java and process management > Process definition , and select either Control, Servant, or Adjunct. Then click Java virtual machine > Custom properties.



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

enter image description here

关于soap - 返回错误的 JAX-WS 服务器端 SOAPHandler 在 WebSphere v8 上获取 "Internal Error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12805119/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com