Skip to main content

developerWorks >  WebSphere  >  Forums  >  IBM WebSphere Portlet Factory - Best Practices  >  developerWorks

Running a simple servlet in a model    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is not answered.

Permlink Replies: 5 - Pages: 1 - Last Post: Nov 5, 2009 11:14 AM Last Post By: mburati Threads: [ Previous | Next ]
asilter

Posts: 7
Registered: Nov 03, 2009 01:26:48 AM
Running a simple servlet in a model
Posted: Nov 03, 2009 01:32:10 AM
 
Click to report abuse...   Click to reply to this thread Reply
I couldn't find a builder like Servlet Builder in builders list. Our customer wants to run servlets from their own servlet library.

Is there a way of running a simple servlet(implementing HttpServlet interface) from a Websphere Portlet Factory Model?

Thanks.
mburati

Posts: 1,690
Registered: May 10, 2006 03:35:21 PM
Re: Running a simple servlet in a model
Posted: Nov 03, 2009 08:57:37 AM   in response to: asilter in response to: asilter's post
 
Click to report abuse...   Click to reply to this thread Reply
To run a servlet in any web application, basically you need the servlet implementation available to the appserver's classloader (eg, either in a shared location or preferably in the WAR's WEB-INF/lib folder) and you need an entry in the web application's web.xml deployment descriptor.

The web.xml deployment descriptor is generated from a template when WPF generates the WAR, depending on which type of WAR it's generating, where the templates live under the project's WEB-INF/bin/deployment/... folder.

For WPF 6.1.2 and prior, you have to edit the web.xml template itself, which will allow you to add to the generated web.xml, but has the side effect that during upgrade you are prompted whether to overwrite your changes (and thus lose your changes unless you copy them and reapply them) or not overwrite (and thus possibly miss an important update that the WPF upgrade provides). In the WPF next beta that's out there now, and in the upcoming WPF 6.1.5 release, there is a new capability to add "fragments" of a web.xml (and portlet.xml) in separate files under WEB-INF/bin/deployment/extensions/... which will then be added to web.xml and/or portlet.xml when we generate them, thus avoiding the upgrade issue with out of the box WPF files.

What is it that these servlet(s) do that you're trying to preserve? Sometimes the classes from former projects are better used via LJOs than via hard coded servlets (since the latter often means you're not making best use of WPF automation capabilities).

..mb1
asilter

Posts: 7
Registered: Nov 03, 2009 01:26:48 AM
Re: Running a simple servlet in a model
Posted: Nov 03, 2009 09:46:34 AM   in response to: mburati in response to: mburati's post
 
Click to report abuse...   Click to reply to this thread Reply
Hi,

The customer has a oldly hard-coded servlet library which has a set of servlets. They strictly want to use them for some data oriented user interfaces.

I put an simple httpservlet class to the classpath location, implementing doGet interface.
I registered the simple servlet definition and url-mapping in web.xml.

http://localhost:9080/MyProject/webengine/*
works fine.

but my servlet definition;
http://localhost:9080/MyProject/servlets/simpleServlet
fails, with a message The page cannot be displayed.

This configuration works in Tomcat deployment, but not in WAS.
Does WAS class loader recognize standart HttpServlet class? I expected it to be so.

Above text still keeps itself as a problem, now another question:)
can you suggest an interface in WAS, which enables those html inputs to be seen in a portlet?
mburati

Posts: 1,690
Registered: May 10, 2006 03:35:21 PM
Re: Running a simple servlet in a model
Posted: Nov 03, 2009 01:43:57 PM   in response to: asilter in response to: asilter's post
 
Click to report abuse...   Click to reply to this thread Reply
You may not have placed the servlet info in the right template.
I believe Tomcat would use standalone.web.xml as the template, WASCE would use wasce.web.xml and a jsr portlet WAR would use portlet.standard.web.xml as the template for web.xml.

I still recommend trying to convince the customer that using the code (as opposed to the old servlets) in your WPF portlets would give you a lot more flexibility and value out of WPF rather than hardwiring old servlets into the WAR.

Another option may be to use WP Web Clipping (outside of WPF) for the old servlet based stuff, and build the new portlets with WPF.

..mb1
asilter

Posts: 7
Registered: Nov 03, 2009 01:26:48 AM
Re: Running a simple servlet in a model
Posted: Nov 05, 2009 08:05:48 AM   in response to: mburati in response to: mburati's post
 
Click to report abuse...   Click to reply to this thread Reply
if I configure the correct deploy descriptor and put the servlet implementations in correct place in which the classloader looks to load, do my servlets output into the portlet division(region)?
Remember there's an anchor href in the page builder in the model, that points my servlet url?
mburati

Posts: 1,690
Registered: May 10, 2006 03:35:21 PM
Re: Running a simple servlet in a model
Posted: Nov 05, 2009 11:14:00 AM   in response to: asilter in response to: asilter's post
 
Click to report abuse...   Click to reply to this thread Reply
No, they wouldn't by default do that.

Portlets receive a PortletRequest from the Portal, do their thing, and then the PortletResponse is handed back to the Portal's controller and the portal takes any output sent to portlet response and figures out how and where to place it within the portal page.

Servlets receive a Servlet Request from the AppServer's servlet container, and typically write to the Servlet output stream (either directly or by dispatching to a JSP page). So if you go directly to a servlet, you're not going through the portal controller and thus your output won't by default be part of the portal page.

If you put a link to a servlet URL in a portlet page (WPF or any other) then what's most likely to happen is that the browser will go directly to that servlet when you click on it, and get the servlet's output and render that as the entire response page, so you'd effectively be leaving the portal.

You may be able to use an IFrame builder and have the IFrame go to the servlet (thus the browser would continue to hang onto the outer portal page). Or you may be able to use the Portal's Web Clipping functionality to turn the existing servlet based app into a portlet.

But in either of those cases, you're not really using the value of WPF, which is automating the back end access and automating and customizing the user interface. The best case would be to try to use the existing Java code that the servlets are based on, from portlet model(s), so that you can actually make use of a lot of WPF's automation and benefits..

..mb1
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums