Bazı istekler için dosyaları iade etmesi gereken RESTful servisini (CXFRS bileşenini kullanarak) uyguluyorum. Her dosya kendi kimliği ve uzantısıyla, yani restfulservice.com/path/file/1/pdf
ile getirilir. Eklenen her dosya hiçbir zaman değişmez. Dosyalar getirildikten sonra taşınmamalı veya silinmemeli ve genellikle eşzamanlı olarak erişilebilir olmalıdır. İşte benim Deve bağlamında bir parçasıdır:Apache Camel, istek üzerine dosya içeriğiyle zenginleştirilmiş bir mesaj zenginleştiriyor
from("direct:fetchFile")
.process(fetchFileProcessor) // set file.id & file.extension
.bean(fileService, "fetchFile(${header.file.id}, ${header.file.extension})") // set body to filename
.setHeader("CamelFileName", simple("${body}"))
.choice()
.when(header("file.extension").isEqualTo("xml"))
.pollEnrich("file:///{{application.fileStorage.basePath}}/xml?noop=true", 500)
.when(header("file.extension").isEqualTo("pdf"))
.pollEnrich("file:///{{application.fileStorage.basePath}}/pdf?noop=true", 500)
.end()
.convertBodyTo(File.class)
.bean(responseProvider, "getResponse(${body}, 200)");
bu yapılandırmayla sorun yanıt zaman aşımı seti hizmeti olmadan, sadece ikinci (? Neden) istek için boş olmayan vücut olmasıdır hata ayıklama ile ikinci istek üzerine sonsuz döngü girer mesajı
DEBUG o.a.c.c.f.FileConsumer - Took 0.000 seconds to poll <base path>\xml
Apace Deve sürüm 2.10.4
olduğunu Herhangi bir yardım mutluluk duyacağızUPD1:
sayfasında 'pollEnrich şu anki Exchange'den veriye erişmiyor' uyarısında bulunuyor. Bu pollEnrich gibi görünüyor
URL'ye (link) belirtilen dinamik fileName
desteklemez: Ben URL'yi
UPD2 dosyaya fileName=${body}
eklerseniz Ama hiçbir şey değiştirir. Geçerli anda Güzergah:
from("direct:fetchFile")
.process(fetchFileProcessor) // set file.id & file.extension
.bean(fileService, "fetchFile(${header.file.id}, ${header.file.extension})") // set body to filename
.choice()
.when(header("file.extension").isEqualTo("xml"))
.pollEnrich("file:///{{application.fileStorage.basePath}}/xml?fileName=${body}&noop=true", 500)
.setHeader("asset.type", simple(MediaType.APPLICATION_XML))
.when(header("file.extension").isEqualTo("pdf"))
.pollEnrich("file:///{{application.fileStorage.basePath}}/pdf?fileName=${body}&noop=true", 500)
.setHeader("asset.type", simple("application/pdf"))
.end()
.convertBodyTo(File.class)
.process(multipartProcessor) // add file ass attachment to multipart body and set it as body
.bean(responseProvider, "getResponse(${body}, 200)");
UPD3
Ben dinamik dosya adları ile PollingConsumer kullanmak için özel işlemci uygulamaya çalışıyorum:
@Override
public void process(Exchange exchange) throws Exception {
Long timeout = exchange.getIn().getHeader("file.timeout", Long.class);
if (enrichUri == null) {
throw new FileNotFoundException("'file.url' header not set");
}
CamelContext context = exchange.getContext();
Endpoint endpoint = context.getEndpoint(enrichUri);
PollingConsumer consumer = endpoint.createPollingConsumer();
consumer.start();
Exchange consumedExchange;
try {
if (timeout == null || timeout < 0) {
consumedExchange = consumer.receive();
} else if (timeout == 0) {
consumedExchange = consumer.receiveNoWait();
} else {
consumedExchange = consumer.receive(timeout);
}
} catch (Exception e) {
throw new AssetNotFoundException(e);
} finally {
consumer.stop();
}
exchange.getIn().setBody(consumedExchange.getIn().getBody());
}
Şimdi ilk tepkisi üzerinde dosya içeriğini döndürür, Ancak her bir istek üzerine, günlük iletilerinin sonsuz döngüsüne sahibim:
UPD4
İşleme başlamadan önce eklenmiş ve sonrasında kaldırılan dinamik bir yol gerçekleştirdim. Bu yöntem Apache Camel forumunda this yayınında açıklanmıştır. Rota, dosyayı tüketmek için yukarıdaki işlemciyi kullanır. Sonuç aynı
gibi çalışıyor: Ben işlemci şu bu durumda Apache Camel dosya bileşeni ile başa çıkmak için çöp ve uygulanan? PollEnrich'e özel bir işlemci geçirmenin bir yolu var mı? – pimlottc