You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Joshua Watkins <jo...@gamesys.co.uk> on 2011/08/18 14:06:30 UTC

Serving static pages with JettyComponent

I am using the camel jetty component to route to activemq to access other
backend services.

For instance: 

   from("jetty:http://0.0.0.0:8083/people")
        .setHeader(JMS_TYPE, constant("AddPeople"))
        .to("activemq:proxy.out").routeId("addPeople");

I would also like to serve up some static web pages that are part of the
classpath. Of course, I want to be able to leverage the jetty server that
is already running within the camel jetty component. Unfortunately I am at
a bit of a loss at how do do this.


I have tried creating a context handler in spring:

<bean id="staticPageHandler"
class="org.eclipse.jetty.server.handler.ContextHandler">									
	<property name="contextPath" value="/"/>
	<property name="resourceBase" value="./resources/web" />
	</bean>

And then added it in the list of handlers on the uri:
"jetty:http://0.0.0.0:8083/people??handlers=staticPageHandler"
However that didn't work either.

Any ideas? Am I missing something simple?




Re: Serving static pages with JettyComponent

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Aug 19, 2011 at 1:57 PM, Joshua Watkins
<jo...@gamesys.co.uk> wrote:
> Thanks Craig. That solution worked.
>
> I will take a look at the deeper cause. It seems odd that you can specify
> handlers but they don't really work. I am however only using 2.6, but I
> can't see any jira tickets for something like this being fixed. If I get
> time I will create a ticket and maybe a patch for the jetty component.
>

Contributions is welcome. Feel free to create a JIRA ticket. I would
assume the handlers would be generic and work as if.
However the intend for the handlers was in relation to security, so we
haven't tested it with serving static pages instead.


> -josh
>
> On 18/08/2011 18:10, "Craig Taylor" <ct...@ctalkobt.net> wrote:
>
>>For Camel 2.2 I ended up implementing a FileDumper() which dumps a file
>>based upon the path directly to the exchange body.  Eg:
>>
>>route.choice()..when(header(Exchange.HTTP_PATH).startsWith("/js")).process
>>(fileDumper)
>>
>>and fileDumper psuedo-code is essentially :
>>
>>mimetype = decode filename (Exchange.HTTP_PATH based)
>>exchange.setHeader(Exchange.CONTENT_TYPE, mimeType)
>>exchange.setBody( Resource from baseDirectory + filename . readFile() )
>>
>>I'd love to find a way to configure the underlying jetty component to do
>>this magic for me but it doesn't appear to be accessible.
>>
>>On Thu, Aug 18, 2011 at 8:06 AM, Joshua Watkins <
>>joshua.watkins@gamesys.co.uk> wrote:
>>
>>> I am using the camel jetty component to route to activemq to access
>>>other
>>> backend services.
>>>
>>> For instance:
>>>
>>>   from("jetty:http://0.0.0.0:8083/people")
>>>        .setHeader(JMS_TYPE, constant("AddPeople"))
>>>        .to("activemq:proxy.out").routeId("addPeople");
>>>
>>> I would also like to serve up some static web pages that are part of the
>>> classpath. Of course, I want to be able to leverage the jetty server
>>>that
>>> is already running within the camel jetty component. Unfortunately I am
>>>at
>>> a bit of a loss at how do do this.
>>>
>>>
>>> I have tried creating a context handler in spring:
>>>
>>> <bean id="staticPageHandler"
>>> class="org.eclipse.jetty.server.handler.ContextHandler">
>>>        <property name="contextPath" value="/"/>
>>>        <property name="resourceBase" value="./resources/web" />
>>>        </bean>
>>>
>>> And then added it in the list of handlers on the uri:
>>> "jetty:http://0.0.0.0:8083/people??handlers=staticPageHandler"
>>> However that didn't work either.
>>>
>>> Any ideas? Am I missing something simple?
>>>
>>>
>>>
>>>
>>
>>
>>--
>>-------------------------------------------
>>Craig Taylor
>>ctalkobt@ctalkobt.net
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Serving static pages with JettyComponent

Posted by Joshua Watkins <jo...@gamesys.co.uk>.
Thanks Craig. That solution worked.

I will take a look at the deeper cause. It seems odd that you can specify
handlers but they don't really work. I am however only using 2.6, but I
can't see any jira tickets for something like this being fixed. If I get
time I will create a ticket and maybe a patch for the jetty component.

-josh

On 18/08/2011 18:10, "Craig Taylor" <ct...@ctalkobt.net> wrote:

>For Camel 2.2 I ended up implementing a FileDumper() which dumps a file
>based upon the path directly to the exchange body.  Eg:
>
>route.choice()..when(header(Exchange.HTTP_PATH).startsWith("/js")).process
>(fileDumper)
>
>and fileDumper psuedo-code is essentially :
>
>mimetype = decode filename (Exchange.HTTP_PATH based)
>exchange.setHeader(Exchange.CONTENT_TYPE, mimeType)
>exchange.setBody( Resource from baseDirectory + filename . readFile() )
>
>I'd love to find a way to configure the underlying jetty component to do
>this magic for me but it doesn't appear to be accessible.
>
>On Thu, Aug 18, 2011 at 8:06 AM, Joshua Watkins <
>joshua.watkins@gamesys.co.uk> wrote:
>
>> I am using the camel jetty component to route to activemq to access
>>other
>> backend services.
>>
>> For instance:
>>
>>   from("jetty:http://0.0.0.0:8083/people")
>>        .setHeader(JMS_TYPE, constant("AddPeople"))
>>        .to("activemq:proxy.out").routeId("addPeople");
>>
>> I would also like to serve up some static web pages that are part of the
>> classpath. Of course, I want to be able to leverage the jetty server
>>that
>> is already running within the camel jetty component. Unfortunately I am
>>at
>> a bit of a loss at how do do this.
>>
>>
>> I have tried creating a context handler in spring:
>>
>> <bean id="staticPageHandler"
>> class="org.eclipse.jetty.server.handler.ContextHandler">
>>        <property name="contextPath" value="/"/>
>>        <property name="resourceBase" value="./resources/web" />
>>        </bean>
>>
>> And then added it in the list of handlers on the uri:
>> "jetty:http://0.0.0.0:8083/people??handlers=staticPageHandler"
>> However that didn't work either.
>>
>> Any ideas? Am I missing something simple?
>>
>>
>>
>>
>
>
>-- 
>-------------------------------------------
>Craig Taylor
>ctalkobt@ctalkobt.net


Re: Serving static pages with JettyComponent

Posted by Craig Taylor <ct...@ctalkobt.net>.
For Camel 2.2 I ended up implementing a FileDumper() which dumps a file
based upon the path directly to the exchange body.  Eg:

route.choice()..when(header(Exchange.HTTP_PATH).startsWith("/js")).process(fileDumper)

and fileDumper psuedo-code is essentially :

mimetype = decode filename (Exchange.HTTP_PATH based)
exchange.setHeader(Exchange.CONTENT_TYPE, mimeType)
exchange.setBody( Resource from baseDirectory + filename . readFile() )

I'd love to find a way to configure the underlying jetty component to do
this magic for me but it doesn't appear to be accessible.

On Thu, Aug 18, 2011 at 8:06 AM, Joshua Watkins <
joshua.watkins@gamesys.co.uk> wrote:

> I am using the camel jetty component to route to activemq to access other
> backend services.
>
> For instance:
>
>   from("jetty:http://0.0.0.0:8083/people")
>        .setHeader(JMS_TYPE, constant("AddPeople"))
>        .to("activemq:proxy.out").routeId("addPeople");
>
> I would also like to serve up some static web pages that are part of the
> classpath. Of course, I want to be able to leverage the jetty server that
> is already running within the camel jetty component. Unfortunately I am at
> a bit of a loss at how do do this.
>
>
> I have tried creating a context handler in spring:
>
> <bean id="staticPageHandler"
> class="org.eclipse.jetty.server.handler.ContextHandler">
>        <property name="contextPath" value="/"/>
>        <property name="resourceBase" value="./resources/web" />
>        </bean>
>
> And then added it in the list of handlers on the uri:
> "jetty:http://0.0.0.0:8083/people??handlers=staticPageHandler"
> However that didn't work either.
>
> Any ideas? Am I missing something simple?
>
>
>
>


-- 
-------------------------------------------
Craig Taylor
ctalkobt@ctalkobt.net