【问题标题】:Camel rest response using ftl使用 ftl 的骆驼休息响应
【发布时间】:2018-09-04 10:21:07
【问题描述】:

我有一条骆驼休息路线在其适当的操作后采用生产/消费 json。现在,我希望使用 FTL 创建 json 响应,但我无法做到。

这是我的代码:

rest("/").bindingMode(RestBindingMode.auto).description("Search for CAF").consumes("application/json").produces("application/json")
                .post("/search/cam")
                .type(CAMRequestDTO.class)
                .outType(CAMResponseDTO.class)
                .route().routeId("search-caf")
                .process(camSearchPreProcessor)
                .bean(camSearchService, "getCAMDetails(${body})")
                .streamCaching()
                .to("freemarker:file:/temp/ftls/camSearch.ftl")//problem
                .end().endRest();

我无法在此处使用 ftl 模板,因为它会抛出:

---------------------------------------------------------------------------------------------------------------------------------------
freemarker.template.TemplateNotFoundException: Template not found for name "/temp/ftls/camSearch.ftl".
The name was interpreted by this TemplateLoader: org.apache.camel.component.freemarker.FreemarkerComponent$1@4b35d31f.

【问题讨论】:

    标签: rest apache-camel


    【解决方案1】:

    我认为正确的网址需要一个斜杠:

     .to("freemarker:file://temp/ftls/camSearch.ftl")
    

    即使最正确的是三重斜线。 事实上,完整的语法是“file://host/path”,对于 localhost,可以省略主机。这将导致您的情况

    "file:///temp/ftls/camSearch.ftl"
    

    【讨论】:

    • 三人组做到了。 :)
    【解决方案2】:

    尝试只使用 freemarker 和 ftl 路径。像这样

    freemarker:temp/ftls/camSearch.ftl
    

    【讨论】:

      猜你喜欢
      • 2013-12-04
      • 2019-06-29
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2014-01-19
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多