1 23 24 package com.sun.enterprise.web; 25 26 import java.io.IOException ; 27 import java.text.MessageFormat ; 28 import java.util.logging.Logger ; 29 import javax.servlet.Servlet ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import org.apache.catalina.Request; 34 import org.apache.catalina.Response; 35 import org.apache.catalina.Valve; 36 import org.apache.catalina.Wrapper; 37 import com.sun.logging.LogDomains; 38 39 51 public class AdHocContextValve implements Valve { 52 53 private static final Logger LOGGER = 54 LogDomains.getLogger(LogDomains.WEB_LOGGER); 55 56 private static final String VALVE_INFO = 57 "com.sun.enterprise.web.AdHocContextValve"; 58 59 private WebModule context; 61 62 63 66 public AdHocContextValve(WebModule context) { 67 this.context = context; 68 } 69 70 71 74 public String getInfo() { 75 return VALVE_INFO; 76 } 77 78 79 87 public int invoke(Request request, Response response) 88 throws IOException , ServletException { 89 90 HttpServletRequest hreq = (HttpServletRequest ) request.getRequest(); 91 HttpServletResponse hres = (HttpServletResponse ) response.getResponse(); 92 93 String adHocServletName = 94 context.getAdHocServletName(hreq.getServletPath()); 95 96 Wrapper adHocWrapper = (Wrapper) context.findChild(adHocServletName); 97 if (adHocWrapper != null) { 98 Servlet adHocServlet = null; 99 try { 100 adHocServlet = adHocWrapper.allocate(); 101 adHocServlet.service(hreq, hres); 102 } catch (Throwable t) { 103 hres.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 104 String msg = LOGGER.getResourceBundle().getString( 105 "webmodule.adHocContextValve.adHocServletServiceError"); 106 msg = MessageFormat.format( 107 msg, 108 new Object [] { hreq.getServletPath() }); 109 response.setDetailMessage(msg); 110 return END_PIPELINE; 111 } finally { 112 if (adHocServlet != null) { 113 adHocWrapper.deallocate(adHocServlet); 114 } 115 } 116 } else { 117 hres.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 118 String msg = LOGGER.getResourceBundle().getString( 119 "webmodule.adHocContextValve.noAdHocServlet"); 120 msg = MessageFormat.format( 121 msg, 122 new Object [] { hreq.getServletPath() }); 123 response.setDetailMessage(msg); 124 return END_PIPELINE; 125 } 126 127 return END_PIPELINE; 128 } 129 130 131 public void postInvoke(Request request, Response response) 132 throws IOException , ServletException { 133 } 135 136 } 137 138 | Popular Tags |