Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide example with custom processor #205

Closed
MarcoLunar opened this issue Nov 8, 2018 · 6 comments
Closed

Provide example with custom processor #205

MarcoLunar opened this issue Nov 8, 2018 · 6 comments

Comments

@MarcoLunar
Copy link

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)"?

@lburgazzoli
Copy link
Contributor

can you try with a lamda ?

from("timer:tick?period=10s")
            .setBody(constant("Hello"))
            .process(e -> { ... })
            .to("log:info?skipBodyLineSeparator=false");

At the moment camel-k requires dependencies to be available in maven central but there's plans to support local dependencies.

@MarcoLunar MarcoLunar changed the title Provide example with custom procressor Provide example with custom processor Nov 8, 2018
@MarcoLunar
Copy link
Author

Yes, lambda works :)

[Camel (camel-1) thread #2 - timer://tick] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: HELLO]

This Java code works:

`public class Sample extends RouteBuilder {

@Override
public void configure() throws Exception {
    from("timer:tick?period=10s")
            .setBody(constant("Hello"))
            .process(exchange -> {
                String body = exchange.getIn().getBody(String.class);
                body = body.toUpperCase();
                exchange.getOut().setBody(body);
            })
            .to("log:info?skipBodyLineSeparator=false");
}

}
`

Thank you!

@gdubya
Copy link

gdubya commented Nov 14, 2018

At the moment camel-k requires dependencies to be available in maven central but there's plans to support local dependencies.

Is it possible to use a local mirror instead of central?

@lburgazzoli
Copy link
Contributor

Not yet but it will be possible

@lburgazzoli
Copy link
Contributor

@gdubya you can now set a custom registry

@lburgazzoli
Copy link
Contributor

Nested class issue fixed by jOOR, see jOOQ/jOOR#71.
Waiting for a new release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants