You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sven Bauhan <sv...@ast.dfs.de> on 2013/03/08 16:28:50 UTC

base class for context component?

Hi,

I'm trying to build my own context component as described in 
http://camel.apache.org/context.html.
I wonder if there is a base class or interface I can use for 
MyContextComponent. I saw there exists org.apache.camel.Component. But 
the method createEndpoint() I have to implement does not make sense for 
a context component.
Is there a better interface for this? Or should i create my own class 
without interface?

Thanks,
Sven Bauhan


Re: base class for context component?

Posted by Taariq Levack <ta...@gmail.com>.
Sven did you see the test[1] that the snippet is from?

I still wonder if this is what you need,  but if you're sure then try to
adapt that test to your application.
The test creates the JNDIRegistry but usually this comes from somewhere
else in the app, and as the docs say you can use JNDI, Spring, Guice or
OSGi etc

Just add this to your registry whatever that is and use the blackbox like
any other endpoint, hiding the details from the caller.

[1]
http://svn.apache.org/viewvc/camel/trunk/components/camel-context/src/test/java/org/apache/camel/component/context/JavaDslBlackBoxTest.java?revision=1069442&view=markup

Taariq


On Wed, Mar 13, 2013 at 5:10 PM, Sven Bauhan <sv...@ast.dfs.de> wrote:

> 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
>
>

Re: base class for context component?

Posted by Sven Bauhan <sv...@ast.dfs.de>.
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


Re: base class for context component?

Posted by Taariq Levack <ta...@gmail.com>.
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.

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);

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

Taariq




On Wed, Mar 13, 2013 at 12:35 PM, Sven Bauhan <sv...@ast.dfs.de> wrote:

> Ok now you lost me completely.
> I do not understand what you want to tell me.
>
> Or did you just explain the source code in http://camel.apache.org/**
> context.html <http://camel.apache.org/context.html> ?
>
> I already understood the code snippets in this explanation. But what is
> missing for me, is how I can put it in a running context.
> Is there a small example that I could investigate to understand how it
> works?
>
> Thanks, Sven
>
>
> On 03/11/13 14:45, Taariq Levack wrote:
>
>> Hi Sven
>>
>> Perhaps you've misunderstood the following...
>> "Defining the context component"
>>
>> In this context(excuse me), what's meant is a bean definition.
>> You should just use the DefaultCamelContext to define your own context,
>> with it's own name as this one is blackbox, and it's own routes.
>>
>> Taariq
>>
>>
>> On Mon, Mar 11, 2013 at 11:21 AM, Sven Bauhan <sv...@ast.dfs.de> wrote:
>>
>>  On 03/09/13 20:40, Henryk Konsek wrote:
>>>
>>>  Hi Sven,
>>>>
>>>>   I'm trying to build my own context component as described in
>>>>
>>>>> http://camel.apache.org/****context.html<http://camel.apache.org/**context.html>
>>>>> <http://camel.**apache.org/context.html<http://camel.apache.org/context.html>
>>>>> >
>>>>> .
>>>>>
>>>>>  Actually Context Component is ready to use out of the box. You don't
>>>> need to create your own. Or if you have to, please share with us the
>>>> reasoning behind this need.
>>>>
>>>> Best regards.
>>>>
>>>>   No, you misunderstood me. I do not want to replace the Context
>>>> Component
>>>>
>>> in Camel, but I need a class to define it. In the example the listing
>>> shows
>>> just the definition of the route without class or method. My questions
>>> concers the place for the definition of DefaultCamelContext. Is there an
>>> interface definition for a class containing a context component?
>>>
>>> Thanks, Sven
>>>
>>>
>>>
>

Re: base class for context component?

Posted by Sven Bauhan <sv...@ast.dfs.de>.
Ok now you lost me completely.
I do not understand what you want to tell me.

Or did you just explain the source code in 
http://camel.apache.org/context.html ?

I already understood the code snippets in this explanation. But what is 
missing for me, is how I can put it in a running context.
Is there a small example that I could investigate to understand how it 
works?

Thanks, Sven

On 03/11/13 14:45, Taariq Levack wrote:
> Hi Sven
>
> Perhaps you've misunderstood the following...
> "Defining the context component"
>
> In this context(excuse me), what's meant is a bean definition.
> You should just use the DefaultCamelContext to define your own context,
> with it's own name as this one is blackbox, and it's own routes.
>
> Taariq
>
>
> On Mon, Mar 11, 2013 at 11:21 AM, Sven Bauhan <sv...@ast.dfs.de> wrote:
>
>> On 03/09/13 20:40, Henryk Konsek wrote:
>>
>>> Hi Sven,
>>>
>>>   I'm trying to build my own context component as described in
>>>> http://camel.apache.org/**context.html<http://camel.apache.org/context.html>
>>>> .
>>>>
>>> Actually Context Component is ready to use out of the box. You don't
>>> need to create your own. Or if you have to, please share with us the
>>> reasoning behind this need.
>>>
>>> Best regards.
>>>
>>>   No, you misunderstood me. I do not want to replace the Context Component
>> in Camel, but I need a class to define it. In the example the listing shows
>> just the definition of the route without class or method. My questions
>> concers the place for the definition of DefaultCamelContext. Is there an
>> interface definition for a class containing a context component?
>>
>> Thanks, Sven
>>
>>


Re: base class for context component?

Posted by Taariq Levack <ta...@gmail.com>.
Hi Sven

Perhaps you've misunderstood the following...
"Defining the context component"

In this context(excuse me), what's meant is a bean definition.
You should just use the DefaultCamelContext to define your own context,
with it's own name as this one is blackbox, and it's own routes.

Taariq


On Mon, Mar 11, 2013 at 11:21 AM, Sven Bauhan <sv...@ast.dfs.de> wrote:

> On 03/09/13 20:40, Henryk Konsek wrote:
>
>> Hi Sven,
>>
>>  I'm trying to build my own context component as described in
>>> http://camel.apache.org/**context.html<http://camel.apache.org/context.html>
>>> .
>>>
>> Actually Context Component is ready to use out of the box. You don't
>> need to create your own. Or if you have to, please share with us the
>> reasoning behind this need.
>>
>> Best regards.
>>
>>  No, you misunderstood me. I do not want to replace the Context Component
> in Camel, but I need a class to define it. In the example the listing shows
> just the definition of the route without class or method. My questions
> concers the place for the definition of DefaultCamelContext. Is there an
> interface definition for a class containing a context component?
>
> Thanks, Sven
>
>

Re: base class for context component?

Posted by Sven Bauhan <sv...@ast.dfs.de>.
On 03/09/13 20:40, Henryk Konsek wrote:
> Hi Sven,
>
>> I'm trying to build my own context component as described in
>> http://camel.apache.org/context.html.
> Actually Context Component is ready to use out of the box. You don't
> need to create your own. Or if you have to, please share with us the
> reasoning behind this need.
>
> Best regards.
>
No, you misunderstood me. I do not want to replace the Context Component 
in Camel, but I need a class to define it. In the example the listing 
shows just the definition of the route without class or method. My 
questions concers the place for the definition of DefaultCamelContext. 
Is there an interface definition for a class containing a context component?

Thanks, Sven


Re: base class for context component?

Posted by Henryk Konsek <he...@gmail.com>.
Hi Sven,

> I'm trying to build my own context component as described in
> http://camel.apache.org/context.html.

Actually Context Component is ready to use out of the box. You don't
need to create your own. Or if you have to, please share with us the
reasoning behind this need.

Best regards.

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com