FileDocCategorySizeDatePackage
AdHocContextValve.javaAPI DocGlassfish v2 API5595Fri May 04 22:36:00 BST 2007com.sun.enterprise.web

AdHocContextValve

public class AdHocContextValve extends Object implements org.apache.catalina.Valve
Implementation of StandardContextValve which is added as the base valve to a web module's ad-hoc pipeline. A web module's ad-hoc pipeline is invoked for any of the web module's ad-hoc paths. The AdHocContextValve is responsible for invoking the ad-hoc servlet associated with the ad-hoc path.
author
Jan Luehe

Fields Summary
private static final Logger
LOGGER
private static final String
VALVE_INFO
private WebModule
context
Constructors Summary
public AdHocContextValve(WebModule context)
Constructor.



          
       
        this.context = context;
    
Methods Summary
public java.lang.StringgetInfo()
Returns descriptive information about this valve.

        return VALVE_INFO;
    
public intinvoke(org.apache.catalina.Request request, org.apache.catalina.Response response)
Processes the given request by passing it to the ad-hoc servlet associated with the request path (which has been determined, by the associated web module, to be an ad-hoc path).

param
request The request to process
param
response The response to return


        HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
        HttpServletResponse hres = (HttpServletResponse) response.getResponse();

        String adHocServletName =
            context.getAdHocServletName(hreq.getServletPath());

        Wrapper adHocWrapper = (Wrapper) context.findChild(adHocServletName);
        if (adHocWrapper != null) {
            Servlet adHocServlet = null;
            try {
                adHocServlet = adHocWrapper.allocate();
                adHocServlet.service(hreq, hres);
            } catch (Throwable t) {
                hres.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                String msg = LOGGER.getResourceBundle().getString(
                    "webmodule.adHocContextValve.adHocServletServiceError");
                msg = MessageFormat.format(
                            msg,
                            new Object[] { hreq.getServletPath() });
                response.setDetailMessage(msg);
                return END_PIPELINE;
            } finally {
                if (adHocServlet != null) {
                    adHocWrapper.deallocate(adHocServlet);
                }
            }
        } else {
            hres.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            String msg = LOGGER.getResourceBundle().getString(
                "webmodule.adHocContextValve.noAdHocServlet");
            msg = MessageFormat.format(
                            msg,
                            new Object[] { hreq.getServletPath() });
            response.setDetailMessage(msg);
            return END_PIPELINE;
        }

        return END_PIPELINE;
    
public voidpostInvoke(org.apache.catalina.Request request, org.apache.catalina.Response response)

        // Do nothing