我尝试使用Apache Camel REST DSL,以便使用HTTP Accept标头返回资源的不同表示形式(xml,html,pdf)。
以下是我的代码的当前状态,它总是返回pdf表示,客户端发送的是Accept:text / html,application / xml或application / pdf。
rest("/bpcg").description("BPCG rest service")
.bindingMode(RestBindingMode.auto)
.get("/{id}").description("Find BPCG by id").outType(String.class)
.produces("application/xml")
.param().name("id").type(path).description("The id of the BPCG to get").dataType("int").endParam()
.to("bean:bpcgService?method=getBPCG(${header.id})")
.produces("text/html")
.param().name("id").type(path).dataType("int").endParam()
.route()
.to("bean:bpcgService?method=getBPCG(${header.id})")
.to("xslt:com/connectivia/cie/spec/xslt/CIE - Business partner companion guide to HTML for Confluence.xsl")
.endRest()
.produces("application/pdf")
.param().name("id").type(path).dataType("int").endParam()
.route().to("bean:bpcgService?method=getBPCG(${header.id})")
.to("xslt:com/connectivia/cie/spec/xslt/CIE - Business partner companion guide to PDF.xsl")
.to("xslt:com/connectivia/cie/spec/xslt/CIE - PDF Style Applier.xsl")
.to("bean:converter?method=ConvertXmlFoToPDF(${body})")
.endRest()