【问题标题】:Unable to Send PDF attachment through Mule HTTPEndPoint无法通过 Mule HTTPEndPoint 发送 PDF 附件
【发布时间】:2013-11-17 07:57:36
【问题描述】:

我有一个要求,我将把 html 表单中的数据提交给 Mule 流,Mule 应该返回一个 PDF 文件。我创建了以下流程。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <flow name="SampleMuleFlow1" doc:name="SampleMuleFlow1">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8081" path="test" doc:name="HTTP" contentType="application/pdf"
            mimeType="application/pdf">
        </http:inbound-endpoint>
        <custom-transformer returnClass="org.mule.api.MuleMessage"
            mimeType="application/pdf"
            class="com.tcs.pdfgen.GenerateGFEService_GenerateGFEServiceImplPort_Client"
            doc:name="Java" />

    </flow>
</mule>

I attach the PDF file through the api   message.addOutboundAttachment().Please check the Custom Tranformer file i have written.

package com.tcs.pdfgen;

/**
 * Please modify this class to meet your needs
 * This class is not complete
 */
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

import javax.xml.namespace.QName;

import org.apache.cxf.attachment.LazyDataSource;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;



    @Override
    public Object transformMessage(MuleMessage message, String outputEncoding)
            throws TransformerException {
        try {
            GenerateGFEService_GenerateGFEServiceImplPort_Client client = new GenerateGFEService_GenerateGFEServiceImplPort_Client();

/*client.genGFE(message, "GeneratedSamplePDF.pdf") method return a byte array of the PDF file.*/

            message.addOutboundAttachment("GFEFile",
                    client.genGFE(message, "GeneratedSamplePDF.pdf"),
                    "application/pdf");

            System.out.println("Attachment Names>>>>"
                    + message.getOutboundAttachmentNames());

            System.out.println("ApplicationHome settings>>>"
                    + message.getOutboundProperty("ApplicationHome"));

            return message;
        } catch (Exception ioe) {
            System.out.println("exception 1111");
            System.out.println("Exception Message>>>>>>" + ioe.getMessage());
            throw new TransformerException(this, ioe);
        } catch (Throwable t) {
            System.out.println("exception?>>>" + t.getMessage());
        } finally {
            try {

            } catch (Throwable t) {
            }
        }
        return message;
    }

}

但在浏览器上,我收到一个错误,PDF 不以“%PDF”开头。我相信 PDF 附件不是通过 HTTP 响应对象发送的。如果我遗漏了什么,请告诉我。

【问题讨论】:

    标签: pdf mule attachment


    【解决方案1】:

    将 PDF 内容输入流设置为消息负载而不是附件:这样 Mule 会将其流式传输回浏览器。

    【讨论】:

      猜你喜欢
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 2015-06-20
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多