On 03/13/13 12:50, Taariq Levack wrote:
I got the idea that you really want to define an instance of the
DefaultCamelContext, and not the new class/implementation that you are
asking about.
I did not mean to create a new implementation of DefaultCamelContext. I want to create a class for a context component.


And the docs you referred to discuss this, and it's the example for how to
do so. You can copy that sample and redefine it like this for example...

DefaultCamelContext fooBlackBox = new DefaultCamelContext(registry);
fooBlackBox.setName("fooBlackBox");
fooBlackBox.addRoutes(new RouteBuilder() {
     @Override
     public void configure() throws Exception {
         // receive foo and forward to bar        from("direct:foo").
           to("direct:bar");
     }
});
fooBlackBox.start();

registry.bind("someKey", fooBlackBox);
This is the code snippet I was talking about. For me it is not an example cause I cannot copy it in a .java file and compile it. There is no class or method definition.

I hope I understood you, else lets try again starting with what you
want to accomplish.


Ok, I try to explain what I mean.

First I defined my context component route:

package de.dfs.com.atsm;

import org.apache.camel.ExchangePattern;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JaxbDataFormat;

public class ContextRouteBuilder extends RouteBuilder {

    public void configure() {
        JaxbDataFormat jaxb = new JaxbDataFormat();
        jaxb.setContextPath("de.dfs.com.atsm");
        BeanToMSG atsm_process = new BeanToMSG();
        Aggregation aggregation = new Aggregation();
        from("direct:segment-in")
        .unmarshal(jaxb)
        .process(atsm_process)
.aggregate(header("ATSM-MID"), aggregation).completionPredicate(aggregation)
        .to("direct:message-out");
    }

}

With this I try to make a context component like in the code snippet above:

package de.dfs.com.atsm;

import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.JndiRegistry;

public class ContextComponent {

    private JndiRegistry m_registry;
    private DefaultCamelContext atsm_context;

    public ContextComponent( JndiRegistry registry ) throws Exception {
        this.m_registry = registry;
        this.atsm_context = new DefaultCamelContext(this.m_registry);
        this.atsm_context.setName("ATSM");
        this.atsm_context.addRoutes(new ContextRouteBuilder());
        this.atsm_context.start();
        this.m_registry.bind("atsm", this.atsm_context);
    }

}

With this context component in the library I want to create an application:

package de.dfs.atciss;

import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.main.Main;
import org.apache.camel.util.jndi.JndiContext;

import de.dfs.com.atsm.ContextComponent;
import de.dfs.com.atsm.ContextRouteBuilder;

public class MainApp {

    public static void main(String... args) throws Exception {
//        Main main = new Main();
//        main.enableHangupSupport();
//        DefaultCamelContext atsm_context = new DefaultCamelContext();
//        atsm_context.setName("ATSM");
//        atsm_context.addRoutes(new ContextRouteBuilder());
//        atsm_context.start();
//        main.bind("atsm", atsm_context);
//        main.addRouteBuilder(new ContextRouteBuilder());
//        main.run(args);
        JndiContext context = new JndiContext();
        JndiRegistry registry = new JndiRegistry(context);
        @SuppressWarnings("unused")
        ContextComponent atsm_component = new ContextComponent(registry);
    }

}

Here I fail, cause I don't know how to integrate my context component into an application.
Can you explain, what to do?

Thanks, Sven

Reply via email to