1 22 23 package org.jboss.web.php; 24 25 import java.io.IOException ; 26 27 import javax.servlet.ServletConfig ; 28 import javax.servlet.ServletException ; 29 import javax.servlet.UnavailableException ; 30 import javax.servlet.http.HttpServlet ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 import org.apache.catalina.Globals; 35 import org.apache.catalina.util.StringManager; 36 37 44 public class Handler extends HttpServlet 45 { 46 47 48 private int debug = 0; 49 50 51 private int bufferSize = 4096; 52 53 57 private ServletConfig servletConfig = null; 58 59 62 private StringManager sm = 63 StringManager.getManager(Constants.Package); 64 65 66 67 protected boolean syntaxHighlight = false; 68 69 70 private String parameterEncoding = System.getProperty("file.encoding", 71 "UTF-8"); 72 73 79 private String scriptPathPrefix = null; 80 81 96 public void init(ServletConfig servletConfig) 97 throws ServletException 98 { 99 super.init(servletConfig); 100 101 if (!Library.isInitialized()) { 102 try { 104 Library.initialize(null); 105 } catch(Exception e) { 106 e.printStackTrace(); 107 } 108 } 109 110 if (!Library.isInitialized()) 111 throw new UnavailableException 112 (sm.getString("handler.missing")); 113 114 this.servletConfig = servletConfig; 115 116 String servletName = servletConfig.getServletName(); 118 if (servletName == null) 119 servletName = ""; 120 if (servletName.startsWith("org.apache.catalina.INVOKER.")) 121 throw new UnavailableException 122 ("Cannot invoke Handler through the invoker"); 123 124 125 String value = null; 127 try { 128 value = servletConfig.getInitParameter("debug"); 129 debug = Integer.parseInt(value); 130 scriptPathPrefix = 131 servletConfig.getInitParameter("scriptPathPrefix"); 132 value = servletConfig.getInitParameter("bufferSize"); 133 if (value != null) { 134 bufferSize = Integer.parseInt(value); 135 if (bufferSize < 1024) 136 bufferSize = 1024; 137 log("init: bufferSize set to " + bufferSize); 138 } 139 } catch (Throwable t) { 140 } 142 log("init: loglevel set to " + debug); 143 144 value = servletConfig.getInitParameter("parameterEncoding"); 145 if (value != null) { 146 parameterEncoding = value; 147 } 148 } 149 150 153 public void destroy() 154 { 155 this.servletConfig = null; 156 } 157 158 private static native int php(byte[] buf, 159 ScriptEnvironment env, 160 HttpServletRequest req, 161 HttpServletResponse res, 162 String requestMethod, 163 String queryString, 164 String contentType, 165 String authUser, 166 String requestURI, 167 String pathTranslated, 168 int contentLength, 169 boolean syntaxHighlight); 170 171 183 protected void service(HttpServletRequest req, HttpServletResponse res) 184 throws ServletException , IOException 185 { 186 187 if (req.getAttribute(Globals.INVOKED_ATTR) != null) 189 throw new UnavailableException 190 ("Cannot invoke PHP Getaway Handler through the invoker"); 191 192 ScriptEnvironment env = new ScriptEnvironment(req, 193 getServletContext(), 194 scriptPathPrefix); 195 if (env.isValid()) { 196 byte[] buf = new byte[bufferSize]; 197 int rv = php(buf, 198 env, 199 req, 200 res, 201 req.getMethod(), 202 req.getQueryString(), 203 req.getContentType(), 204 req.getRemoteUser(), 205 req.getRequestURI(), 206 env.getFullPath(), 207 req.getContentLength(), 208 syntaxHighlight); 209 } 210 else { 211 res.setStatus(HttpServletResponse.SC_NOT_FOUND); 212 } 213 } 214 215 public static void log(Handler handler, String msg) 216 { 217 } 219 } 220 | Popular Tags |