camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Doepner <odoep...@gmail.com>
Subject Full example of configuring endpoints in pure Java (without uri strings)
Date Wed, 02 Aug 2017 16:47:05 GMT
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 : ßäöüÄÖÜ

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message