简体   繁体   English

Spring DSL 的 Apache Camel bean 参数绑定问题

[英]Apache Camel bean parameter binding issue with Spring DSL

I am running into a strange issue with Apache Camel and Spring DSL.我在使用 Apache Camel 和 Spring DSL 时遇到了一个奇怪的问题。 Here is an excerpt of my Spring defined route:这是我的 Spring 定义路线的摘录:

<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.执行extractDocumentRootOid(Exchange exchange) java 方法并将结果存储到documentRootOid头中。

The getOrganizationByOid(Exchange exchange, String oid) java method is executed and the result is stored to the organization header.执行getOrganizationByOid(Exchange exchange, String oid) java 方法并将结果存储到组织头中。

The extractStyleSheetAttributeFromOrganization(Exchange exchange, Organization organization) java method is executed and the result is stored to the organizationStyleSheet header.执行extractStyleSheetAttributeFromOrganization(Exchange exchange, Organization organization) java 方法并将结果存储到organizationStyleSheet头中。

Once it gets to the transformBodyUsingStyleSheet method, things get weird.一旦进入transformBodyUsingStyleSheet方法,事情就会变得很奇怪。 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}) .我在方法的第一行放置了一个调试器,并且styleSheet值总是显示为交换体,而不是我试图传入的值(${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?如果我通过调试器查看标头,我会看到我的organizationStyleSheet标头和我期望的值,所以我猜测我的 bean 参数绑定有问题? Has anyone else ran into this before?有没有其他人遇到过这个问题?

PS I tried replacing * with ${exchange} but got a number of errors saying PS 我尝试用${exchange}替换*但得到了一些错误说

org.apache.camel.ExpressionEvaluationException: 
  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.看起来这是由于“transformBodyUsingStyleSheet”方法上缺少右括号引起的。 I fixed that and it resolved my issue.我解决了这个问题,它解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM