2

I need to return a remote PDF file as application/pdf. In a classic WAR, I'd build a servlet that retrieves the remote PDF as InputStream and returns the same PDF as OutputStream, is possible to do so in Apache Camel? What is the best practice?

I saw camel-servlet but I didn't understand the way to do this.

egorlitvinenko
  • 2,736
  • 2
  • 16
  • 36
GSX
  • 63
  • 7

1 Answers1

2

I found this solution: defining the rest service as follows (REST DSL)

<rest path="/">
    <get consumes="application/json"
        outType="java.io.InputStream"
        produces="application/pdf" uri="/provarest">
        <to uri="direct:provaRest"/>
    </get>
</rest>

I'm able to return the PDF with this route

<route id="route6">
    <from id="_from1Route6" uri="direct:provaRest"/>
    <to id="_toProvaRest" uri="provaRestProcessorId"/>
</route>

where provaRestProcessorId is a processor with this method

@Override
public void process(Exchange exchange) throws Exception {
    InputStream is = new FileInputStream(new File("C:\\somepath\\Prova.pdf"));
    exchange.getOut().setBody(is);
}
GSX
  • 63
  • 7