2015-02-05 5 views
1

내 문제는 어떻게 문자열 템플릿 선언 내에서 Exchange의 헤더 값에 액세스 할 수 있는지 알 수 없습니다. 국제화 된 메일 템플릿을 갖고 싶습니다. 아래의 테스트 코드 ...Apache-Camel 문자열 템플릿 내에서 헤더 값에 액세스

public class StringTemplateTest extends CamelTestSupport { 

    @EndpointInject(uri = "mock:result") 
    protected MockEndpoint resultEndpoint; 

    @Produce(uri = "direct:start") 
    protected ProducerTemplate template; 

    @Test 
    public void testTemplating() throws Exception { 
     resultEndpoint.expectedBodiesReceived("test"); 
     template.sendBodyAndHeader("test", "lang", "de"); 
     resultEndpoint.assertIsSatisfied(); 
    } 

    @Override 
    protected RouteBuilder createRouteBuilder() { 
     return new RouteBuilder() { 
      public void configure() { 
       from("direct:start").to("string-template:mailTemplate_$simple{in.header.lang}.tm").to("mock:result"); 
      } 
     }; 
    } 
} 

이 끝나는 ...

java.io.FileNotFoundException: Cannot find resource: mailTemplate_$simple{in.header.lang}.tm in classpath for URI: mailTemplate_$simple{in.header.lang}.tm 

내가 기대하는 문자열 템플릿이 mailTemplate_de.tm에 대한 lookig된다.

미리 도움을 주셔서 감사합니다.

답변

1

귀하의 문제는 .to("component:xyz") 종점이 경로가 구축 될 때 평가된다는 점입니다. 이들은 동적이 아니며 ${} 속성을 선택하지 않습니다.

대신이 같은 recipientList를 사용해야합니다 :

from("direct:start") 
    .recipientList(simple("string_template:mailTemplate_${in.header.lang}.tm")) 
    .to("mock:result") 
+0

동적 약이 FAQ를 참조하십시오 http://camel.apache.org/how-to-use-a-dynamic-uri-in -to.html –