[英]Apache Camel Spring Boot Java - how can I pass a dynamic value from a rest route to a from file route?
我有一個 Apache Camel REST路線。 我想從Postman調用這個 REST post 路由,我想向它發送包含文件路徑的 JSON 內容。 然后我想讀取該文件路徑以在from file route
的路徑 a 中使用它。
到目前為止,我有這個:
@Component
class RestApi extends RouteBuilder {
@Override
public void configure() {
CamelContext context = new DefaultCamelContext();
restConfiguration()
.contextPath(contextPath)
.port(serverPort)
.enableCORS(true)
.apiContextPath("/api-doc")
.apiProperty("api.title", "Test REST API")
.apiProperty("api.version", "v1")
.apiContextRouteId("doc-api")
.component("servlet")
.bindingMode(RestBindingMode.json);
rest("/api/")
.id("api-route")
.consumes("application/json")
.post("/bean")
.bindingMode(RestBindingMode.json_xml)
.type(MyBean.class)
.to("direct:remoteService");
from("direct:remoteService")
.routeId("direct-route")
.tracing()
.log(">>> ${body.id}")
.log(">>> ${body.name}")
// I tried calling it with "toD"
但它不起作用。
.toD("file://${body.name}?fileName=sources.zip&noop=true&delay=5000&moveFailed=error");
from("file://${body.name}?fileName=sources.zip&noop=true&delay=5000&moveFailed=error")
.tracing()
.log(">>> ${body.id}")
.log(">>> ${body.name}")
.log("Loading zip file ${file:name}")
.split(new ZipSplitter())
.streaming()
.to("direct:another-route");
}
}
我嘗試使用 toD,但出現以下錯誤:
引起:java.lang.IllegalArgumentException:無效目錄:${body.name}。 不允許使用 ${ } 占位符的動態表達式。 使用 fileName 選項設置動態表達式。
我想獲得與 Postman body.name
發送的路徑。 我可以獲得該值,因為它顯示在日志中,然后使用該路徑從文件路徑開始,
from("file://${body.name}?fileName=sources.zip&noop=true&delay=5000&moveFailed=error")
.tracing()
.log(">>> ${body.id}")
.log(">>> ${body.name}")
.log("Loading zip file ${file:name}")
.split(new ZipSplitter())
.streaming()
.to("direct:another-route");
編輯
我嘗試使用 pollEncrich,但我需要傳遞一個變量,該變量是我從 post route ${body.name}
。 如何將該變量傳遞給 pollEnrich 的路由?
我試過這個,但它不起作用:
rest("/api/")
.id("api-route")
.consumes("application/json")
.post("/bean")
.bindingMode(RestBindingMode.json_xml)
.type(MyBean.class)
.to("direct:remoteService");
from("direct:remoteService")
.routeId("direct-route")
.tracing()
.log(">>> ${body.id}")
.log(">>> ${body.name}")
.pollEnrich("file://${body.name}?fileName=sources.zip&noop=true&delay=5000&moveFailed=error")
.split(new ZipSplitter())
.streaming()
.to("direct:process-files");
我收到以下錯誤:
無效目錄:${body.name}。 不允許使用 ${ } 占位符的動態表達式。 使用 fileName 選項設置動態表達式。
請參閱內容豐富器 EIP(文件上的 to 和 toD 是作為新文件寫入)。 您需要使用 pollEnrich(內容豐富器)來加載現有文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.