Java 使用ApacheCXFAPI调用webservice时soap正文为空

Java 使用ApacheCXFAPI调用webservice时soap正文为空,java,web-services,soap,wsdl,cxf,Java,Web Services,Soap,Wsdl,Cxf,Iam在将soap主体附加到Web服务时面临问题。Iam使用ApacheCXFAPI。 调用webservice时,我看到soap主体生成为空。 Iam使用以下代码: GetPDFDocumentRequest request = new ObjectFactory().createGetPDFDocumentRequest(); request.setCrid(reference); request.setResourceId(confirmationId); req

Iam在将soap主体附加到Web服务时面临问题。Iam使用ApacheCXFAPI。 调用webservice时,我看到soap主体生成为空。 Iam使用以下代码:

 GetPDFDocumentRequest request = new ObjectFactory().createGetPDFDocumentRequest();
    request.setCrid(reference);
    request.setResourceId(confirmationId);
    request.setVersion(Integer.parseInt(version));
    request.setDocType(pdfType);
    String encryptedString  = svc().getPDFDocument(request).getDocument();
虽然当我从GetPDFDocumentRequest打印值时。所有值:crid、resourceid、version和doctype都有值,但我看不到它附加在soap正文中,如下所示:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"></env:Header><soap:Body><ns2:GetPDFDocumentRequest xmlns="http://test.fm.com/Static/interface" xmlns:ns2="https://test.fm.grp.net/style/webservices/schemas/messages" xmlns:ns3="http://test.fm.com/EventML" xmlns:ns4="http://test.fm.com/StyleML" xmlns:ns5="http://test.fm.com/odc" xmlns:ns6="https://test.fm.rbsgrp.net/test/lifecycle/schemas/types" xmlns:ns7="https://test.fm.rbsgrp.net/style/persistence/schemas/types" xmlns:ns8="http://test.fm.com/Reporting/interface" xmlns:ns9="http://test.fm.com/ConfigML"/></soap:Body>

通过检查java代码中的请求POJO,您将无法看到SOAP主体/包装元素。这是因为如果CXF在框架级别发送请求之前将请求包装在SOAP主体中。它对程序员是透明的,不能在java代码中查看

但是,如果您确实想查看和截获原始消息,请尝试使用“JAXWS处理程序”或其等效的“CXF拦截器”

更重要的是,除非您需要对数据进行一些特殊的预/后处理或按摩,否则您实际上不需要拦截来查看SOAP主体。否则,仅使用Java类中的服务方法,将数据读写到CXF wsgen创建的POJO中,就足以满足大多数实际目的

更新:
我发现一个CXF JIRA问题与您的问题完全相同它为您的问题提供了在结尾写下的解决方案——我认为这很可能也是您的解决方案。这是JIRA链接-

我只在out拦截器中打印了这个soap主体。目前我的问题是soap主体是空白的。它应该像下面的注释ok中提到的那样,您可以在您正在打印整个请求的拦截器中共享代码吗(在没有SOAP正文的情况下打印)…也只是为了确认在webservice端,SOAP正文也是空白的。此代码以其他方式工作,但它从一个应用程序生成soap主体。它部署在JBOSS 5.1.2.GA中。这不是拦截器的问题。同一个拦截器在其他应用程序上运行良好。在我看来,这并不像我的问题。在我的场景中,soap主体是生成的,参数id未设置。哎呀。我认为jboss有一些问题。因为在其他情况下,当从windows服务调用我的代码时,我的代码工作正常
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.4</version>
</dependency> 
import java.io.OutputStream;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.io.CacheAndWriteOutputStream;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.io.CachedOutputStreamCallback;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class LogInterceptor extends LoggingOutInterceptor {

     private Logger logger = Logger.getLogger(LogInterceptor.class);
    public LogInterceptor() {
        super(Phase.PRE_STREAM);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        OutputStream out = message.getContent(OutputStream.class);
        final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(out);
        message.setContent(OutputStream.class, newOut);
        newOut.registerCallback(new LoggingCallback());
    }

    public class LoggingCallback implements CachedOutputStreamCallback {
        public void onFlush(CachedOutputStream cos) {
        }

        public void onClose(CachedOutputStream cos) {
            try {
                StringBuilder builder = new StringBuilder();
                cos.writeCacheTo(builder, limit);
                String soapXml = builder.toString();
                logger.log(Level.INFO, "SOAP XML SENT TO STYLE" + soapXml);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}