You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by hong5858 <to...@optonline.net> on 2016/05/03 14:30:48 UTC

Re: Camel BeanIO catch and ignore InvalidRecordException

I have the same issue. I am using beanio to unmarshal a file with delimited
records and need to catch invalid records while proceeding the remaining
file. Is there a way to register a custom error handler?

Thanks
Thomas



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-BeanIO-catch-and-ignore-InvalidRecordException-tp5762999p5782120.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel BeanIO catch and ignore InvalidRecordException

Posted by Brad Johnson <br...@mediadriver.com>.
I'm not sure if this would work for your specific case but recently I
created an emitter that took a GenericFile from Camel, read the BeanIO
format in from the bundle, and then read record at a time.  I wasn't
looking to catch malformed records so the method throws any exceptions. The
init method has that odd looking check from the actual method called from
Camel because I'm in blueprint/OSGi and if I called the init from Blueprint
the classloader context wasn't right.   The way that is used in a Camel
routes is.  The reader is just sending those to the processQueue which I
inject into the bean with @EndpointInject.  In this case I use a SEDA queue
but you could use pretty much anything.  If you put a try catch around the
read you could have a second errorQueue that you send the results to.  I'm
not sure what you'd get exactly but it should put you on your way.

        <!-- Publish beans to the process queues based on input file -->
        <route id="process.ahs.paymentech.route">
            <from uri="{{batch.local.inbox}}" />
            <bean ref="beanProducer" method="publishBeans" />
        </route>


    public void init() throws IOException {

        // create a StreamFactory
        factory = StreamFactory.newInstance();
    //The format in Blueprint is in the resources directory in Maven which
ends up in the root of the jar file.  I create a subfolder in resources for
my data formats.

        InputStream inStream = new
java.io.BufferedInputStream(MyClass.class.getClassLoader().getResourceAsStream("dataformats/my-format.xml"));
        factory.load(inStream);

        initialized=true;

    }

    public void publishBeans(GenericFile file) throws IOException
    {
        if(!initialized) init();
        BeanReader in = factory.createReader("myFileFormat",
file.getAbsoluteFilePath());
        Object o;

        while ((o = in.read()) != null) {

            processQueue.sendBody(o);

        }

        in.close();


    }

On Wed, May 4, 2016 at 7:46 AM, hong5858 <to...@optonline.net> wrote:

> by catching the error records I meant to get a chance to write them to a
> file.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-BeanIO-catch-and-ignore-InvalidRecordException-tp5762999p5782171.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Camel BeanIO catch and ignore InvalidRecordException

Posted by hong5858 <to...@optonline.net>.
by catching the error records I meant to get a chance to write them to a
file. 



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-BeanIO-catch-and-ignore-InvalidRecordException-tp5762999p5782171.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel BeanIO catch and ignore InvalidRecordException

Posted by hong5858 <to...@optonline.net>.
understood there are options to ignore errors but what I need is to catch
those records and continue proceeding the rest.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-BeanIO-catch-and-ignore-InvalidRecordException-tp5762999p5782170.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel BeanIO catch and ignore InvalidRecordException

Posted by Brad Johnson <br...@mediadriver.com>.
ignoreUnidentifiedRecords=true

Can be set on the stream. Obviously that means you have to know you want to
simply ignore records that it can't parse.

On Tue, May 3, 2016 at 11:30 AM, Claus Ibsen <cl...@gmail.com> wrote:

> I logged a ticket to allow to plugin a custom error handler from beanio.
> https://issues.apache.org/jira/browse/CAMEL-9939
>
> But you can configure the default to ignore various errors. There is
> those 3 options, see the configuration class from camel-beanio - eg
> BeanIOConfiguration.
>
> On Tue, May 3, 2016 at 2:30 PM, hong5858 <to...@optonline.net> wrote:
> > I have the same issue. I am using beanio to unmarshal a file with
> delimited
> > records and need to catch invalid records while proceeding the remaining
> > file. Is there a way to register a custom error handler?
> >
> > Thanks
> > Thomas
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Camel-BeanIO-catch-and-ignore-InvalidRecordException-tp5762999p5782120.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: Camel BeanIO catch and ignore InvalidRecordException

Posted by Claus Ibsen <cl...@gmail.com>.
I logged a ticket to allow to plugin a custom error handler from beanio.
https://issues.apache.org/jira/browse/CAMEL-9939

But you can configure the default to ignore various errors. There is
those 3 options, see the configuration class from camel-beanio - eg
BeanIOConfiguration.

On Tue, May 3, 2016 at 2:30 PM, hong5858 <to...@optonline.net> wrote:
> I have the same issue. I am using beanio to unmarshal a file with delimited
> records and need to catch invalid records while proceeding the remaining
> file. Is there a way to register a custom error handler?
>
> Thanks
> Thomas
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-BeanIO-catch-and-ignore-InvalidRecordException-tp5762999p5782120.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2