- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试做非常简单的事情:客户端通过其 WSDL 调用 SOAP 服务来加载 PDF 文档。
我正在使用 Apache CXF 2.7.5 和 MTOM
问题是文档似乎没有完全发送到客户端(文件大小不等于原始文件),因此 ADOBE 无法打开它,因为它已损坏。
我的单元测试和 SOAPUI 调用都失败了。
If the title of the question has to be improved you're welcome
提前致谢。
服务接口(interface)
@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;
}
}
PDF数据源
@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 链接到 Pastebin SOAP UI http Log
最佳答案
已解决,因为我的 Apache http 配置出现问题。
关于java - 无法使用 CXF/MTOM 接收所有文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17047854/
我将Eclipse Helios Service Release 2版本用于apache cxf。当我转到windo->首选项-> Web服务-> CXF 2.x首选项,并设置cxf运行时时,版本和类
我是任何开放框架的新手(我是基于 java 的解决方案工程师)并试图构建一个 cxf 项目。 我知道我需要 applicationContext.xml文件和内容之类的
我想为不同的目的注册不同的类,以便在同一阶段调用 (Phase.PRE_INVOKE)。是否可以? 最佳答案 看这里http://cxf.apache.org/docs/interceptors.ht
我想使用 wsdl2java(CXF) 命令生成自定义包。 我的 WSDL 结构是: wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/w
我在通过 JAXRSClientFactoryBean.create 创建的 CXF 中有一个 JAX-RS 客户端。如何设置连接/接收超时? 我想我需要掌握管道,但不知道如何操作。这个项目没有使用
鉴于来自 fuse 源的 apache-servicemix-4.4.1-fuse-00-08 的“cxf-osgi”示例,使用 maven 3.0.3 构建,将其部署到 apache karaf 2
这个问题在这里已经有了答案: How do I fix a NoSuchMethodError? (33 个答案) 关闭 29 天前。 我刚刚尝试通过 Maven 使用 Apache CXF 和 S
我正在尝试使用 Apache CXF 开发一个 API 调用,该调用会随请求一起接收附件。我遵循了 this 教程,这就是我到目前为止所得到的。 @POST @Path("/upload") @Req
'org.apache.cxf.tools.wsdlto.WSDLToJava' 将 wsdl 转换为 java 类。 它是在内部使用 JAXB 吗?为什么这个命令能够生成类似于“xjc”创建的类?有
我已经使用 CXF 和 Spring 开发了一个 Java Web 服务。 由于安全原因,我想隐藏 WSDL,尽管 WS 仍然可用。 有没有办法使用 CXF 做到这一点? 最佳答案 您可以在 web.
我有一个生成的 JAXB 类(来自 XSD)。我能够以 XML 和 JSON 的形式返回,但是一旦我将 text/html 添加到我的 Produces 注释中,我就会得到: "No message
我创建了一个非常简单的基于 cxf 的非 spring Servlet,它加载了一个 javax.ws.rs.Application类型。 这是 web.xml: CXFSe
我正在使用 JBOSS EAP 6.2 来部署 restful web 服务。 restful web 服务使用 apache cxf,它取自 jboss eap。目前它使用 jar cxf-api-
我有一个服务方法定义为: public JaxbList getDeal() { List deals = new ArrayList(); Deal type = new Deal(
我需要将 wadl 转换为 java pojo,为此我已经下载了 apache cxf 3.0.1 版本。但是当我在命令提示符下运行 wadl2java bat 文件时,出现以下异常 D:\softw
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: Which maven2 artifacts are necessary to build a WS with CX
我想将一个简单的 CXF Jax-Ws 服务器部署到 ServiceMix。它只是一个同时具有服务接口(interface)和 impl 类的 OSGI 包。我需要将它部署到不同的 ServiceMi
是否可以在 wso2 ESB 中部署 CXF Web 服务? 目前我已经开始从 WSO2 User Guide 引用 wso2 的文档。我想将现有的 CXF Web 服务部署到 ESB。因此,有关这方
我想了解 cxf-bundle和 cxf-bundle-jaxrs jar 。它们是两个不同的 jar ,还是前者本身包含后者? 谢谢,巴蒂亚 最佳答案 前者包含后者。 但是,您实际上不应该使用其中任
我已经built and deployed a custom web services consumer in Java on Domino using the available CXF frame
我是一名优秀的程序员,十分优秀!