我在RAD 8和Websphere v7上使用JAX-WS创建了Web服务。 我使用ProtocolHandler来处理SOAP消息。
在handleMessage(SOAPMessageContext)方法中,我调用了getMessage()来获取SOAP消息。 我不能。这是我的代码
public boolean handleMessage(SOAPMessageContext context) {
try {
SOAPMessage soapMessage = context.getMessage(); // getMessage() always cause the error
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope= soapPart.getEnvelope();
} catch (SOAPException e) {
System.out.println("SOAPException");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
我总是得到以下错误。看来这个问题与SAAJ库有关。 但据我所知,我不明白IBM JDK有SAAJ实现的类。 并且......上面的代码在两天前工作了。在那之后,它不起作用。
所以我删除了所有项目文件并创建了新的动态Web项目来检查它是否有效。 它不起作用......
有人知道解决方案吗?或者有同样的问题?
[13. 7. 4 21:16:41:028 KST] 0000001c SystemErr R javax.xml.ws.WebServiceException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
[13. 7. 4 21:16:41:028 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
[13. 7. 4 21:16:41:028 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.message.impl.MessageImpl.getAsSOAPMessage(MessageImpl.java:344)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.SoapMessageContext.getMessage(SoapMessageContext.java:183)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at com.koreanair.naora.xml.handler.RAAWPID01ServicesProtocolHandler.handleMessage(RAAWPID01ServicesProtocolHandler.java:28)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at com.koreanair.naora.xml.handler.RAAWPID01ServicesProtocolHandler.handleMessage(RAAWPID01ServicesProtocolHandler.java:1)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.HandlerChainProcessor.callHandleMessageWithTracker(HandlerChainProcessor.java:871)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.HandlerChainProcessor.handleMessage(HandlerChainProcessor.java:516)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.HandlerChainProcessor.callGenericHandlers(HandlerChainProcessor.java:289)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.HandlerChainProcessor.processChain(HandlerChainProcessor.java:232)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.HandlerInvokerUtils.invokeInboundHandlers(HandlerInvokerUtils.java:65)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.handler.impl.HandlerInvokerImpl.invokeInboundHandlers(HandlerInvokerImpl.java:37)
[13. 7. 4 21:16:41:029 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.server.EndpointController.inboundHeaderAndHandlerProcessing(EndpointController.java:348)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.server.EndpointController.handleRequest(EndpointController.java:260)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.server.EndpointController.invoke(EndpointController.java:103)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:161)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:189)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1442)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:944)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:507)
[13. 7. 4 21:16:41:030 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[13. 7. 4 21:16:41:031 KST] 0000001c SystemErr R at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[13. 7. 4 21:16:41:056 KST] 0000001c SystemErr R at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
[13. 7. 4 21:16:41:056 KST] 0000001c SystemErr R at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[13. 7. 4 21:16:41:056 KST] 0000001c SystemErr R at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[13. 7. 4 21:16:41:056 KST] 0000001c SystemErr R at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[13. 7. 4 21:16:41:056 KST] 0000001c SystemErr R at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1656)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.MessageImpl.init(MessageImpl.java:536)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.MessageImpl.<init>(MessageImpl.java:316)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(SOAPMessageFactory1_1Impl.java:74)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at org.apache.axis2.jaxws.message.impl.MessageImpl.getAsSOAPMessage(MessageImpl.java:285)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R ... 41 more
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R Caused by: java.lang.NoClassDefFoundError: com/sun/xml/messaging/saaj/soap/SOAPDocumentImpl
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.<init>(SOAPPartImpl.java:106)
[13. 7. 4 21:16:41:057 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl.getSOAPPart(Message1_1Impl.java:90)
[13. 7. 4 21:16:41:058 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.MessageImpl.initCharsetProperty(MessageImpl.java:1441)
[13. 7. 4 21:16:41:058 KST] 0000001c SystemErr R at com.sun.xml.messaging.saaj.soap.MessageImpl.init(MessageImpl.java:406)
[13. 7. 4 21:16:41:058 KST] 0000001c SystemErr R ... 44 more
答案 0 :(得分:2)
堆栈跟踪行跟踪显示您有类加载问题
Caused by: java.lang.NoClassDefFoundError: com/sun/xml/messaging/saaj/soap/SOAPDocumentImpl
您的应用程序似乎包含一些包含应用程序服务器提供的类的库。下面的文章讨论了这类问题并指出了常见案例的解决方案,还包括底层用于集成第三方JAX-WS库的链接,这似乎是您的情况(下面还添加了直接链接)。
Best Practices for Integrating Open Source Software Packages with WebSphere Application Server
Enabling a third-party JAX-WS application in WebSphere Application Server V7
如果您更喜欢最快的出路,我可能会建议您查找并删除WAR或EAR中所有与WebServices相关的库,并使用WebSphere附带的库。
答案 1 :(得分:2)
您可以使用SOAP Handler拦截SOAP传入或传出标头。使用注释引用WS类/委托调用中的句柄,并在Handler类中覆盖handleRequest()。
前:
Handler.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<javaee:handler-chain>
<javaee:handler>
<javaee:handler-class>com.test.SoapHeaderValidation</javaee:handler-class>
</javaee:handler>
</javaee:handler-chain>
</javaee:handler-chains>
Delegete Class:
@HandlerChain(file="handler.xml")
public class RequestHandlerDelegate {
RequestHandler _requestHandler = new RequestHandler();
public String sendRequest(String xmlString) {
return _requestHandler.sendRequest(xmlString);
}
}
Handler Class:
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
// for response message only, true for outbound messages, false for inbound
if (!isRequest) {
try {
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope envelope= soapMsg.getSOAPPart().getEnvelope();
SOAPHeader header = envelope.getHeader();
if (header == null) {
generateSOAPErrMessage(soapMsg, "NO SOAP Header");
}
NodeList nl = header.getElementsByTagName("wsse:UsernameToken");
String user = nl.item(0).getFirstChild().getFirstChild().getNodeValue();
String password = nl.item(0).getFirstChild().getNextSibling().getFirstChild().getNodeValue();
} catch (Excection e) {
System.Out.println(e);
}
答案 2 :(得分:1)
试试这段代码:(如果你使用这种方法进行Req \ Rsp日志记录,它可以正常工作)
public boolean handleMessage(final SOAPMessageContext context) {
try {
final boolean isOutgoing = ((Boolean) context
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
final SOAPMessage message = context.getMessage();
if (null != message && null != message.getSOAPBody()) {
if (isOutgoing) {
String response = extractXmlMessage(message.getSOAPBody());
RequestResponseLogger.log("RESPONSE", response);
} else {
String request = extractXmlMessage(message.getSOAPBody());
RequestResponseLogger.log("REQUEST", request);
}
}
} catch (TransformerException transformerException) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unable to log Request Response Message ");
}
} catch (SOAPException e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unable to log Request Response Message ");
}
}
return true;
}