[英]File not Found exception while trying to read file by using Apache-Camel
我有以下代碼從Windows系統讀取文件並將其放在ibm-mq中。 我沒有收到任何錯誤。 但是當我在IBM Queue中檢查消息時,我沒有任何消息。
public class FileToJMS{
public static void main(String args[]) throws Exception
{
final Map headers=new HashMap();
headers.put("xxx","yy");
headers.put("yyy","zzz");
headers.put("xyz","1");
CamelContext camelContext = new DefaultCamelContext();
MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setHostName("zrled201");
try {
connectionFactory.setPort(1234);
connectionFactory.setQueueManager("xxxxx");
connectionFactory.setChannel("channel");
connectionFactory.setTransportType(1);
} catch (JMSException e) {
e.printStackTrace();
}
camelContext.addComponent("wmq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
try {
camelContext.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("file:C:/apche_camel/wmq_inputs/file_Name.xml?noop=true").process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeaders(headers);
}
})
.to("wmq:queue:ESB.ENTRY.SERVICE.IN");
System.out.println("done");
}
});
} catch (Exception e) {
e.printStackTrace();
}
camelContext.start();
Thread.sleep(10000);
camelContext.stop();
}
我已經在控制台上查看了調試信息,我發現了一些類似的東西
[Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.FileEndpoint - Using Generic file
process strategy:
org.apache.camel.component.file.strategy.GenericFileRename
ProcessStrategy@74b7bb95
1691 [Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/JP_SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.strategy.MarkerFileExclusive
ReadLockStrategy - Prepare on startup by deleting orphaned lock
files from: C:\apche_camel\wmq_inputs\SH_TEST_04.xml
1691 [Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.FileConsumer -
Cannot poll as directory does not exists or its not a directory:
C:\apche_camel\wmq_inputs\SH_TEST_04.xml
1691 [Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.FileConsumer - Took
0.000 seconds to poll: C:\apche_camel\wmq_inputs\SH_TEST_04.xml
2197 [Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.FileConsumer -
Cannot poll as directory does not exists or its not a directory:
C:\apche_camel\wmq_inputs\SH_TEST_04.xml
2197 [Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.FileConsumer - Took 0.000 seconds to
poll: C:\apche_camel\wmq_inputs\_H_TEST_04.xml
2696 [Camel (camel-1) thread #0 -
file://C:/apche_camel/wmq_inputs/_SH_TEST_04.xml] DEBUG
org.apache.camel.component.file.FileConsumer - Cannot poll as directory
does not exists or its not a directory:
C:\apche_camel\wmq_inputs\SH_TEST_04.xml
正如可以看到調試信息顯示“沒有這樣的文件或目錄”。 我認為這是權限錯誤,我嘗試使用普通的java代碼,代碼能夠讀取文件sucessfull。 我完全不知道問題出在哪里。 錯過了在mq中放置文件的代碼中的任何內容?
你擁有的uri應該是目錄路徑,沒有文件名。 您可以使用fileName選項指定文件名:
from("file:C:/apche_camel/wmq_inputs?fileName=file_Name.xml&noop=true")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.