You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by andrew goh via users <us...@camel.apache.org> on 2026/05/18 12:10:52 UTC

CamelPrint

hello all,

Apache Camel is an interesting, huge tech stack / framework.

Recently, as I'm learning the ropes of Apache Camel, I tried making a 
web based pdf renderer which I called it 'camel print'.
I got into quite a lot of bummers and finally made a working version.
In a gist, the route is like:

|context.addRoutes(new RouteBuilder() {||
||||
||  @Override||
||  public void configure() throws Exception {||
||from("seda:print.jobs?concurrentConsumers=5&waitForTaskToComplete=IfReplyExpected") 
||
||    .choice()||
||    .when(header("outputType").isEqualTo("xml"))||
||      .marshal().jaxb(jaxbctxpath).stop()||
||    .when(header("outputType").isEqualTo("xslt"))||
||      .marshal().jaxb(jaxbctxpath)||
||      .toD("xslt:${header.xsltTemplate}").stop()||
||    .otherwise()||
||      .marshal().jaxb(jaxbctxpath)||
||      .toD("xslt:${header.xsltTemplate}")||
||      .process("foToPdfProcessor").stop();||
||  }||
||});
|

I tried doing this in xml using xml-io-dsl
https://camel.apache.org/components/4.18.x/others/java-xml-io-dsl.html
It actually worked very well, until I got stuck as I wanted to 
'dynamically' pass that '|jaxbctxpath'| for the jaxb context path.
I couldn't figure out how to pass 'variables' during route build phase 
with xml, and finally resorted to just doing java dsl.

'printing' or rendering is like

|  ProducerTemplate template = camelmgr.getProducerTemplate(); ||
||  Exchange pdfResp = template.request("seda:print.jobs", exchange -> {||
||    exchange.getIn().setBody(jaxbObject);||
||    exchange.getIn().setHeader("xsltTemplate", xsltemplate);||||||
||  });||
||||
||  byte[] pdf = pdfResp.getMessage().getBody(byte[].class);||
|

The stack is kind of 'huge' it apparently pulled in a good number of 
camel dependencies, I'm not sure if I'd be able to make that 'thinner'. 
The other 'non-camel' dependencies are like Apache FOP, jetty etc.

Hope to hear your comments

Cheers :)
   Andrew

||