PlanetJava
Custom Search

java-stripes-user
[Top] [All Lists]

Stripes in an OSGi Bundle

Subject: Stripes in an OSGi Bundle
Date: Wed, 20 Jun 2007 13:57:53 -0400
Hi,
I've been setting up OSGi in a servlet container, so that I can have a web 
application that consists of multiple OSGi bundles (which has many benefits, 
including the ability to explicitly declare bundle dependencies, make Java 
packages private to a particular bundle, dynamically load/unload bundles, 
etc.).  There is a guide for the Equinox OSGi implementation that I followed to 
set this up and get servlets/JSPs working 
(http://www.eclipse.org/equinox/server/http_in_container.php).  When I 
subsequently attempted to get Stripes working in a bundle, I ran into one issue.
To get server-side OSGi working transparently (i.e. servlets/jsps work without 
OSGi-specific changes), there are many cases where HttpServletRequestWrapper 
subclasses are used to abstract away OSGi details.  The general pattern for 
these subclasses is that a custom RequestDispatcher is returned in the 
getRequestDispatcher() method that strips away the wrapper when a servlet 
forward or include is performed.  Stripes v1.4.3 uses its own 
HttpServletRequestWrapper subclass (StripesRequestWrapper) that does not follow 
this pattern.  This was preventing Stripes-in-a-bundle from working correctly, 
because the StripesRequestWrapper was not getting stripped away in a forward, 
causing all HttpServletRequestWrappers nested in the stripes wrapper to also 
not get stripped away.  I worked around this issue by subclassing StipesFilter 
and StripesRequestWrapper to conform to the OSGi pattern for HttpSer
 vletRequestWrapper subclasses (see code below).
My question is this: Is there any reason why StripesRequestWrapper does not 
include the dispatcher behavior from my OSGIStripesRequestWrapper subclass 
(i.e. defining a dispatcher that strips the wrapper away on a forward)?  Would 
it be worthwhile to consider moving the changes in OSGIStripesRequestWrapper to 
StripesRequestWrapper?  I realize that there could be an issue if the filter is 
only called on the initial request, but not on a forward (the 
StripesRequestWrapper would be stripped but never reapplied).  With the OSGi 
bundle setup that I'm using, the filter is getting called both on the initial 
request and on forwards.
Thanks,
Raj Doshi
public class OSGIStripesFilter extends StripesFilter {
@Override
protected StripesRequestWrapper wrapRequest(HttpServletRequest servletRequest) 
throws StripesServletException {
return new OSGIStripesRequestWrapper(servletRequest);
}
}
public class OSGIStripesRequestWrapper extends StripesRequestWrapper {
public OSGIStripesRequestWrapper(HttpServletRequest request) throws 
StripesServletException {
super(request);
}
@Override
public RequestDispatcher getRequestDispatcher(String arg0) {
return new StripesRequestDispatcher(super.getRequestDispatcher(arg0));
}
private class StripesRequestDispatcher implements RequestDispatcher {
private RequestDispatcher requestDispatcher;
public StripesRequestDispatcher(RequestDispatcher requestDispatcher) {
this.requestDispatcher = requestDispatcher;
}
public void forward(ServletRequest req, ServletResponse resp) throws 
ServletException, IOException {
if (req instanceof OSGIStripesRequestWrapper)
req = ((OSGIStripesRequestWrapper) req).getRequest();
requestDispatcher.forward(req, resp);
}
public void include(ServletRequest req, ServletResponse resp) throws 
ServletException, IOException {
if (req instanceof OSGIStripesRequestWrapper)
req = ((OSGIStripesRequestWrapper) req).getRequest();
requestDispatcher.include(req, resp);
}
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
msgmiddle
<Prev in Thread] Current Thread [Next in Thread>
Current Sitemap | © 2012 planetjava | Contact | Privacy Policy