As mentioned earlier, recently was working on using embedded Jetty server in an OSGi environment. Though the information is available on web, but quite scattered. Especially how to configure or debug jetty. So, below is the collated information:
Once you have the up and running servlet as per the steps at:
http ://b ryan hunt .wor dpre ss.c om/2 010/ 05/1 4/os gi-a s-a- web- appl icat ion- serv er/
You can do away with auto start of bundles in the launch configuration, use the following code in the activator of your bundle
http
You can do away with auto start of bundles in the launch configuration, use the following code in the activator of your bundle
Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry"); if (bundle.getState() == Bundle.RESOLVED) { bundle.start(Bundle.START_TRANSIENT); }
To make sure your bundle auto starts, implement the startup extension. In your plugin.xml put this:
Configure Jetty:
Now, many times you will not have the option to change the config.ini to provide the port, or you want to configure the Jetty from within your application, there you will need to use the JettyConfigurator class. Use the following code in the activator of your bundle
Dictionary settings = new Hashtable(); settings.put("http.enabled", Boolean.TRUE); settings.put("http.port", 8080); settings.put("http.host", "0.0.0.0"); settings.put("https.enabled", Boolean.FALSE); try { JettyConfigurator.startServer("my.jetty", settings); } catch (Exception e) { e.printStackTrace(); }You can configure many other settings using the JettyConfigurator as mentioned above.
No comments:
Post a Comment