views:

399

answers:

3

I am trying to swap out Sun's HTTPServer for the much better Jetty server, within an OSGi bundle, running on Equinox.

I have tried this:

System.setProperty("com.sun.net.httpserver.HttpServerProvider","org.mortbay.jetty.j2se6.JettyHttpServerProvider");

but when endpoint.publish(url) is called, and the server is spawned, it complains of a ClassNotFoundException for org.mortbay.jetty.j2se6.JettyHttpServerProvider.

However, the correct jars are in the bundle, and indeed in the Activator I can instantiate a org.mortbay.jetty.j2se6.JettyHttpServerProvider.

I think that this is a some kind of classpath issue - the spawned server is in a different classpath maybe? I have tried adding the JARs in at the JDK level, but this doesn't make any difference.

Can oanyone shed any light how on earth to get this working?

P.S. Maybe hideous System.setProperty calls will vanish from the world one day. Hopefully :)

A: 

Equinox has an implementation of the OSGi standard HttpService backed by Jetty 6.x. It just a matter of including the correct bundles and you have Jetty running within Equinox fairly easily. However, I found that a) Jetty is completely hidden from you, all you see is the HttpService interface, and b) the HttpService interface is rather simplistic. You can only add servlets+mappings and some static resources

omerkudat
A: 

I can't seem to reply to omerkudat, so I've had to put the reply here...

Metro doesn't seem to use Jetty if you include the osgi jar. You seem to need this:

http://docs.codehaus.org/display/JETTY/J2se6HttpServerSPI

Which I manually compiled, and set the System Property as above, unsuccessfylly.

mjgp2
A: 

The problem is that the factory is not OSGi aware, and the class that loads the factory has no reference to the Jetty implementation. It's not whether it's in your bundle (which you seem to have combined in one bundle) but rather that the factory method is in some core code, and that fails to be able to resolve Jetty.

The call to instantiate an HttpServer is not part of the Java6 API, bur rather one of Sun's internal classes - so this call will fail when running on non-Sun JVMs. It would be better to find out how to use Metro to do something other than use this factory method in order to get the class together.

AlBlue