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 <[email protected]> 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.
>