You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by livensn <ni...@gmail.com> on 2012/08/21 12:24:40 UTC

Validator component + onException

Hi all,

I got the following camel route :

from("direct:customerroute")
                .log("File was found in directory: " + customersFolder)
                .choice()
                .when(simple("${file:ext} == 'xml' || ${file:ext} ==
'XML'"))
                .log("XML file recognized")
                .to("validator:" + xsdAddress + "/" + customersXsd)
                .to("xslt:" + xslAddress + "/" + customersXsl)
                .unmarshal(jaxbCustomersFormat)
                .process(customerProcessor)
                .end()

Now when a ValidationException occurs, I catch it with the following
configuration :

        onException(Exception.class)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception
{
                        Exception exception = (Exception)
exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
                        LOGGER.error("Unexpected exception!", exception);
                    }
                })
                .to("file://" + errorPath)
                .handled(true);

The exception gets logged perfectly, so the onException works.
But when we come to the part where he wants to delete the original file
after copying it to the error folder, camel throws this exception :
"Renaming file from: ... to: ... failed due cannot delete from file: ...
after copy succeeded"

So I think that this ValidatorProcessor doesn't close the stream to the file
after an exception, and therefor it can't be deleted.

Or I might of configured something wrong / misunderstood something. Any help
would be appreciated :)

Best regards,

Nick



--
View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Validator component + onException

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi Nick,

I'm trying to reproduce the behaviour you've described on a WIN-XP box
however without any success so:

- Would it be possible for you to provide the full stacktrace where file
renaming fails?
- Can you reproduce the problem using the 2.10.1 release?
- Looking at your route you don't make use of the FileConsumer but the
DirectConsumer. So I assume you send a java.io.File object to this consumer
using ProducerTemplate, right? Or is it just a copy&paste typo as you posted
your route to the user forum?

Babak 


livensn wrote
> Hi all,
> 
> I got the following camel route :
> 
> from("direct:customerroute")
>                 .log("File was found in directory: " + customersFolder)
>                 .choice()
>                 .when(simple("${file:ext} == 'xml' || ${file:ext} ==
> 'XML'"))
>                 .log("XML file recognized")
>                 .to("validator:" + xsdAddress + "/" + customersXsd)
>                 .to("xslt:" + xslAddress + "/" + customersXsl)
>                 .unmarshal(jaxbCustomersFormat)
>                 .process(customerProcessor)
>                 .end()
> 
> Now when a ValidationException occurs, I catch it with the following
> configuration :
> 
>         onException(Exception.class)
>                 .process(new Processor() {
>                     public void process(Exchange exchange) throws
> Exception {
>                         Exception exception = (Exception)
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
>                         LOGGER.error("Unexpected exception!", exception);
>                     }
>                 })
>                 .to("file://" + errorPath)
>                 .handled(true);
> 
> The exception gets logged perfectly, so the onException works.
> But when we come to the part where he wants to delete the original file
> after copying it to the error folder, camel throws this exception :
> "Renaming file from: ... to: ... failed due cannot delete from file: ...
> after copy succeeded"
> 
> So I think that this ValidatorProcessor doesn't close the stream to the
> file after an exception, and therefor it can't be deleted.
> 
> Or I might of configured something wrong / misunderstood something. Any
> help would be appreciated :)
> 
> Best regards,
> 
> Nick





--
View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756p5719718.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Validator component + onException

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Just for the record. I have logged a ticket to get this fixed in the future
https://issues.apache.org/jira/browse/CAMEL-5608

On Tue, Aug 21, 2012 at 2:13 PM, livensn <ni...@gmail.com> wrote:
> As you said, I updated to the most recent version (2.10.0) through maven, but
> this didn't do the job. :)
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756p5717767.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Validator component + onException

Posted by livensn <ni...@gmail.com>.
As you said, I updated to the most recent version (2.10.0) through maven, but
this didn't do the job. :)




--
View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756p5717767.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Validator component + onException

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Aug 21, 2012 at 1:12 PM, livensn <ni...@gmail.com> wrote:
> Hi,
>
> I'm using Windows 7.
> The .converBodyTo(String.class) part worked :)
>

Good to know.

What Camel versions do you use?
Would like to have it working out of the box, and we may have fixed
that in a recent release.


> Thank you Claus!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756p5717764.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Validator component + onException

Posted by livensn <ni...@gmail.com>.
Hi,

I'm using Windows 7.
The .converBodyTo(String.class) part worked :)

Thank you Claus!



--
View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756p5717764.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Validator component + onException

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

What OS and Camel version are you using?
And have you tried upgrading to newer releases?
And you can also try to load the content into memory before the
validator, eg using a .convertBodyTo(String.class) etc.


On Tue, Aug 21, 2012 at 12:24 PM, livensn <ni...@gmail.com> wrote:
> Hi all,
>
> I got the following camel route :
>
> from("direct:customerroute")
>                 .log("File was found in directory: " + customersFolder)
>                 .choice()
>                 .when(simple("${file:ext} == 'xml' || ${file:ext} ==
> 'XML'"))
>                 .log("XML file recognized")
>                 .to("validator:" + xsdAddress + "/" + customersXsd)
>                 .to("xslt:" + xslAddress + "/" + customersXsl)
>                 .unmarshal(jaxbCustomersFormat)
>                 .process(customerProcessor)
>                 .end()
>
> Now when a ValidationException occurs, I catch it with the following
> configuration :
>
>         onException(Exception.class)
>                 .process(new Processor() {
>                     public void process(Exchange exchange) throws Exception
> {
>                         Exception exception = (Exception)
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
>                         LOGGER.error("Unexpected exception!", exception);
>                     }
>                 })
>                 .to("file://" + errorPath)
>                 .handled(true);
>
> The exception gets logged perfectly, so the onException works.
> But when we come to the part where he wants to delete the original file
> after copying it to the error folder, camel throws this exception :
> "Renaming file from: ... to: ... failed due cannot delete from file: ...
> after copy succeeded"
>
> So I think that this ValidatorProcessor doesn't close the stream to the file
> after an exception, and therefor it can't be deleted.
>
> Or I might of configured something wrong / misunderstood something. Any help
> would be appreciated :)
>
> Best regards,
>
> Nick
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validator-component-onException-tp5717756.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen