org.apache.geronimo.console.servlet
public class: GenericForwardServlet [javadoc |
source]
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.geronimo.console.servlet.GenericForwardServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Servlet that forwards GET and POST requests to a servlet in an alternate
context. The servlet path and alternate context are defined in GBeans of
type ContextForward, and this one servlet handles the forwarding for all
those different paths.
NOTE: This does not work for DWR, because it changes the request path info
while forwarding, and DWR requires the exact initial request info in order
to construct URLs in the data that it returns. It should work to forward
to most typical servlets, JSPs, and static content.
Methods from javax.servlet.http.HttpServlet: |
---|
class$, doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service |
Methods from javax.servlet.GenericServlet: |
---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log, service |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.geronimo.console.servlet.GenericForwardServlet Detail: |
public void destroy() {
if(listener != null) {
kernel.getLifecycleMonitor().removeLifecycleListener(listener);
listener = null;
}
}
|
public void doGet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
|
public void doPost(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
String path = req.getPathInfo();
if(path == null) {
log.error("Unable to forward request; no path information provided. Path is used to identify where to forward to.");
throw new ServletException("Unable to forward request");
}
ForwardData forward = null;
for (Iterator it = forwards.keySet().iterator(); it.hasNext();) {
String prefix = (String) it.next();
if(path.startsWith(prefix)) {
forward = (ForwardData) forwards.get(prefix);
path = path.substring(prefix.length());
break;
}
}
if(forward == null) {
log.error("Unable to forward URL "+path+"; does not match any known ContextForward definitions.");
throw new ServletException("Unable to forward request");
}
if(!path.equals("") && !path.startsWith("/")) path = "/"+path;
String queryString = req.getQueryString();
if (queryString != null) {
path += "?" + queryString;
}
path = forward.getServletPath()+path;
ServletContext ctx = forward.getForwardContext(getServletContext());
if (ctx == null) {
log.error("Unable to forward URL " + path + ". Context not found: " + forward.getContextPath());
throw new ServletException("Unable to forward request");
}
RequestDispatcher dispatcher = ctx.getRequestDispatcher(path);
dispatcher.forward(req, resp);
}
|
public void init(ServletConfig config) throws ServletException {
super.init(config);
kernel = KernelRegistry.getSingleKernel();
AbstractNameQuery query = new AbstractNameQuery(ContextForward.class.getName());
Set set = kernel.listGBeans(query);
for (Iterator it = set.iterator(); it.hasNext();) {
AbstractName name = (AbstractName) it.next();
addGBean(name);
}
kernel.getLifecycleMonitor().addLifecycleListener(listener = new LifecycleAdapter() {
public void running(AbstractName abstractName) {
addGBean(abstractName);
}
public void stopping(AbstractName abstractName) {
removeGBean(abstractName);
}
public void stopped(AbstractName abstractName) {
removeGBean(abstractName);
}
public void failed(AbstractName abstractName) {
removeGBean(abstractName);
}
public void unloaded(AbstractName abstractName) {
removeGBean(abstractName);
}
}, query);
}
|