[GitHub] MarcoLunar opened a new issue #205: Provide example with custom procressor

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] MarcoLunar opened a new issue #205: Provide example with custom procressor

GitBox
MarcoLunar opened a new issue #205: Provide example with custom procressor
URL: https://github.com/apache/camel-k/issues/205
 
 
   Provide example with custom procressor, maybe some bean.
   Is it possible right, now? I have tried inner classes, even anonymous classes, but... exception throws:
   `import org.apache.camel.Exchange;
   import org.apache.camel.Processor;
   import org.apache.camel.builder.RouteBuilder;
   
   public class Sample extends RouteBuilder {
   
       @Override
       public void configure() throws Exception {
           Processor ucp = new Processor() {
   
               public void process(Exchange exchange) throws Exception {
                   String body = exchange.getIn().getBody(String.class);
                   body = body.toUpperCase();
                   exchange.getOut().setBody(body);
               }
           };
           from("timer:tick?period=10s")
                   .setBody(constant("Hello"))
                   .process(ucp)
                   .to("log:info?skipBodyLineSeparator=false");
       }
   
   }`
   
   Exception:
   
   `Exception in thread "main" java.lang.NoClassDefFoundError: Sample$1
    at Sample.configure(Sample.java:10)
    at org.apache.camel.builder.RouteBuilder.includeRoutes(RouteBuilder.java:440)
    at org.apache.camel.builder.RouteBuilder.addRoutes(RouteBuilder.java:599)
    at org.apache.camel.k.jvm.RoutesLoaders$JavaSource$1.configure(RoutesLoaders.java:98)
    at org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:462)
    at org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:402)
    at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:383)
    at org.apache.camel.impl.DefaultCamelContext$1.call(DefaultCamelContext.java:1029)
    at org.apache.camel.impl.DefaultCamelContext$1.call(DefaultCamelContext.java:1026)
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3272)
    at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:1026)
    at org.apache.camel.main.MainSupport.postProcessCamelContext(MainSupport.java:612)
    at org.apache.camel.main.MainSupport.postProcessContext(MainSupport.java:550)
    at org.apache.camel.k.jvm.Runtime.doStart(Runtime.java:98)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.main.MainSupport.run(MainSupport.java:170)
    at org.apache.camel.k.jvm.Application.main(Application.java:65)
   Caused by: java.lang.ClassNotFoundException: Sample$1
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 17 more
   `
   
   I have also tried to use external jar as my dependency. I know about "-d" option, but it uses only maven external repository. I have build my project, maven project and install it into my local repository. But "kamel run -d" is not looking into it... it only looks into repo.maven.apache.org (my jar is mel:cp:12):
   `level=info msg="determine classpath: [mvn -Dmaven.repo.local=/tmp/artifacts/m2 org.apache.camel.k:camel-k-runtime-dependency-lister:0.0.4:generate-dependency-list]"
   [INFO] Scanning for projects...
   [INFO]
   [INFO] ---------< org.apache.camel.k.integration:camel-k-integration >---------
   [INFO] Building camel-k-integration 0.0.4
   [INFO] --------------------------------[ jar ]---------------------------------
   Downloading from central: https://repo.maven.apache.org/maven2/mel/cp/12/cp-12.pom
   [WARNING] The POM for mel:cp:jar:12 is missing, no dependency information available
   Downloading from central: https://repo.maven.apache.org/maven2/mel/cp/12/cp-12.jar
   [INFO] ------------------------------------------------------------------------
   [INFO] BUILD FAILURE
   [INFO] ------------------------------------------------------------------------
   `
   
   Is it possible to use jar from local repo? If so, is it possible to initiate some class (of course implementing Processor) and use it in statement like ".process(objectOfThisSomeClass)"?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services