我在使用 Apache Camel 和 Spring DSL 时遇到了一个奇怪的问题。以下是我的 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>
直到我发布最后一行为止,一切都正常。执行 extractDocumentRootOid(Exchange Exchange)
java 方法,并将结果存储到 documentRootOid header 中。
执行getOrganizationByOid(Exchange Exchange, String oid)
java方法并将结果存储到organization header 。
执行 extractStyleSheetAttributeFromOrganization(Exchange Exchange, Organization Organization)
java 方法,并将结果存储到 organizationStyleSheet header 中。
一旦到达 transformBodyUsingStyleSheet
方法,事情就会变得奇怪。这是我的方法声明:
public void transformBodyUsingStyleSheet(Exchange exchange, String styleSheet)
我在方法的第一行放置了一个调试器,并且 styleSheet
值始终显示为交换主体,而不是我尝试在 (${header .organizationStyleSheet})
.
如果我通过调试器查看 header ,我会看到我的 organizationStyleSheet header 和我期望的值,所以我猜测我的 bean 参数绑定(bind)存在问题?之前有其他人遇到过这种情况吗?
附注我尝试用 ${exchange}
替换 *
但收到一些错误消息
org.apache.camel.ExpressionEvaluationException:
Cannot create/evaluate simple expression:
${exchange} to be bound to parameter at index: 0 on method"
最佳答案
看起来这是由于“transformBodyUsingStyleSheet”方法上缺少右括号引起的。我解决了这个问题并解决了我的问题。
关于java - Apache Camel bean 参数与 Spring DSL 的绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32914223/