You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Benson Margulies <bi...@basistech.com> on 2007/07/12 03:53:49 UTC

Getting the HTTP server off the bus

Could someone reveal how to ask the default bus for the running Jetty
instance? I want to add a static content directory for it to handle.

 

 


RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Willem,

The recipe in 2.0 looks like:

Bus bus =  BusFactory.getDefaultBus();
        DestinationFactoryManager dfm =
bus.getExtension(DestinationFactoryManager.class);
        JettyHTTPTransportFactory df = (JettyHTTPTransportFactory)
dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configu
ration");
        EndpointInfo ei = new EndpointInfo();
        ei.setAddress(serviceFactory.getAddress());
        @SuppressWarnings("unused")
        Destination destination = df.getDestination(ei);
        JettyHTTPDestination jettyDestination =
(JettyHTTPDestination)destination; 
        ServerEngine engine= jettyDestination.getEngine();

Now I wish that I could just retrieve the org.mortbay.jetty.Server from
the JettyHTTPServerEngine and talk to it, I already know how. It already
knows how to handle static content. It's kind of crazy to write my own
code to serve up static data, when the code from Jetty is out there and
can do it perfectly well.

If I offered a patch, would you take it?



> -----Original Message-----
> From: Willem Jiang [mailto:ning.jiang@iona.com]
> Sent: Wednesday, July 11, 2007 10:35 PM
> To: cxf-user@incubator.apache.org
> Subject: Re: Getting the HTTP server off the bus
> 
> Hi Benson,
> 
> All the Jetty related stuff of CXF are in the
> cxf-rt-transports-http-jetty module.
> You can get the serverEngine which wraps the Jetty instance from the
> JettyHttpTransportFactory.
> 
> You can use the below codes to get the serverEngine.
> 
>         Bus bus =  BusFactory.getDefaultBus();
>         DestinationFactoryManager dfm =
> bus.getExtension(DestinationFactoryManager.class);
>         JettyHttpTransportFactory df = (JettyHttpTransportFactory)
>
dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configu
ra
> tion");
>        ServerEngine engine= df.getEngine();
> 
> The you just need to extends JettyHTTPHandler to deal with the static
> content directory, and add it into the engine by call addServant(URL
> url, JettyHTTPHandler handler).
> 
> You can find the detail information about the ServerEngine and
> JettyHTTPHandler from this directory
> 
>
https://svn.apache.org/repos/asf/incubator/cxf/trunk/rt/transports/http-
> jetty/src/main/java/org/apache/cxf/transport/http_jetty
> 
> Enjoy hacking the code !
> 
> Willem.
> 
> 
> Benson Margulies wrote:
> > Could someone reveal how to ask the default bus for the running
Jetty
> > instance? I want to add a static content directory for it to handle.
> >
> >
> >
> >
> >
> >
> >

RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Yes, indeed, this is really a superior solution. It's much better than
trying to replace factories.

Now, if I only knew why the jetty FileResource constructs over a URL
instead of a pathname :-)

Thanks!

> -----Original Message-----
> From: Willem Jiang [mailto:ning.jiang@iona.com]
> Sent: Monday, July 16, 2007 4:44 AM
> To: cxf-user@incubator.apache.org
> Subject: Re: Getting the HTTP server off the bus
> 
> Benson,
> 
> I just noticed that you can get the context handler by the below code
> when you get the service engine.
> 
> ...
> 
> JettyHTTPDestination destination =
> (JettyHTTPDestination)df.getDestination(epi);
> ServerEngine engine= destination.getEngine();
> ContextHandler context = (ContextHandler) engine.getServant(new
> URL(address));
> ...
> 
> And you can use this context to add the static resource handler.
> 
> Willem.
> 
> Benson Margulies wrote:
> > Before I finish the story I started, I see that I could get what I
want
> > around here by making a mutant copy of JettyHTTPServerEngine and
using
> > it by imposing my own subclass of JettyHTTPServerEngineFactory. So
I'm
> > looking around to see where I can configure THAT trick.
> >
> >
> > In XFire, I made a variation on XFireHttpServer in which I could
have
> > the following ...
> >
> > ResourceHandler rh = new ResourceHandler();
> >         rh.setDirAllowed(true);
> >         context.addHandler(rh);
> >         context.setResourceBase(staticContentDirectory);
> >
> >
> >
> >

RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Well, you can ignore the first paragraph. The rest of my analysis turned
out to be correct. 

Would anyone care to see the following on a wiki?

            EndpointInfo ei = new EndpointInfo();
            ei.setAddress(serviceFactory.getAddress());
            Destination destination = df.getDestination(ei);
            JettyHTTPDestination jettyDestination =
(JettyHTTPDestination) destination;
            ServerEngine engine = jettyDestination.getEngine();
            Handler handler = engine.getServant(new
URL(serviceFactory.getAddress()));
            org.mortbay.jetty.Server server = handler.getServer();
            Handler serverHandler = server.getHandler();
            ContextHandlerCollection contextHandlerCollection =
(ContextHandlerCollection)serverHandler;
            HandlerList handlerList = new HandlerList();
            ResourceHandler resourceHandler = new ResourceHandler();
            handlerList.addHandler(resourceHandler);
            handlerList.addHandler(contextHandlerCollection);
            server.setHandler(handlerList);
            handlerList.start();
            File staticContentFile = new File(staticContentPath);
            URL targetURL = new URL("file://" +
staticContentFile.getCanonicalPath());
            FileResource fileResource = new FileResource(targetURL);
            resourceHandler.setBaseResource(fileResource);

> -----Original Message-----
> From: Benson Margulies [mailto:bim2007@basistech.com]
> Sent: Monday, July 16, 2007 8:48 PM
> To: cxf-user@incubator.apache.org
> Subject: RE: Getting the HTTP server off the bus
> 
> Dan and Willem,
> 
> It looks to me like I'm fairly nearly stuck until you let me fully
> control the server wiring unless I'm willing to do some fairly
extensive
> rewiring of your wiring.
> 
> The jetty doc isn't precisely helpful here, but I have reached the
> following tentative view of the situation:
> 
> As things are, the org.mortbay.jetty.Server has, as its singular
> handler, a ContextHandlerCollection, which has (at least one)
> ContextHandler. ContextHandlers are all about Servlet contexts, of
> course.
> 
> Once a ContextHandlerCollection has at least one ContextHandler, it
> ignores any ordinary handlers that it has when handling any request
that
> begins with '/'.
> 
> So, to get a ResourceHandler into the game, I think that I'd have to
> create a HandlerList and have that point off to the
> ContextHandlerCollection as well as the ResourceHandler, and install
it
> as the server's handler.
> 
> I have a giant feeling here that there's something basic I'm missing
> about Jetty that is supposed to make this easier, but I'm pretty near
to
> accusing the folks who run the Jetty web site of intentionally making
> the version 6 docs less helpful than the version 5 docs to sell more
> consulting.
> 
> Probably just sour grapes on my part.
> 
> --benson


RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Dan and Willem,

It looks to me like I'm fairly nearly stuck until you let me fully
control the server wiring unless I'm willing to do some fairly extensive
rewiring of your wiring.

The jetty doc isn't precisely helpful here, but I have reached the
following tentative view of the situation:

As things are, the org.mortbay.jetty.Server has, as its singular
handler, a ContextHandlerCollection, which has (at least one)
ContextHandler. ContextHandlers are all about Servlet contexts, of
course.

Once a ContextHandlerCollection has at least one ContextHandler, it
ignores any ordinary handlers that it has when handling any request that
begins with '/'. 

So, to get a ResourceHandler into the game, I think that I'd have to
create a HandlerList and have that point off to the
ContextHandlerCollection as well as the ResourceHandler, and install it
as the server's handler.

I have a giant feeling here that there's something basic I'm missing
about Jetty that is supposed to make this easier, but I'm pretty near to
accusing the folks who run the Jetty web site of intentionally making
the version 6 docs less helpful than the version 5 docs to sell more
consulting.

Probably just sour grapes on my part.

--benson


RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
For now, I can ask the org.mortbay.jetty.Server for its list of
Handlers. There is only one in this case, and it's the ContextHandler. I
think that your proposed accessor makes perfect sense when you get
around to it.

> -----Original Message-----
> From: Jiang, Ning (Willem) [mailto:Ning.Jiang@iona.com]
> Sent: Monday, July 16, 2007 11:47 AM
> To: cxf-user@incubator.apache.org
> Subject: RE: Getting the HTTP server off the bus
> 
> Hi Beanson,
> 
> My bad to take  the JettyHTTPHandler as ContextHandler.
> 
> I just checked the Jetty's handler api, and I didn't find a way to get
the
> parent handler form a childer handler.
> 
> Maybe you can find the Context handler by looking up the context path
from
> server, or we can add the getContextHandler method in the
> JettyHTTPServerEngine.
> 
> Willem.
> 
> 
> -----Original Message-----
> From: Benson Margulies [mailto:bim2007@basistech.com]
> Sent: Mon 7/16/2007 22:53
> To: cxf-user@incubator.apache.org
> Subject: RE: Getting the HTTP server off the bus
> 
> Willem,
> 
> When I call getServant, I get back the JettyHTTPHandler.  Which,
> interestingly enough, will cheerfully return the Jetty Server object
> which I was asking for in the first place.
> 
> The ContextHandler in which the JettyHTTPHandler lives is somewhat
> obscurely connected, I haven't found the trail of breadcrumbs for it
> yet, but I'm working on it.
> 
> --benson
> 
> 
> > -----Original Message-----
> > From: Willem Jiang [mailto:ning.jiang@iona.com]
> > Sent: Monday, July 16, 2007 4:44 AM
> > To: cxf-user@incubator.apache.org
> > Subject: Re: Getting the HTTP server off the bus
> >
> > Benson,
> >
> > I just noticed that you can get the context handler by the below
code
> > when you get the service engine.
> >
> > ...
> >
> > JettyHTTPDestination destination =
> > (JettyHTTPDestination)df.getDestination(epi);
> > ServerEngine engine= destination.getEngine();
> > ContextHandler context = (ContextHandler) engine.getServant(new
> > URL(address));
> > ...
> >
> > And you can use this context to add the static resource handler.
> >
> > Willem.
> >
> > Benson Margulies wrote:
> > > Before I finish the story I started, I see that I could get what I
> want
> > > around here by making a mutant copy of JettyHTTPServerEngine and
> using
> > > it by imposing my own subclass of JettyHTTPServerEngineFactory. So
> I'm
> > > looking around to see where I can configure THAT trick.
> > >
> > >
> > > In XFire, I made a variation on XFireHttpServer in which I could
> have
> > > the following ...
> > >
> > > ResourceHandler rh = new ResourceHandler();
> > >         rh.setDirAllowed(true);
> > >         context.addHandler(rh);
> > >         context.setResourceBase(staticContentDirectory);
> > >
> > >
> > >
> > >


RE: Getting the HTTP server off the bus

Posted by "Jiang, Ning (Willem)" <Ni...@iona.com>.
Hi Beanson,

My bad to take  the JettyHTTPHandler as ContextHandler.

I just checked the Jetty's handler api, and I didn't find a way to get the parent handler form a childer handler.

Maybe you can find the Context handler by looking up the context path from server, or we can add the getContextHandler method in the JettyHTTPServerEngine.

Willem.


-----Original Message-----
From: Benson Margulies [mailto:bim2007@basistech.com]
Sent: Mon 7/16/2007 22:53
To: cxf-user@incubator.apache.org
Subject: RE: Getting the HTTP server off the bus
 
Willem,

When I call getServant, I get back the JettyHTTPHandler.  Which,
interestingly enough, will cheerfully return the Jetty Server object
which I was asking for in the first place.

The ContextHandler in which the JettyHTTPHandler lives is somewhat
obscurely connected, I haven't found the trail of breadcrumbs for it
yet, but I'm working on it.

--benson


> -----Original Message-----
> From: Willem Jiang [mailto:ning.jiang@iona.com]
> Sent: Monday, July 16, 2007 4:44 AM
> To: cxf-user@incubator.apache.org
> Subject: Re: Getting the HTTP server off the bus
> 
> Benson,
> 
> I just noticed that you can get the context handler by the below code
> when you get the service engine.
> 
> ...
> 
> JettyHTTPDestination destination =
> (JettyHTTPDestination)df.getDestination(epi);
> ServerEngine engine= destination.getEngine();
> ContextHandler context = (ContextHandler) engine.getServant(new
> URL(address));
> ...
> 
> And you can use this context to add the static resource handler.
> 
> Willem.
> 
> Benson Margulies wrote:
> > Before I finish the story I started, I see that I could get what I
want
> > around here by making a mutant copy of JettyHTTPServerEngine and
using
> > it by imposing my own subclass of JettyHTTPServerEngineFactory. So
I'm
> > looking around to see where I can configure THAT trick.
> >
> >
> > In XFire, I made a variation on XFireHttpServer in which I could
have
> > the following ...
> >
> > ResourceHandler rh = new ResourceHandler();
> >         rh.setDirAllowed(true);
> >         context.addHandler(rh);
> >         context.setResourceBase(staticContentDirectory);
> >
> >
> >
> >


RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Willem,

When I call getServant, I get back the JettyHTTPHandler.  Which,
interestingly enough, will cheerfully return the Jetty Server object
which I was asking for in the first place.

The ContextHandler in which the JettyHTTPHandler lives is somewhat
obscurely connected, I haven't found the trail of breadcrumbs for it
yet, but I'm working on it.

--benson


> -----Original Message-----
> From: Willem Jiang [mailto:ning.jiang@iona.com]
> Sent: Monday, July 16, 2007 4:44 AM
> To: cxf-user@incubator.apache.org
> Subject: Re: Getting the HTTP server off the bus
> 
> Benson,
> 
> I just noticed that you can get the context handler by the below code
> when you get the service engine.
> 
> ...
> 
> JettyHTTPDestination destination =
> (JettyHTTPDestination)df.getDestination(epi);
> ServerEngine engine= destination.getEngine();
> ContextHandler context = (ContextHandler) engine.getServant(new
> URL(address));
> ...
> 
> And you can use this context to add the static resource handler.
> 
> Willem.
> 
> Benson Margulies wrote:
> > Before I finish the story I started, I see that I could get what I
want
> > around here by making a mutant copy of JettyHTTPServerEngine and
using
> > it by imposing my own subclass of JettyHTTPServerEngineFactory. So
I'm
> > looking around to see where I can configure THAT trick.
> >
> >
> > In XFire, I made a variation on XFireHttpServer in which I could
have
> > the following ...
> >
> > ResourceHandler rh = new ResourceHandler();
> >         rh.setDirAllowed(true);
> >         context.addHandler(rh);
> >         context.setResourceBase(staticContentDirectory);
> >
> >
> >
> >

Re: Getting the HTTP server off the bus

Posted by Willem Jiang <ni...@iona.com>.
Benson,

I just noticed that you can get the context handler by the below code 
when you get the service engine.

...

JettyHTTPDestination destination = (JettyHTTPDestination)df.getDestination(epi);
ServerEngine engine= destination.getEngine();
ContextHandler context = (ContextHandler) engine.getServant(new URL(address));
...

And you can use this context to add the static resource handler.

Willem.

Benson Margulies wrote:
> Before I finish the story I started, I see that I could get what I want
> around here by making a mutant copy of JettyHTTPServerEngine and using
> it by imposing my own subclass of JettyHTTPServerEngineFactory. So I'm
> looking around to see where I can configure THAT trick.
>
>
> In XFire, I made a variation on XFireHttpServer in which I could have
> the following ...
>
> ResourceHandler rh = new ResourceHandler();
>         rh.setDirAllowed(true);
>         context.addHandler(rh);
>         context.setResourceBase(staticContentDirectory);
>
>   
>
>   

RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Before I finish the story I started, I see that I could get what I want
around here by making a mutant copy of JettyHTTPServerEngine and using
it by imposing my own subclass of JettyHTTPServerEngineFactory. So I'm
looking around to see where I can configure THAT trick.


In XFire, I made a variation on XFireHttpServer in which I could have
the following ...

ResourceHandler rh = new ResourceHandler();
        rh.setDirAllowed(true);
        context.addHandler(rh);
        context.setResourceBase(staticContentDirectory);

>

RE: Getting the HTTP server off the bus

Posted by "Jiang, Ning (Willem)" <Ni...@iona.com>.
Hi Benson,
It's my fault that I missed something about getting the destination from the transport factory.

It is JettyHTTPTransportFactory and not JettyHttpTransportFactory

The code should be
 Bus bus =  BusFactory.getDefaultBus();
 DestinationFactoryManager dfm =   bus.getExtension(DestinationFactoryManager.class);
 JettyHTTPTransportFactory df = (JettyHTTPTransportFactory)
     dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");

 // get the the destionation from the transport factory by the address
 EndpointInfo epi = new EndpointInfo(); 
 epi.setAddress("you endpoint address");
 JettyHTTPDestination destination = df.getDestination(epi);
 ServerEngine engine= destination.getEngine();

Willem.



-----Original Message-----
From: Benson Margulies [mailto:bim2007@basistech.com]
Sent: Sat 7/14/2007 2:42
To: cxf-user@incubator.apache.org
Subject: RE: Getting the HTTP server off the bus
 
Willem,

In 2.0, there is no JettyHttpTransportFactory.
There is a JettyHTTPTransportFactory.

But it has no getEngine().

?


> -----Original Message-----
> From: Willem Jiang [mailto:ning.jiang@iona.com]
> Sent: Wednesday, July 11, 2007 10:35 PM
> To: cxf-user@incubator.apache.org
> Subject: Re: Getting the HTTP server off the bus
> 
> Hi Benson,
> 
> All the Jetty related stuff of CXF are in the
> cxf-rt-transports-http-jetty module.
> You can get the serverEngine which wraps the Jetty instance from the
> JettyHttpTransportFactory.
> 
> You can use the below codes to get the serverEngine.
> 
>         Bus bus =  BusFactory.getDefaultBus();
>         DestinationFactoryManager dfm =
> bus.getExtension(DestinationFactoryManager.class);
>         JettyHttpTransportFactory df = (JettyHttpTransportFactory)
>
dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configu
ra
> tion");
>        ServerEngine engine= df.getEngine();
> 
> The you just need to extends JettyHTTPHandler to deal with the static
> content directory, and add it into the engine by call addServant(URL
> url, JettyHTTPHandler handler).
> 
> You can find the detail information about the ServerEngine and
> JettyHTTPHandler from this directory
> 
>
https://svn.apache.org/repos/asf/incubator/cxf/trunk/rt/transports/http-
> jetty/src/main/java/org/apache/cxf/transport/http_jetty
> 
> Enjoy hacking the code !
> 
> Willem.
> 
> 
> Benson Margulies wrote:
> > Could someone reveal how to ask the default bus for the running
Jetty
> > instance? I want to add a static content directory for it to handle.
> >
> >
> >
> >
> >
> >
> >


RE: Getting the HTTP server off the bus

Posted by Benson Margulies <bi...@basistech.com>.
Willem,

In 2.0, there is no JettyHttpTransportFactory.
There is a JettyHTTPTransportFactory.

But it has no getEngine().

?


> -----Original Message-----
> From: Willem Jiang [mailto:ning.jiang@iona.com]
> Sent: Wednesday, July 11, 2007 10:35 PM
> To: cxf-user@incubator.apache.org
> Subject: Re: Getting the HTTP server off the bus
> 
> Hi Benson,
> 
> All the Jetty related stuff of CXF are in the
> cxf-rt-transports-http-jetty module.
> You can get the serverEngine which wraps the Jetty instance from the
> JettyHttpTransportFactory.
> 
> You can use the below codes to get the serverEngine.
> 
>         Bus bus =  BusFactory.getDefaultBus();
>         DestinationFactoryManager dfm =
> bus.getExtension(DestinationFactoryManager.class);
>         JettyHttpTransportFactory df = (JettyHttpTransportFactory)
>
dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configu
ra
> tion");
>        ServerEngine engine= df.getEngine();
> 
> The you just need to extends JettyHTTPHandler to deal with the static
> content directory, and add it into the engine by call addServant(URL
> url, JettyHTTPHandler handler).
> 
> You can find the detail information about the ServerEngine and
> JettyHTTPHandler from this directory
> 
>
https://svn.apache.org/repos/asf/incubator/cxf/trunk/rt/transports/http-
> jetty/src/main/java/org/apache/cxf/transport/http_jetty
> 
> Enjoy hacking the code !
> 
> Willem.
> 
> 
> Benson Margulies wrote:
> > Could someone reveal how to ask the default bus for the running
Jetty
> > instance? I want to add a static content directory for it to handle.
> >
> >
> >
> >
> >
> >
> >

Re: Getting the HTTP server off the bus

Posted by Willem Jiang <ni...@iona.com>.
Hi Benson,

All the Jetty related stuff of CXF are in the 
cxf-rt-transports-http-jetty module.
You can get the serverEngine which wraps the Jetty instance from the 
JettyHttpTransportFactory.

You can use the below codes to get the serverEngine.

        Bus bus =  BusFactory.getDefaultBus();
        DestinationFactoryManager dfm = 
bus.getExtension(DestinationFactoryManager.class);
        JettyHttpTransportFactory df = (JettyHttpTransportFactory) 
dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
       ServerEngine engine= df.getEngine();
 
The you just need to extends JettyHTTPHandler to deal with the static 
content directory, and add it into the engine by call addServant(URL 
url, JettyHTTPHandler handler).
    
You can find the detail information about the ServerEngine and 
JettyHTTPHandler from this directory

https://svn.apache.org/repos/asf/incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty

Enjoy hacking the code !

Willem.


Benson Margulies wrote:
> Could someone reveal how to ask the default bus for the running Jetty
> instance? I want to add a static content directory for it to handle.
>
>  
>
>  
>
>
>