Bindy running within a WAR

classic Classic list List threaded Threaded
11 messages Options
Ted
Reply | Threaded
Open this post in threaded view
|

Bindy running within a WAR

Ted
Hi,

I have a self executable Spring Boot (1.2.2) and Camel Boot (2.15.0) application built as a WAR.  My route makes use of Bindy to unmarshal CSV to my object class.  Everything work well when I run the code directly using Maven (mvn spring-boot:run) or if I run using Eclipse.  However if I build my WAR file and execute that (java -jar myWebApp.war) then I get errors

java.lang.IllegalArgumentException: The separator has not been defined in the annotation @CsvRecord or not instantiated during initModel. must be specified
        at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:293)
        at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:137)
        at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:67)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
        at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)


In the Camel/Bindy code I can see that DefaultPackageScanClassResolver.loadImplementationsInJar obviously has special provision for jar files but what about the equivalent for WAR files?  Class files are located under WEB-INF in war files which means my annotated classes are not being found.  See method DefaultPackageScanClassResolver.doLoadImplementationsInJar where the code is attempting to find classes that start with a particular package but will never find any because the file locations include WEB-INF, which would not be the case with a jar file.

Is there another way of doing this or does Bindy need fixing?
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

Claus Ibsen-2
Hi

What web server do you use for the War? Is it jetty or tomcat or something else?

Yeah bindy unfortunately uses that annotation scanning on classpath.
There is a ticket to improve this for the future.
You can impement a custom yourself that can load in the WAR.
http://camel.apache.org/pluggable-class-resolvers.html

On Mon, Mar 30, 2015 at 5:06 PM, Ted <[hidden email]> wrote:

> Hi,
>
> I have a self executable Spring Boot (1.2.2) and Camel Boot (2.15.0)
> application built as a WAR.  My route makes use of Bindy to unmarshal CSV to
> my object class.  Everything work well when I run the code directly using
> Maven (mvn spring-boot:run) or if I run using Eclipse.  However if I build
> my WAR file and execute that (java -jar myWebApp.war) then I get errors
>
> java.lang.IllegalArgumentException: The separator has not been defined in
> the annotation @CsvRecord or not instantiated during initModel. must be
> specified
>         at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:293)
>         at
> org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:137)
>         at
> org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:67)
>         at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
>         at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at
> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
>         at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129)
>         at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
>         at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>
>
> In the Camel/Bindy code I can see that
> DefaultPackageScanClassResolver.loadImplementationsInJar obviously has
> special provision for jar files but what about the equivalent for WAR files?
> Class files are located under WEB-INF in war files which means my annotated
> classes are not being found.  See method
> DefaultPackageScanClassResolver.doLoadImplementationsInJar where the code is
> attempting to find classes that start with a particular package but will
> never find any because the file locations include WEB-INF, which would not
> be the case with a jar file.
>
> Is there another way of doing this or does Bindy need fixing?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Bindy-running-within-a-WAR-tp5765035.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
Ted
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

Ted
Thanks, I've created a PackageScanClassResolver for my project that works with WAR files.

In the documentation http://camel.apache.org/pluggable-class-resolvers.html it says I simply need to create a spring bean but when I tried the bean was never referenced.  I had a quick look in DefaultCamelContext and SpringCamelContext but all I could see was a hard coded reference to the DefaultPackageScanClassResolver.  My Spring config looks like this:

        @Bean
        BeltPackageScanClassResolver beltResolver() {
                BeltPackageScanClassResolver resolver = new BeltPackageScanClassResolver();

                return resolver;
        }

Am I missing something?
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

Claus Ibsen-2
That is for using spring xml, with <camelContext>.

On Tue, Mar 31, 2015 at 12:59 PM, Ted <[hidden email]> wrote:

> Thanks, I've created a PackageScanClassResolver for my project that works
> with WAR files.
>
> In the documentation http://camel.apache.org/pluggable-class-resolvers.html
> it says I simply need to create a spring bean but when I tried the bean was
> never referenced.  I had a quick look in DefaultCamelContext and
> SpringCamelContext but all I could see was a hard coded reference to the
> DefaultPackageScanClassResolver.  My Spring config looks like this:
>
>         @Bean
>         BeltPackageScanClassResolver beltResolver() {
>                 BeltPackageScanClassResolver resolver = new
> BeltPackageScanClassResolver();
>
>                 return resolver;
>         }
>
> Am I missing something?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Bindy-running-within-a-WAR-tp5765035p5765077.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
Ted
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

Ted
Okay, thanks Claus.
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

RaviP
I'm facing the similar issue with my war.  I'm using wildfly 8.2.0 & Camel 2.14.1.  My route uses bindy to unmarshal csv to domain object. Junits are working & war deployed on tomcat also works.

I'm getting the following exception when i deploy the war on wildfly 8.2.0

java.lang.IllegalArgumentException: The separator has not been defined in
the annotation @CsvRecord or not instantiated during initModel. must be
specified.

I see that a solution recommended was to use PackageScanClassResolver.

Can you please tell me how to do that incase of wildfly ?  Do i've to add additional dependencies.

thanks
Ravi.
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

Charles Moulliard-2
Hi Ravi,

Have you tried to use the camel bindy "module" instead of packaging all the
deps within the war file (
http://wildflyext.gitbooks.io/wildfly-camel/content/components/camel-bindy.html,
http://wildflyext.gitbooks.io/wildfly-camel/content/start/index.html) ?

Regards,

On Mon, Apr 13, 2015 at 7:34 PM, RaviP <[hidden email]>
wrote:

> I'm facing the similar issue with my war.  I'm using wildfly 8.2.0 & Camel
> 2.14.1.  My route uses bindy to unmarshal csv to domain object. Junits are
> working & war deployed on tomcat also works.
>
> I'm getting the following exception when i deploy the war on wildfly 8.2.0
>
> java.lang.IllegalArgumentException: The separator has not been defined in
> the annotation @CsvRecord or not instantiated during initModel. must be
> specified.
>
> I see that a solution recommended was to use PackageScanClassResolver.
>
> Can you please tell me how to do that incase of wildfly ?  Do i've to add
> additional dependencies.
>
> thanks
> Ravi.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Bindy-running-within-a-WAR-tp5765035p5765711.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

RaviP
I tried deploying the war in ... wildfly-camel-patch option ...I'm getting LinkageError exception

I'm using ContextLoaderListener to load the camel context.

                 <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-web</artifactId>
                        <version>4.1.5.RELEASE</version>
                </dependency>

wildfly-camel-patch also contains 4.1.5.RELEASE.

thanks
Ravi.
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR, widlfly 8.2.0 and Camel

sanjay.gautam
This post was updated on .
In reply to this post by Charles Moulliard-2
Hi

I am also facing the same issue , I looked at the code and looks like that here is exactly the issue

Class Name : BindyCsvDataFormat
at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.


BindyCsvFactory factory = (BindyCsvFactory)getFactory(exchange.getContext().getPackageScanClassResolver());
        ObjectHelper.notNull(factory, "not instantiated");

        // List of Pojos
        List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();

        // Pojos of the model
        Map<String, Object> model;

        InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));

        // Scanner is used to read big file
        Scanner scanner = new Scanner(in);

        // Retrieve the separator defined to split the record
        String separator = factory.getSeparator();
        String quote = factory .getQuote();

Please let me know why the factory is not getting populated with the seperator even though I have defined it correctly .


ERROR
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:293) [camel-core-2.15.0.jar:2.15.0]
        at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:137) [camel-bindy-2.15.0.jar:2.15.0]
        at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:67) [camel-core-2.15.0.jar:2.15.0]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.15.0.jar:2.15.0]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448) [camel-core-2.15.0.jar:2.15.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.15.0.jar:2.15.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) [camel-core-2.15.0.jar:2.15.0]
Reply | Threaded
Open this post in threaded view
|

Re: Bindy running within a WAR

RaviP
In reply to this post by RaviP
I've moved on by changing it to beanio.  

thanks
Ravi.
Reply | Threaded
Open this post in threaded view
|

RE: Bindy running within a WAR

Bonnet Benjamin
In reply to this post by RaviP
Hi,
If you use it inside jBoss/wildfly, you should use jboss package scan class resolver. See camel-extra (https://code.google.com/a/apache-extras.org/p/camel-extra/).
Regards

-----Message d'origine-----
De : RaviP [mailto:[hidden email]]
Envoyé : lundi 13 avril 2015 19:35
À : [hidden email]
Objet : Re: Bindy running within a WAR

I'm facing the similar issue with my war.  I'm using wildfly 8.2.0 & Camel 2.14.1.  My route uses bindy to unmarshal csv to domain object. Junits are working & war deployed on tomcat also works.

I'm getting the following exception when i deploy the war on wildfly 8.2.0

java.lang.IllegalArgumentException: The separator has not been defined in the annotation @CsvRecord or not instantiated during initModel. must be specified.

I see that a solution recommended was to use PackageScanClassResolver.

Can you please tell me how to do that incase of wildfly ?  Do i've to add additional dependencies.

thanks
Ravi.



--
View this message in context: http://camel.465427.n5.nabble.com/Bindy-running-within-a-WAR-tp5765035p5765711.html
Sent from the Camel - Users mailing list archive at Nabble.com.