Metro + Jetty + OSGi = pain

烈酒焚心 提交于 2019-12-10 12:00:03

问题


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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1876126/metro-jetty-osgi-pain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!