1

嗨,我创建了一个 cxf:outInterceptors 来收集响应时间和有效负载,我得到以下异常:

WARNING: Interceptor for {http://test.org/Test/TestService/v1}TestService#{http://test.org/Test/TestService/v1}getTestData() has thrown exception, unwinding now
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. 
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:395)
    at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:238)
    at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:484)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java:119)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:109)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:137)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:122)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:81)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:61)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:323)
    at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:193)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:128)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:221)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3284)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

我的 Out 拦截器是:

public class TestOutInterceptor extends AbstractSoapInterceptor {

    private SAAJOutInterceptor saajOut = new SAAJOutInterceptor();




    public Test() {
    super(Phase.PRE_LOGICAL);
    getAfter().add(SAAJOutInterceptor.class.getName());
    // TODO Auto-generated constructor stub
    }

    @Override
    public void handleMessage(SoapMessage soapMessage) throws Fault {


    SOAPMessage soapMessagexml = getSOAPMessage(soapMessage);

        System.out.println(new BigDecimal((new Date()).getTime()));

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
        soapMessagexml.writeTo(out);
        String strMsg = new String(out.toByteArray());
         System.out.println(strMsg);

        } catch (SOAPException e) {
        logger.error("", e);
        } catch (IOException e) {
        logger.error("", e);
        }

    }
    }



    private SOAPMessage getSOAPMessage(SoapMessage smsg){

        SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);

    if (soapMessage == null) {



        saajOut.handleMessage(smsg);

        soapMessage = smsg.getContent(SOAPMessage.class);

    }   

    return soapMessage;

  }



}

我的春季配置是:

<cxf:bus>
        <cxf:features>
            <cxf:logging></cxf:logging>
        </cxf:features>
        </bean> -->
        </cxf:inInterceptors>
        <cxf:outInterceptors>
            <ref bean="TestOutInterceptor" />
        </cxf:outInterceptors>

    </cxf:bus>

我使用的版本是:

CXF:2.5.4 spring.version:3.1.0.RELEASE

4

1 回答 1

1

将 CXF 版本更新到 2.7.4 部分解决了该问题。然后我需要更新我的拦截器代码来解决这个问题。解决方案在此链接中得到了很好的解释:

public class TestOutInterceptor extends AbstractSoapInterceptor {
    private static Logger logger = LoggerFactory
        .getLogger(EnterpriseServiceMonitoringOutInterceptor.class);
    private SAAJOutInterceptor saajOut = new SAAJOutInterceptor();




    public TestOutInterceptor() {
    super(Phase.PRE_PROTOCOL);
    getAfter().add(SAAJOutInterceptor.class.getName());
    // TODO Auto-generated constructor stub
    }

    @Override
    public void handleMessage(SoapMessage soapMessage) throws Fault {
    getSOAPMessage(soapMessage);
        //add the ending interceptor to do the work
    soapMessage.getInterceptorChain().add(new EndingInterceptor());
    }



    private SOAPMessage getSOAPMessage(SoapMessage smsg){

        SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);

    if (soapMessage == null) {



        saajOut.handleMessage(smsg);

        soapMessage = smsg.getContent(SOAPMessage.class);

    }   

    return soapMessage;

  }

    static class EndingInterceptor extends AbstractSoapInterceptor {

    private SAAJOutEndingInterceptor saajOutEnding = new SAAJOutEndingInterceptor();
        public EndingInterceptor() {
             super(Phase.PRE_PROTOCOL_ENDING);
             addBefore(SAAJOutEndingInterceptor.class.getName()); 
         }
        public void handleMessage(SoapMessage soapMessage) throws Fault { 
            ServiceData serviceData=(ServiceData) soapMessage.getExchange().remove("esmServiceData");
        System.out.println("Test");
        System.out.println(soapMessage.getInterceptorChain());

        SOAPMessage soapMessagexml = getSOAPMessage(soapMessage);
        if(serviceData!=null){
            serviceData.setResponseTime(new BigDecimal((new Date()).getTime()));

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
            soapMessagexml.writeTo(out);
            String strMsg = new String(out.toByteArray());
             serviceData.setResponsePayload(strMsg);
             logger.debug(strMsg);
            } catch (SOAPException e) {
            logger.error("", e);
            } catch (IOException e) {
            logger.error("", e);
            }

        }
        }

        private SOAPMessage getSOAPMessage(SoapMessage smsg){

            SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);

        if (soapMessage == null) {



            saajOutEnding .handleMessage(smsg);

            soapMessage = smsg.getContent(SOAPMessage.class);

        }   

        return soapMessage;

      }
   } 

}
于 2013-06-18T20:46:14.337 回答