Skip to content

Apache Camel bean parameter binding issue with Spring DSL

I am running into a strange issue with Apache Camel and Spring DSL. Here is an excerpt of my Spring defined route:

  <from uri="direct:process-xml"/>
  <setHeader headerName="documentRootOid">
    <method bean="" method="extractDocumentRootOid"/>
  <setHeader headerName="organization">
    <method bean="" method="getOrganizationByOid(*,${header.documentRootOid})"/>
  <setHeader headerName="organizationStyleSheet">
    <method bean="" method="extractStyleSheetAttributeFromOrganization(*,${header.organization})"/>
  <bean beanType="" method="transformBodyUsingStyleSheet(*,${header.organizationStyleSheet}"/>

Everything works fine up until the last line that I posted. The extractDocumentRootOid(Exchange exchange) java method is executed and the result is stored to the documentRootOid header.

The getOrganizationByOid(Exchange exchange, String oid) java method is executed and the result is stored to the organization header.

The extractStyleSheetAttributeFromOrganization(Exchange exchange, Organization organization) java method is executed and the result is stored to the organizationStyleSheet header.

Once it gets to the transformBodyUsingStyleSheet method, things get weird. Here is my method declaration:

public void transformBodyUsingStyleSheet(Exchange exchange, String styleSheet) 

I put a debugger on the first line of the method and the styleSheet value always appears to be the exchange body, NOT the value that I am trying to pass in (${header.organizationStyleSheet}).

If I look at the headers through a debugger, I see my organizationStyleSheet header and the value that I expect, so I am guessing that there is an issue with my bean parameter bindings? Has anyone else ran into this before?

P.S. I tried replacing * with ${exchange} but got a number of errors saying

  Cannot create/evaluate simple expression: 
    ${exchange} to be bound to parameter at index: 0 on method"


It looks like this was caused by a missing closing parenthesis on the “transformBodyUsingStyleSheet” method. I fixed that and it resolved my issue.