检索由camece端点中的Producertemplate发送的属性
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检索由camece端点中的Producertemplate发送的属性相关的知识,希望对你有一定的参考价值。
我正在开发我正在使用apche camel的spring boot应用程序我想生成动态文件url。我正在使用sendBodyAndProperty方法从中传递body和property但我面临未知函数Id错误。
producerTemplate.sendBodyAndProperty("direct:firstRout",
user.toString(), "Id",
user.getId() + ".json");
这里Id是关键,user.getId()是值
Route Builder代码
@Component
public class CamelComponent extends RouteBuilder{
public static String fileName;
@Override
public void configure() throws Exception {
from("direct:firstRoute").convertBodyTo(String.class)
.to("file:///D:/test/?fileName=${Id}"));
}
}
这是堆栈跟踪
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[file:///D:/test/?fileName=${Id}] <<< in route: Route(route1)[[From[direct:firstRoute]] -> [ConvertBodyTo[ja... because of Failed to resolve endpoint: file:///D:/test/?fileName=%24%7BId%7D due to: Unknown function: Id at location 0
${Id}
*
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1831) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) ~[camel-spring-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:174) ~[camel-spring-2.20.0.jar:2.20.0]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at com.igtb.App.main(App.java:11) [classes/:na]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[file:///D:/test/?fileName=${Id}] <<< in route: Route(route1)[[From[direct:firstRoute]] -> [ConvertBodyTo[ja... because of Failed to resolve endpoint: file:///D:/test/?fileName=%24%7BId%7D due to: Unknown function: Id at location 0
${Id}
*
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1298) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1148) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3727) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3441) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:208) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3249) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3245) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3268) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3245) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3168) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:133) ~[camel-spring-2.20.0.jar:2.20.0]
... 16 common frames omitted
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: file:///D:/test/?fileName=%24%7BId%7D due to: Unknown function: Id at location 0
${Id}
*
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:763) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:115) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:121) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:62) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:56) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:549) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:510) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:226) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1295) ~[camel-core-2.20.1.jar:2.20.1]
... 28 common frames omitted
Caused by: org.apache.camel.language.simple.types.SimpleIllegalSyntaxException: Unknown function: Id at location 0
${Id}
*
at org.apache.camel.language.simple.SimpleExpressionParser.parseExpression(SimpleExpressionParser.java:67) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.SimpleLanguage.createExpression(SimpleLanguage.java:186) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.component.file.GenericFileEndpoint.createFileLanguageExpression(GenericFileEndpoint.java:1298) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.component.file.GenericFileEndpoint.setFileName(GenericFileEndpoint.java:584) ~[camel-core-2.20.1.jar:2.20.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:568) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:645) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:497) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:507) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:254) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:309) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:297) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.component.file.GenericFileComponent.createEndpoint(GenericFileComponent.java:67) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.component.file.GenericFileComponent.createEndpoint(GenericFileComponent.java:37) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:126) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:716) ~[camel-core-2.20.1.jar:2.20.1]
... 38 common frames omitted
Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: Id
at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createSimpleExpression(SimpleFunctionExpression.java:256) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createExpression(SimpleFunctionExpression.java:58) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.ast.SimpleFunctionStart.doCreateLiteralExpression(SimpleFunctionStart.java:68) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.ast.SimpleFunctionStart.createExpression(SimpleFunctionStart.java:58) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.SimpleExpressionParser.createExpressions(SimpleExpressionParser.java:174) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.SimpleExpressionParser.doParseExpression(SimpleExpressionParser.java:97) ~[camel-core-2.20.1.jar:2.20.1]
at org.apache.camel.language.simple.SimpleExpressionParser.parseExpression(SimpleExpressionParser.java:64) ~[camel-core-2.20.1.jar:2.20.1]
... 56 common frames omitted
答案
这应该工作。
@Component
public class CamelComponent extends RouteBuilder{
public static String fileName;
@Override
public void configure() throws Exception {
from("direct:firstRoute").convertBodyTo(String.class)
.to("file:///D:/test/?fileName=${exchangeProperty.Id}"));
}
}
您访问该酒店的方式是使用exchangeProperty
。
以上是关于检索由camece端点中的Producertemplate发送的属性的主要内容,如果未能解决你的问题,请参考以下文章
如何配置 Appsync 以从 HTTP 端点检索数据以填充列表?