2013-01-16 3 views
2

I 낙타 유효성 검사 오류 메시지

<route> 
    <from uri="target/in"/> 
    <doTry> 
     <to uri="validator:schema.xsd"/> 
     <to uri="file:target/messages/validation/valid?fileName=a.xml"/> 
     <doCatch> 
      <exception>org.apache.camel.ValidationException</exception>    
      <to uri="file:target/messages/validation/invalid?fileName=a.xml"/> 
     </doCatch> 
    </doTry> 
</route> 

낙타

에서 다음 경로 내가 XML 파일이 게시물

http://camel.465427.n5.nabble.com/XML-Validation-getting-to-the-error-messages-using-Camel-td4768229.html

에서와 같이 유효성 검사를 통과하지 않을 때 오류 메시지가 할이 하지만 스프링 DSL에서는 어떻게해야합니까?

답변

2

처럼 클로스는 참조 스레드 상태 :

예외 원인 = exchange.getProperty (Exchange.EXCEPTION_CAUGHT, Exception.class);

그래서,이 경로가 예외를 저장해야합니다 : 당신이 당신의 샘플 코드와 같이 파일에 예외 정보를 저장하려면

<route> 
    <from uri="target/in"/> 
    <doTry> 
     <to uri="validator:schema.xsd"/> 
     <to uri="file:target/messages/validation/valid?fileName=a.xml"/> 
     <doCatch> 
      <exception>org.apache.camel.ValidationException</exception>  
      <transform> 
       <simple>${property.CamelExceptionCaught}</simple> 
      </transform 
      <to uri="file:target/messages/validation/invalid?fileName=a.xml"/> 
     </doCatch> 
    </doTry> 
</route> 
+0

감사합니다. 그것은 메시지를 다시 보냅니다. 그러나 그것은 내가 기대했던 메시지가 아닙니다. 나는 비누를 받고 있어요 : 서버 파일을 저장할 수 없습니다 : 대상 \ 메시지 \ 검증 \의 무효를 \ a.xml 예외가 후 다른 폴더에있는 XML 파일을 배치에 문제가 던져? – Graham

0

을, 당신은 문자열로 변환해야합니다. 그렇지 않으면 Camel이 스키마 유효성 검사 예외를 java.io.inputStream으로 변환 할 수 없으므로 파일에 대한 또 다른 예외가 발생합니다.

<route> 
    <from uri="target/in"/> 
    <doTry> 
     <to uri="validator:schema.xsd"/> 
     <to uri="file:target/messages/validation/valid?fileName=a.xml"/> 
     <doCatch> 
      <exception>org.apache.camel.ValidationException</exception>  
      <transform> 
       <simple>${property.CamelExceptionCaught}</simple> 
      </transform> 
      <transform> 
       <simple>${bodyAs(String)}</simple> 
      </transform> 
      <to uri="file:target/messages/validation/invalid?fileName=a.xml"/> 
     </doCatch> 
    </doTry> 
</route> 
0

하나의 파일에서 예외를 보내고 다른 하나에서는 잘못된 xml을 보낼 수 있습니다.

<route> 
    <from uri="target/in"/> 
    <doTry> 
     <to uri="validator:schema.xsd"/> 
     <to uri="file:target/messages/validation/valid?fileName=a.xml"/> 
     <doCatch> 
      <exception>org.apache.camel.ValidationException</exception> 
      <setHeader headerName="CamelOverruleFileName"> 
       <simple>${file:onlyname.noext}.${date:now:yyyyMMdd_HHmmssSSS}.xml</simple> 
      </setHeader> 
      <to uri="file:target/messages/validation/invalid/"/> 
      <setBody> 
       <simple>Got "${exception.message}" with this stack\n${exception.stacktrace}\n${body}</simple> 
      </setBody> 
      <setHeader headerName="CamelOverruleFileName"> 
       <simple>${file:onlyname.noext}.${date:now:yyyyMMdd_HHmmssSSS}.xml.error</simple> 
      </setHeader> 
      <to uri="file:target/messages/validation/invalid/"/> 
     </doCatch> 
    </doTry> 
</route> 
관련 문제