Skip to content
Advertisement

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:

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

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

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement