2013-06-11 5 views
1

매우 간단한 작업을 수행하려고합니다. 클라이언트는 WSDL을 통해 SOAP 서비스를 호출하여 PDF 문서를로드합니다.CXF/MTOM을 사용하여 모든 문서를받을 수 없습니다.

내가

문제는이 문서가 완전히 클라이언트로 전송되지 않는 것으로 보인다 아파치 CXF 2.7.5MTOM을 사용하고 있습니다 (파일 크기하면 원본과 동일하지 않습니다) 그래서 ADOBE는 손상되어 열 수 없습니다.

내 단위 테스트와 SOAPUI 호출이 모두 실패했습니다.

질문의 제목이있는 경우

는 사전에

감사합니다 천만에요 개선한다.

서비스 인터페이스

@WebService 
@DataBinding(value = JAXBDataBinding.class) 
public interface DocumentService { 
    @WebMethod(operationName = "getContent") 
    DocumentContentVO getContent(@WebParam(name = "documentId") String documentId); 
} 

서비스 구현

@WebService(endpointInterface = "com.*.*.ws.sei.DocumentService", portName = "DocumentPort") 
public class CXFDocumentService extends AbstractCommonService implements DocumentService { 
@Override 
public DocumentContentVO getContent(String documentId) { 
    DocumentContentVO contentVO = new DocumentContentVO(); 
    contentVO.setDocumentId(documentId); 
    DataSource ds = new PDFDataSource(nodeService,documentId); 
    contentVO.setContent(new DataHandler(ds)); 
    return contentVO; 
    } 
} 

PDFDataSource

@Component 
public class PDFDataSource implements DataSource { 

public static final String APPLICATION_PDF = "application/pdf"; 
private final String documentId; 
private PCPNodeService nodeService; 

public PDFDataSource(PCPNodeService nodeService, String documentId) { 
    this.documentId = documentId; 
    this.nodeService = nodeService; 
} 

@Override 
public InputStream getInputStream() throws IOException { 
    FileInputStream fis = new FileInputStream("c:/document.pdf"); 
    RemoteInputStream remoteInputStream = nodeService.getNodeInputStream(documentId); 
    return fis; 
} 

@Override 
public OutputStream getOutputStream() throws IOException { 
    return null; 
} 

@Override 
public String getContentType() { 
    return APPLICATION_PDF; 
} 

@Override 
public String getName() { 
    return "INDICATE-DOCUMENT-NAME.pdf"; 
} 
} 

를 페이스트 빈하는 값 개체

@XmlRootElement(name = "DocumentContentVO") 
@XmlAccessorType(XmlAccessType.FIELD) 
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING) 
public class DocumentContentVO { 

private String documentId; 

@XmlMimeType("application/octet-stream") 
private DataHandler content; 


public DataHandler getContent() { 
    return content; 
} 

public void setContent(DataHandler content) { 
    this.content = content; 
} 

public String getDocumentId() { 
    return documentId; 
} 

public void setDocumentId(String documentId) { 
    this.documentId = documentId; 
} 

} 

단위 테스트 (클라이언트 호출을 할)

public class DocumentWSClientTest { 

@Test 
public void soap_operation_getContent_should_return_pdf_document() throws Exception { 

    final String documentId = "931c43c0-66a1-4ca3-bd86-5195a8f9e3de"; 
    final String wsdl = "http://localhost/pcp-soap/soap/v1/Documents?wsdl"; 
    final String operation = "getContent"; 
    final QName opName = new QName("http://sei.ws.*.*.com/", "getContent"); 

    // 
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(); 
    Client client = factory.createClient(wsdl); 
    Object[] result = client.invoke(opName, documentId); 
    DocumentContentVO documentContentVO = (DocumentContentVO) result[0]; 
    InputStream inputStream = documentContentVO.getContent().getInputStream(); 
    File file = new File("c:/job/test.pdf"); 
    if (file.exists()) { 
     file.delete(); 
    } 
    file.createNewFile(); 
    FileOutputStream outputStream = new FileOutputStream(file); 
    byte[] buffer = new byte[1024]; 
    while (inputStream.read(buffer) > -1) { 
     outputStream.write(buffer); 
    } 
} 
} 

예외 스택

org.apache.cxf.interceptor.Fault: Could not write attachments. 
at org.apache.cxf.interceptor.AttachmentOutInterceptor$AttachmentOutEndingInterceptor.handleMessage(AttachmentOutInterceptor.java:105) 
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) 
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77) 
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) 
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) 
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239) 
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223) 
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203) 
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137) 
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158) 
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243) 
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:163) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755) 
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219) 
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) 
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457) 
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) 
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557) 
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) 
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075) 
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384) 
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) 
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009) 
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) 
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) 
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154) 
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) 
at org.eclipse.jetty.server.Server.handle(Server.java:370) 
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489) 
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960) 
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021) 
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865) 
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240) 
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) 
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668) 
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) 
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) 
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) 
at java.lang.Thread.run(Thread.java:662) 
    **Caused by: java.io.IOException: Closed** 
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) 
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:107) 
at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:51) 
at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:60) 
at org.apache.cxf.attachment.AttachmentSerializer.writeAttachments(AttachmentSerializer.java:272) 
at org.apache.cxf.interceptor.AttachmentOutInterceptor$AttachmentOutEndingInterceptor.handleMessage(AttachmentOutInterceptor.java:103) 
... 38 more 

SOAPUI httpLog 링크SOAP UI http Log

+0

Apache CXF 버전 2.7.5 –

답변

-1

Apache http 설정에 문제가있어 해결되었습니다.

+0

자세한 정보를 제공 할 수 있습니까? – totali