|
|
|
Re: How to deploy a Servlet in a Desktop RCP App? [message #489219 is a reply to message #489190] |
Thu, 01 October 2009 22:12 |
Steve Viens Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Okay, got this working ... and like so many other times the answer was very simple. I had most of the solution already but was stuck on how to activate the 'registry' bundle (though for a while I didn't realize that was my problem). For future searchers here are the steps I followed:
1. Add the following bundles to your RCP appplication's list of dependent plug-ins.
javax.servlet
org.eclipse.equinox.http.registry
org.eclipse.equinox.http.jetty
2. Add a org.eclipse.equinox.http.registry.servlets extension point with a child of type 'servlet'. I used the values below:
class: viens.net.rcp.sample.servlet.servlets.HelloServlet
alias: /hello
load-on-startup: true
3. Finally, I added the following to the start() method of my Activator class (note that the port Jetty is listening on is 8080)
Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry");
if (bundle.getState() == Bundle.RESOLVED) {
bundle.start(Bundle.START_TRANSIENT);
}
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);
settings.put("context.path","/");
settings.put("context.sessioninactiveinterval",1800);
try {
JettyConfigurator.startServer(PLUGIN_ID + ".jetty",settings);
}
catch (Exception e) {
e.printStackTrace();
}
That's it. For anyone that want's to get this running quickly, my Servlet code is below.
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("HelloServlet.doGet Called");
resp.getWriter().println("<html><body>Hello, Eclipse RCP!</body></html>");
}
}
When you get this running point your browser to http://localhost:8080/hello and you should see the message "Hello, Eclipse RCP!".
Cheers,
Steve
PS: Thanks to the folks who posted some of the info above in the following "Running Jetty as a Workbench service" thread on EclipseZone:
http://www.eclipsezone.com/eclipse/forums/t107522.html
|
|
|
Powered by
FUDForum. Page generated in 0.03164 seconds