2

我在 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
4

3 回答 3

2

堆栈跟踪上的以下行表明您有类加载问题

Caused by: java.lang.NoClassDefFoundError: com/sun/xml/messaging/saaj/soap/SOAPDocumentImpl 

您的应用程序似乎包含一些库,其中包含应用程序服务器提供的一些类。下面的文章讨论了这类问题并指出了常见情况的解决方案,还包括底部用于集成第三方 JAX-WS 库的链接,这似乎是您的情况(下面还添加了直接链接)。

将开源软件包与 WebSphere Application Server 集成的最佳实践

在 WebSphere Application Server V7 中启用第三方 JAX-WS 应用程序

如果您更喜欢最快的方法,我可能会建议您在 WAR 或 EAR 中查找并删除所有与 WebServices 相关的库,并改用 WebSphere 附带的库。

于 2013-07-05T13:54:26.673 回答
2

您可以使用 SOAP 处理程序拦截 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);
            }
于 2013-12-23T19:35:37.963 回答
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;
}
于 2013-07-08T11:55:58.937 回答