2012-07-26 84 views
3

我試圖建立一個嘗試驗證xml的路線,如果一切正確,然後必須拆分這個文件,否則引發異常,它必須做別的事情。所以,我做了以下內容:駱駝 - 拆分()和doCatch(....)不起作用

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}") 
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue) 
    .doTry() 
     .to("validator:classpath:"+validator) 
     .split(xPathMessageTypeSplit) 
     .to("jms:"+queue+"?jmsMessageType=Text") 
    .doCatch(ValidationException.class) 
     .log(LoggingLevel.INFO, "Validation Exception for message ${body}") 
     .to("xslt:classpath:"+transformationsErrorAfter) 
     .split(xPathNotificationSplit) 
     .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2") 
    .end(); 

不過,這並不編譯(如果我不使用分割,然後它編譯和作品)和錯誤是:

The method doCatch(Class<ValidationException>) is undefined for the type ExpressionNode 

所以我嘗試以下

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}") 
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue) 
    .doTry() 
     .to("direct:validate") 
    .doCatch(ValidationException.class) 
     .log(LoggingLevel.INFO, "Validation Exception for message ${body}") 
     .to("xslt:classpath:"+transformationsErrorAfter) 
     .split(xPathNotificationSplit) 
     .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2") 
    .end(); 

    from("direct:validate") 
     .to("validator:classpath:"+validator) 
     .to("direct:split_message"); 

    from("direct:split_message") 
     .split(xPathMessageTypeSplit) 
     .to("jms:"+queue+"?jmsMessageType=Text"); 

這一次,我得到重複的端點的錯誤

org.apache.camel.FailedToStartRouteException: Failed to start route route312 because of Multiple consumers for the same endpoint is not allowed: Endpoint[direct://validate] 

你對如何解決這個問題有什麼想法嗎?

+0

如果你把'.END()發生'了'.doCatch'之前? – 2012-08-05 22:59:58

回答

1

你的第二次嘗試似乎很好。你得到的錯誤是由兩條以from("direct:validate") 開頭的路由引起的。你的應用中沒有其他路由消耗同一個端點嗎?

編輯:嘗試以不同的名字,也許驗證已經存在(在您的應用程序或內部駱駝)

+0

no .. from(「direct:validate」)是我在路線中唯一的一個 – ddelizia 2012-07-26 12:51:50

+0

也許嘗試以不同的方式命名它,只是看到 – cexbrayat 2012-07-26 13:07:47

+0

我試着用另一個名字,但我得到了同樣的錯誤 – ddelizia 2012-07-26 13:32:59

5

爲了從分裂(我們回到doTry()塊)塊(或選擇或其他嵌套類型),你需要使用endDoTry()。與其名稱相反,此方法將結束嵌套拆分塊並返回到doTry()DSL。

我會用你貼有這些變化,第一條路線:

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}") 
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue) 
    .doTry() 
     .to("validator:classpath:"+validator) 
     .split(xPathMessageTypeSplit) 
      .to("jms:"+queue+"?jmsMessageType=Text") 
     .endDoTry() 
    .doCatch(ValidationException.class) 
     .log(LoggingLevel.INFO, "Validation Exception for message ${body}") 
     .to("xslt:classpath:"+transformationsErrorAfter) 
     .split(xPathNotificationSplit) 
      .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2") 
     .endDoTry() 
    .end();