Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to deploy a Servlet in a Desktop RCP App?
How to deploy a Servlet in a Desktop RCP App? [message #488972] Thu, 01 October 2009 00:42 Go to next message
Steve Viens is currently offline Steve ViensFriend
Messages: 13
Registered: July 2009
Junior Member
I'm having a little trouble finding a good/clear reference for deploying a Servlet within an RCP Application. I successfully got a Servlet running as an OSGI app/service but I'm confused about how to configure a servlet engine within an RCP app. Can anyone explain how to go about this or provide a good reference for how to do this? Here's what I'm trying to do (in case you're interested).

I'm writing an RCP-based CTI application (Computer Telephony Integration) for a Call Center and need to provide integration with an existing web application. Call Center Reps would like the RCP app to initiate a phone call when they click on a phone number displayed in thier web application.

To do this, I though I'd include an http "clicktodial" servlet in the RCP application that when invoked with a phone number parameter could initiate the phone call. We would then replace the plain-text phone numbers displayed in the web app with hyperlinks that invoked the Servlet (by specifying localhost as the host in the url). One of these hyperlinks might look something like the example below

http://localhost:97531/clicktodial?phone=978-867-5309

Clicking on the hyperlink would attempt to call the Servlet in the RCP application running on the local device. Any opionon of this strategy is welcome as well. Smile

Steve
Re: How to deploy a Servlet in a Desktop RCP App? [message #489115 is a reply to message #488972] Thu, 01 October 2009 14:30 Go to previous messageGo to next message
Chris Aniszczyk is currently offline Chris AniszczykFriend
Messages: 674
Registered: July 2009
Senior Member
Steve Viens wrote:
> I'm having a little trouble finding a good/clear reference for deploying
> a Servlet within an RCP Application. I successfully got a Servlet
> running as an OSGI app/service but I'm confused about how to configure a
> servlet engine within an RCP app. Can anyone explain how to go about
> this or provide a good reference for how to do this? Here's what I'm
> trying to do (in case you're interested).
>
> I'm writing an RCP-based CTI application (Computer Telephony
> Integration) for a Call Center and need to provide integration with an
> existing web application. Call Center Reps would like the RCP app to
> initiate a phone call when they click on a phone number displayed in
> thier web application.
>
> To do this, I though I'd include an http "clicktodial" servlet in the
> RCP application that when invoked with a phone number parameter could
> initiate the phone call. We would then replace the plain-text phone
> numbers displayed in the web app with hyperlinks that invoked the
> Servlet (by specifying localhost as the host in the url). One of these
> hyperlinks might look something like the example below
>
> http://localhost:97531/clicktodial?phone=978-867-5309
>
> Clicking on the hyperlink would attempt to call the Servlet in the RCP
> application running on the local device. Any opionon of this strategy is
> welcome as well. :)

This should be pretty easy since you already have a servlet running as
an OSGi application... since RCP is in essence an OSGi application :)

Have you tried this presentation for extra help?

http://www.slideshare.net/eclipseguru/building-serverside-ec lipse-based-web-applications?type=powerpoint

If you're running the browser widget in Eclipse and access your servlet,
you can add a location listener on the browser and do whatever you want.
I'm not sure if this is what you need though.

Cheers,

Chris Aniszczyk | EclipseSource Austin | +1 860 839 2465
http://twitter.com/eclipsesource | http://twitter.com/caniszczyk
Re: How to deploy a Servlet in a Desktop RCP App? [message #489190 is a reply to message #489115] Thu, 01 October 2009 19:00 Go to previous messageGo to next message
Steve Viens is currently offline Steve ViensFriend
Messages: 13
Registered: July 2009
Junior Member
Hi Chris,

I'm not really finding this to be very easy but I am relatively new to Eclipse RCP and OSGi, etc. This is my first RCP application. I have the RCP application complete with SWT based UI and can launch via a Eclipse Application launch configuration (and a .product file) and I can run Jetty via an OSGi Framework launch configuration ... I'm having trouble determining what I need to do to start Jetty via the Eclipse launch configuration.

Unfortunately there are a quite a few expainations of running Equinox Jetty in server side OSGi applications (like the reference you provided) but I haven't found much/anything regarding running Jetty within a desktop bound RCP application (though I've found plenty of posts from people looking to do the same thing).

Sad

Thanks for trying to help.

Steve
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 Go to previous message
Steve Viens is currently offline Steve ViensFriend
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


Previous Topic:Commands and default behavior: Save
Next Topic:How to open dialog windows in center of view?
Goto Forum:
  


Current Time: Sun Dec 21 09:19:09 GMT 2014

Powered by FUDForum. Page generated in 0.04617 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software