You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ndjensen <nd...@gmail.com> on 2008/11/20 20:37:30 UTC

jetty endpoints in different camel contexts

Hi,

On Camel 1.5.0, it seems like you can't have multiple jetty endpoints in
separate camel contexts on the same port.  For example, if I have the
following routes,

<route id="exampleRouteOne">
        <from uri="jetty:http://0.0.0.0:8080/services/doSomething" />
	<bean ref="someService" method="doSomething" />
</route>

<route id="exampleRouteTwo">
	<from uri="jetty:http://0.0.0.0:8080/services/foo" />
        <bean ref="someBean" method="processRequest" />
</route>


it works great when they're in the same camel context, but throws the
following exception at startup of the second address when they're not.



INFO  log                            - Started
SelectChannelConnector@0.0.0.0:8080
INFO  log                            - jetty-6.1.9
WARN  log                            - failed
SelectChannelConnector@0.0.0.0:8080
java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind(Native Method)
        at
sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
        at
org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
        at
org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
        at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
        at
org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:111)
        at
org.apache.camel.component.http.HttpEndpoint.connect(HttpEndpoint.java:94)
        at
org.apache.camel.component.http.HttpConsumer.doStart(HttpConsumer.java:50)
        at
org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
        at
org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:421)
        at
org.apache.camel.impl.DefaultCamelContext.startRoutes(DefaultCamelContext.java:659)
        at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:632)
        at
org.apache.camel.spring.SpringCamelContext.maybeDoStart(SpringCamelContext.java:167)
        at
org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:162)
        at
org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
        at
org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:97)
        at
org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:116)
        at
org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:78)
        at
org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
        at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:76)
        at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:275)
        at
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:737)
        at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:384)
        at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)



I'm working with a plugin architecture, so the routes have to be in separate
camel contexts unless there's some way to refer to other camel contexts in
spring that I'm not aware of.  The plugin needs to be able to specify its
routes in its own spring xml file without affecting others' xml files, and
be on the same http port.

I've worked around this by creating my own custom component that is a copy
of the JettyHttpComponent, but changing the fields to static so the routes
that specify the custom component will share the same server field.  Is
there a better way around this?  Will this be resolved in future versions of
Camel?

Thanks,

Nathan
-- 
View this message in context: http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20608492.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: jetty endpoints in different camel contexts

Posted by ndjensen <nd...@gmail.com>.
I'm looking at the 1.5.0 source for JettyHttpComponent for the private
camelServlet.  Looking at camel's revision log, it looks like that issue
with extending and overriding is negated by revision 718242 under
CAMEL-1091, which is slated for a 1.5.1 release.  Until 1.5.1 is released I
will probably keep my separate component instead of extending.


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Could you point out exactly where the issue is with extending. I can't
> at first glance find the private CamelServlet.
> Maybe you could provide a patch to camel-http or camel-jetty component
> so you can extend JettyComponent.
> 
> We love contributions:
> http://activemq.apache.org/camel/contributing.html
> 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 
> 
> On Wed, Dec 3, 2008 at 12:17 AM, ndjensen <nd...@gmail.com> wrote:
>>
>> Hi, thanks for the help.  Originally I considered extending the jetty
>> component and overriding createServer(), or creating the Server in spring
>> and injecting it into the jetty component. Unfortunately camelServlet is
>> private and instantiated in createServer(), so I would null pointer in
>> connect().
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> Hi
>>>
>>> Interesting use-case for reuse of singleton components. First time I
>>> read about this. Usually you want isolation of your applications.
>>>
>>> Maybe a better solution would be to extend JettyHttpComponent and
>>> override some of the methods that creates the server so you can fetch
>>> your shared instance instead.
>>>
>>> If using spring it's just defining a spring bean with the id=jetty
>>> that is your class instead of the default one
>>>
>>> <bean id="jetty" class="com.mycompany.MyJettyComponent">
>>>    <property name="foo" value="bar"/>
>>> </bean>
>>>
>>> Then when you do the routing in DSL and you use the jetty scheme it
>>> uses your component instead of the default one
>>>
>>> <from uri="jetty:xxxx"/>
>>> <to uri="log:hello"/>
>>>
>>> In the route above it picks up MyJettyComponent
>>>
>>>
>>> /Claus Ibsen
>>> Apache Camel Committer
>>> Blog: http://davsclaus.blogspot.com/
>>>
>>>
>>>
>>> On Thu, Nov 20, 2008 at 8:37 PM, ndjensen <nd...@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> On Camel 1.5.0, it seems like you can't have multiple jetty endpoints
>>>> in
>>>> separate camel contexts on the same port.  For example, if I have the
>>>> following routes,
>>>>
>>>> <route id="exampleRouteOne">
>>>>        <from uri="jetty:http://0.0.0.0:8080/services/doSomething" />
>>>>        <bean ref="someService" method="doSomething" />
>>>> </route>
>>>>
>>>> <route id="exampleRouteTwo">
>>>>        <from uri="jetty:http://0.0.0.0:8080/services/foo" />
>>>>        <bean ref="someBean" method="processRequest" />
>>>> </route>
>>>>
>>>>
>>>> it works great when they're in the same camel context, but throws the
>>>> following exception at startup of the second address when they're not.
>>>>
>>>>
>>>>
>>>> INFO  log                            - Started
>>>> SelectChannelConnector@0.0.0.0:8080
>>>> INFO  log                            - jetty-6.1.9
>>>> WARN  log                            - failed
>>>> SelectChannelConnector@0.0.0.0:8080
>>>> java.net.BindException: Address already in use
>>>>        at sun.nio.ch.Net.bind(Native Method)
>>>>        at
>>>> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
>>>>        at
>>>> sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
>>>>        at
>>>> org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
>>>>        at
>>>> org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
>>>>        at
>>>> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
>>>>        at
>>>> org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:111)
>>>>        at
>>>> org.apache.camel.component.http.HttpEndpoint.connect(HttpEndpoint.java:94)
>>>>        at
>>>> org.apache.camel.component.http.HttpConsumer.doStart(HttpConsumer.java:50)
>>>>        at
>>>> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>>>>        at
>>>> org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:421)
>>>>        at
>>>> org.apache.camel.impl.DefaultCamelContext.startRoutes(DefaultCamelContext.java:659)
>>>>        at
>>>> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:632)
>>>>        at
>>>> org.apache.camel.spring.SpringCamelContext.maybeDoStart(SpringCamelContext.java:167)
>>>>        at
>>>> org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:162)
>>>>        at
>>>> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>>>>        at
>>>> org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:97)
>>>>        at
>>>> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:116)
>>>>        at
>>>> org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:78)
>>>>        at
>>>> org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
>>>>        at
>>>> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:76)
>>>>        at
>>>> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:275)
>>>>        at
>>>> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:737)
>>>>        at
>>>> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:384)
>>>>        at
>>>> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
>>>>        at
>>>> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
>>>>
>>>>
>>>>
>>>> I'm working with a plugin architecture, so the routes have to be in
>>>> separate
>>>> camel contexts unless there's some way to refer to other camel contexts
>>>> in
>>>> spring that I'm not aware of.  The plugin needs to be able to specify
>>>> its
>>>> routes in its own spring xml file without affecting others' xml files,
>>>> and
>>>> be on the same http port.
>>>>
>>>> I've worked around this by creating my own custom component that is a
>>>> copy
>>>> of the JettyHttpComponent, but changing the fields to static so the
>>>> routes
>>>> that specify the custom component will share the same server field.  Is
>>>> there a better way around this?  Will this be resolved in future
>>>> versions
>>>> of
>>>> Camel?
>>>>
>>>> Thanks,
>>>>
>>>> Nathan
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20608492.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20803294.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20815558.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: jetty endpoints in different camel contexts

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Could you point out exactly where the issue is with extending. I can't
at first glance find the private CamelServlet.
Maybe you could provide a patch to camel-http or camel-jetty component
so you can extend JettyComponent.

We love contributions:
http://activemq.apache.org/camel/contributing.html


/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Wed, Dec 3, 2008 at 12:17 AM, ndjensen <nd...@gmail.com> wrote:
>
> Hi, thanks for the help.  Originally I considered extending the jetty
> component and overriding createServer(), or creating the Server in spring
> and injecting it into the jetty component. Unfortunately camelServlet is
> private and instantiated in createServer(), so I would null pointer in
> connect().
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Interesting use-case for reuse of singleton components. First time I
>> read about this. Usually you want isolation of your applications.
>>
>> Maybe a better solution would be to extend JettyHttpComponent and
>> override some of the methods that creates the server so you can fetch
>> your shared instance instead.
>>
>> If using spring it's just defining a spring bean with the id=jetty
>> that is your class instead of the default one
>>
>> <bean id="jetty" class="com.mycompany.MyJettyComponent">
>>    <property name="foo" value="bar"/>
>> </bean>
>>
>> Then when you do the routing in DSL and you use the jetty scheme it
>> uses your component instead of the default one
>>
>> <from uri="jetty:xxxx"/>
>> <to uri="log:hello"/>
>>
>> In the route above it picks up MyJettyComponent
>>
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>>
>>
>> On Thu, Nov 20, 2008 at 8:37 PM, ndjensen <nd...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> On Camel 1.5.0, it seems like you can't have multiple jetty endpoints in
>>> separate camel contexts on the same port.  For example, if I have the
>>> following routes,
>>>
>>> <route id="exampleRouteOne">
>>>        <from uri="jetty:http://0.0.0.0:8080/services/doSomething" />
>>>        <bean ref="someService" method="doSomething" />
>>> </route>
>>>
>>> <route id="exampleRouteTwo">
>>>        <from uri="jetty:http://0.0.0.0:8080/services/foo" />
>>>        <bean ref="someBean" method="processRequest" />
>>> </route>
>>>
>>>
>>> it works great when they're in the same camel context, but throws the
>>> following exception at startup of the second address when they're not.
>>>
>>>
>>>
>>> INFO  log                            - Started
>>> SelectChannelConnector@0.0.0.0:8080
>>> INFO  log                            - jetty-6.1.9
>>> WARN  log                            - failed
>>> SelectChannelConnector@0.0.0.0:8080
>>> java.net.BindException: Address already in use
>>>        at sun.nio.ch.Net.bind(Native Method)
>>>        at
>>> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
>>>        at
>>> sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
>>>        at
>>> org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
>>>        at
>>> org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
>>>        at
>>> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
>>>        at
>>> org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:111)
>>>        at
>>> org.apache.camel.component.http.HttpEndpoint.connect(HttpEndpoint.java:94)
>>>        at
>>> org.apache.camel.component.http.HttpConsumer.doStart(HttpConsumer.java:50)
>>>        at
>>> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>>>        at
>>> org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:421)
>>>        at
>>> org.apache.camel.impl.DefaultCamelContext.startRoutes(DefaultCamelContext.java:659)
>>>        at
>>> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:632)
>>>        at
>>> org.apache.camel.spring.SpringCamelContext.maybeDoStart(SpringCamelContext.java:167)
>>>        at
>>> org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:162)
>>>        at
>>> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>>>        at
>>> org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:97)
>>>        at
>>> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:116)
>>>        at
>>> org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:78)
>>>        at
>>> org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
>>>        at
>>> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:76)
>>>        at
>>> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:275)
>>>        at
>>> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:737)
>>>        at
>>> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:384)
>>>        at
>>> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
>>>        at
>>> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
>>>
>>>
>>>
>>> I'm working with a plugin architecture, so the routes have to be in
>>> separate
>>> camel contexts unless there's some way to refer to other camel contexts
>>> in
>>> spring that I'm not aware of.  The plugin needs to be able to specify its
>>> routes in its own spring xml file without affecting others' xml files,
>>> and
>>> be on the same http port.
>>>
>>> I've worked around this by creating my own custom component that is a
>>> copy
>>> of the JettyHttpComponent, but changing the fields to static so the
>>> routes
>>> that specify the custom component will share the same server field.  Is
>>> there a better way around this?  Will this be resolved in future versions
>>> of
>>> Camel?
>>>
>>> Thanks,
>>>
>>> Nathan
>>> --
>>> View this message in context:
>>> http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20608492.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20803294.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: jetty endpoints in different camel contexts

Posted by ndjensen <nd...@gmail.com>.
Hi, thanks for the help.  Originally I considered extending the jetty
component and overriding createServer(), or creating the Server in spring
and injecting it into the jetty component. Unfortunately camelServlet is
private and instantiated in createServer(), so I would null pointer in
connect().


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Interesting use-case for reuse of singleton components. First time I
> read about this. Usually you want isolation of your applications.
> 
> Maybe a better solution would be to extend JettyHttpComponent and
> override some of the methods that creates the server so you can fetch
> your shared instance instead.
> 
> If using spring it's just defining a spring bean with the id=jetty
> that is your class instead of the default one
> 
> <bean id="jetty" class="com.mycompany.MyJettyComponent">
>    <property name="foo" value="bar"/>
> </bean>
> 
> Then when you do the routing in DSL and you use the jetty scheme it
> uses your component instead of the default one
> 
> <from uri="jetty:xxxx"/>
> <to uri="log:hello"/>
> 
> In the route above it picks up MyJettyComponent
> 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 
> 
> On Thu, Nov 20, 2008 at 8:37 PM, ndjensen <nd...@gmail.com> wrote:
>>
>> Hi,
>>
>> On Camel 1.5.0, it seems like you can't have multiple jetty endpoints in
>> separate camel contexts on the same port.  For example, if I have the
>> following routes,
>>
>> <route id="exampleRouteOne">
>>        <from uri="jetty:http://0.0.0.0:8080/services/doSomething" />
>>        <bean ref="someService" method="doSomething" />
>> </route>
>>
>> <route id="exampleRouteTwo">
>>        <from uri="jetty:http://0.0.0.0:8080/services/foo" />
>>        <bean ref="someBean" method="processRequest" />
>> </route>
>>
>>
>> it works great when they're in the same camel context, but throws the
>> following exception at startup of the second address when they're not.
>>
>>
>>
>> INFO  log                            - Started
>> SelectChannelConnector@0.0.0.0:8080
>> INFO  log                            - jetty-6.1.9
>> WARN  log                            - failed
>> SelectChannelConnector@0.0.0.0:8080
>> java.net.BindException: Address already in use
>>        at sun.nio.ch.Net.bind(Native Method)
>>        at
>> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
>>        at
>> sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
>>        at
>> org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
>>        at
>> org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
>>        at
>> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
>>        at
>> org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:111)
>>        at
>> org.apache.camel.component.http.HttpEndpoint.connect(HttpEndpoint.java:94)
>>        at
>> org.apache.camel.component.http.HttpConsumer.doStart(HttpConsumer.java:50)
>>        at
>> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>>        at
>> org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:421)
>>        at
>> org.apache.camel.impl.DefaultCamelContext.startRoutes(DefaultCamelContext.java:659)
>>        at
>> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:632)
>>        at
>> org.apache.camel.spring.SpringCamelContext.maybeDoStart(SpringCamelContext.java:167)
>>        at
>> org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:162)
>>        at
>> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>>        at
>> org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:97)
>>        at
>> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:116)
>>        at
>> org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:78)
>>        at
>> org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
>>        at
>> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:76)
>>        at
>> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:275)
>>        at
>> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:737)
>>        at
>> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:384)
>>        at
>> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
>>        at
>> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
>>
>>
>>
>> I'm working with a plugin architecture, so the routes have to be in
>> separate
>> camel contexts unless there's some way to refer to other camel contexts
>> in
>> spring that I'm not aware of.  The plugin needs to be able to specify its
>> routes in its own spring xml file without affecting others' xml files,
>> and
>> be on the same http port.
>>
>> I've worked around this by creating my own custom component that is a
>> copy
>> of the JettyHttpComponent, but changing the fields to static so the
>> routes
>> that specify the custom component will share the same server field.  Is
>> there a better way around this?  Will this be resolved in future versions
>> of
>> Camel?
>>
>> Thanks,
>>
>> Nathan
>> --
>> View this message in context:
>> http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20608492.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20803294.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: jetty endpoints in different camel contexts

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Interesting use-case for reuse of singleton components. First time I
read about this. Usually you want isolation of your applications.

Maybe a better solution would be to extend JettyHttpComponent and
override some of the methods that creates the server so you can fetch
your shared instance instead.

If using spring it's just defining a spring bean with the id=jetty
that is your class instead of the default one

<bean id="jetty" class="com.mycompany.MyJettyComponent">
   <property name="foo" value="bar"/>
</bean>

Then when you do the routing in DSL and you use the jetty scheme it
uses your component instead of the default one

<from uri="jetty:xxxx"/>
<to uri="log:hello"/>

In the route above it picks up MyJettyComponent


/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Thu, Nov 20, 2008 at 8:37 PM, ndjensen <nd...@gmail.com> wrote:
>
> Hi,
>
> On Camel 1.5.0, it seems like you can't have multiple jetty endpoints in
> separate camel contexts on the same port.  For example, if I have the
> following routes,
>
> <route id="exampleRouteOne">
>        <from uri="jetty:http://0.0.0.0:8080/services/doSomething" />
>        <bean ref="someService" method="doSomething" />
> </route>
>
> <route id="exampleRouteTwo">
>        <from uri="jetty:http://0.0.0.0:8080/services/foo" />
>        <bean ref="someBean" method="processRequest" />
> </route>
>
>
> it works great when they're in the same camel context, but throws the
> following exception at startup of the second address when they're not.
>
>
>
> INFO  log                            - Started
> SelectChannelConnector@0.0.0.0:8080
> INFO  log                            - jetty-6.1.9
> WARN  log                            - failed
> SelectChannelConnector@0.0.0.0:8080
> java.net.BindException: Address already in use
>        at sun.nio.ch.Net.bind(Native Method)
>        at
> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
>        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
>        at
> org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
>        at
> org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
>        at
> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
>        at
> org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:111)
>        at
> org.apache.camel.component.http.HttpEndpoint.connect(HttpEndpoint.java:94)
>        at
> org.apache.camel.component.http.HttpConsumer.doStart(HttpConsumer.java:50)
>        at
> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>        at
> org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:421)
>        at
> org.apache.camel.impl.DefaultCamelContext.startRoutes(DefaultCamelContext.java:659)
>        at
> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:632)
>        at
> org.apache.camel.spring.SpringCamelContext.maybeDoStart(SpringCamelContext.java:167)
>        at
> org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:162)
>        at
> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
>        at
> org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:97)
>        at
> org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:116)
>        at
> org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:78)
>        at
> org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
>        at
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:76)
>        at
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:275)
>        at
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:737)
>        at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:384)
>        at
> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
>        at
> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
>
>
>
> I'm working with a plugin architecture, so the routes have to be in separate
> camel contexts unless there's some way to refer to other camel contexts in
> spring that I'm not aware of.  The plugin needs to be able to specify its
> routes in its own spring xml file without affecting others' xml files, and
> be on the same http port.
>
> I've worked around this by creating my own custom component that is a copy
> of the JettyHttpComponent, but changing the fields to static so the routes
> that specify the custom component will share the same server field.  Is
> there a better way around this?  Will this be resolved in future versions of
> Camel?
>
> Thanks,
>
> Nathan
> --
> View this message in context: http://www.nabble.com/jetty-endpoints-in-different-camel-contexts-tp20608492s22882p20608492.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>