camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Full example of configuring endpoints in pure Java (without uri strings)
Date Fri, 04 Aug 2017 11:42:09 GMT
Hi

Yeah you can run Camel standalone with that main class or do it by yourself.

One comment is that when you create the CxfEndpoint then you need to
set the CxfComponent on this instance as well.

Ideally you create the endpoints via the uri syntax, or via the component.

For some camel components then they rely on the component for the
endpoints,producers,consumers etc such as JMS, Jetty, and possible
CXF.

So a good rule of thumb is to create endpoints via their components.
Afterwards you can tweak then via their getter/setters.

In the future we will have some tooling to auto generate a builder
style Java DSL for the endpoints so you can configure them in a type
safe manner via java code. That is on the roadmap for 3.x.

On Wed, Aug 2, 2017 at 6:47 PM, Oliver Doepner <odoepner@gmail.com> wrote:
> Hello,
>
> I am trying to use Camel using the pure Java approach (Java DSL, no DI
> framework, no URI Strings).
>
> My approach so far is like the simplistic sample below, but I am not sure
> if it uses proper practices.
>
> Can you please let me know if/what problems you see with this approach?
> Is there maybe documentation somewhere with a full "pure Java" example?
>
> Thank you
> Oliver
>
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.cxf.CxfComponent;
> import org.apache.camel.component.cxf.CxfEndpoint;
> import org.apache.camel.main.Main;
> import org.apache.camel.main.MainListenerSupport;
>
> public class CamelExample {
>
>     public static void main(String... args) throws Exception {
>
>         final Main main = new Main();
>
>         main.addMainListener(new MainListenerSupport() {
>             @Override
>             public void configure(CamelContext context) {
>                 context.addComponent("cxf", new CxfComponent());
>
>                 final CxfEndpoint webService = new CxfEndpoint();
>                 webService.setCamelContext(context);
>                 webService.setAddress("http://service/entity");
>                 webService.setServiceClass(MyService.class);
>                 webService.setDefaultOperationName("test");
>                 // etc
>
>                 Processor requestPreparation = new Processor() {
>                     @Override
>                     public void process(Exchange exchange) throws Exception
> {
>                         exchange.getIn().setBody(new MyServiceRequest());
>                     }
>                 };
>
>                 main.addRouteBuilder(
>                         new RouteBuilder() {
>                             @Override
>                             public void configure() throws Exception {
>                                 from("direct:start")
>                                         .process(requestPreparation)
>                                         .to(webService);
>                             }
>                         }
>                 );
>             }
>         });
>
>         main.run();
>     }
>
>     /* web service related classes stubbed out to keep example code simple
> */
>
>     private static final class MyService {};
>     private static final class MyServiceRequest {};
>
> }
>
>
>
> --
> Oliver Doepner
> Software Developer
> IMP Solutions, Halifax, NS
> Phone 1-902-482-1615
>
>
>
> --
> Oliver Doepner
> Halifax, Nova Scotia
> http://oliver.doepner.net/
> Buchstabensalat : ßäöüÄÖÜ



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

Mime
View raw message