You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/03/05 05:21:54 UTC

svn commit: r514542 - /incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/WicketFilter.java

Author: ehillenius
Date: Sun Mar  4 20:21:53 2007
New Revision: 514542

URL: http://svn.apache.org/viewvc?view=rev&rev=514542
Log:
organized members

Modified:
    incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/WicketFilter.java

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/WicketFilter.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/WicketFilter.java?view=diff&rev=514542&r1=514541&r2=514542
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/WicketFilter.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/WicketFilter.java Sun Mar  4 20:21:53 2007
@@ -62,6 +62,12 @@
 	 */
 	public static final String FILTER_PATH_PARAM = "filterPath";
 
+	/** Log. */
+	private static final Logger log = LoggerFactory.getLogger(WicketFilter.class);
+
+	/** The URL path prefix expected for (so called) resources (not html pages). */
+	private static final String RESOURCES_PATH_PREFIX = "/resources/";
+
 	/**
 	 * The servlet path holder when the WicketSerlvet is used. So that the
 	 * filter path will be computed with the first request. Note: This variable
@@ -69,12 +75,6 @@
 	 */
 	static final String SERVLET_PATH_HOLDER = "<servlet>";
 
-	/** Log. */
-	private static final Logger log = LoggerFactory.getLogger(WicketFilter.class);
-
-	/** The URL path prefix expected for (so called) resources (not html pages). */
-	private static final String RESOURCES_PATH_PREFIX = "/resources/";
-
 	/** See javax.servlet.FilterConfig */
 	private FilterConfig filterConfig;
 
@@ -145,14 +145,6 @@
 	}
 
 	/**
-	 * @return The class loader
-	 */
-	protected ClassLoader getClassLoader()
-	{
-		return Thread.currentThread().getContextClassLoader();
-	}
-	
-	/**
 	 * Handles servlet page requests.
 	 * 
 	 * @param servletRequest
@@ -172,19 +164,25 @@
 		{
 			Thread.currentThread().setContextClassLoader(getClassLoader());
 
-			// If the request does not provide information about the encoding of its
+			// If the request does not provide information about the encoding of
+			// its
 			// body (which includes POST parameters), than assume the default
-			// encoding as defined by the wicket application. Bear in mind that the
-			// encoding of the request usually is equal to the previous response.
+			// encoding as defined by the wicket application. Bear in mind that
+			// the
+			// encoding of the request usually is equal to the previous
+			// response.
 			// However it is a known bug of IE that it does not provide this
-			// information. Please see the wiki for more details and why all other
+			// information. Please see the wiki for more details and why all
+			// other
 			// browser deliberately copied that bug.
 			if (servletRequest.getCharacterEncoding() == null)
 			{
 				try
 				{
-					// The encoding defined by the wicket settings is used to encode
-					// the responses. Thus, it is reasonable to assume the request
+					// The encoding defined by the wicket settings is used to
+					// encode
+					// the responses. Thus, it is reasonable to assume the
+					// request
 					// has the same encoding. This is especially important for
 					// forms and form parameters.
 					servletRequest.setCharacterEncoding(webApplication.getRequestCycleSettings()
@@ -195,10 +193,10 @@
 					throw new WicketRuntimeException(ex.getMessage());
 				}
 			}
-	
+
 			// Create a new webrequest
 			final WebRequest request = webApplication.newWebRequest(servletRequest);
-	
+
 			// Are we using REDIRECT_TO_BUFFER?
 			if (webApplication.getRequestCycleSettings().getRenderStrategy() == RenderStrategy.REDIRECT_TO_BUFFER)
 			{
@@ -212,7 +210,7 @@
 					{
 						BufferedHttpServletResponse bufferedResponse = webApplication
 								.popBufferedResponse(sessionId, queryString);
-	
+
 						if (bufferedResponse != null)
 						{
 							bufferedResponse.writeTo(servletResponse);
@@ -223,20 +221,20 @@
 					}
 				}
 			}
-	
+
 			// First, set the webapplication for this thread
 			Application.set(webApplication);
-	
+
 			// Get session for request
 			final WebSession session = webApplication.getSession(request);
-	
+
 			// Create a response object and set the output encoding according to
 			// wicket's application setttings.
 			final WebResponse response = webApplication.newWebResponse(servletResponse);
 			response.setAjax(request.isAjax());
 			response.setCharacterEncoding(webApplication.getRequestCycleSettings()
 					.getResponseRequestEncoding());
-	
+
 			try
 			{
 				RequestCycle cycle = session.newRequestCycle(request, response);
@@ -254,10 +252,10 @@
 			{
 				// Close response
 				response.close();
-	
+
 				// Clean up thread local session
 				Session.unset();
-	
+
 				// Clean up thread local application
 				Application.unset();
 			}
@@ -311,7 +309,8 @@
 
 			rootPath = path;
 
-			if (filterPath != null) {
+			if (filterPath != null)
+			{
 				if (!path.endsWith("/"))
 				{
 					rootPath = rootPath + "/" + filterPath;
@@ -340,18 +339,19 @@
 			Thread.currentThread().setContextClassLoader(getClassLoader());
 
 			IWebApplicationFactory factory = getApplicationFactory();
-	
+
 			// Construct WebApplication subclass
 			this.webApplication = factory.createApplication(this);
-	
+
 			// Set this WicketServlet as the servlet for the web application
 			this.webApplication.setWicketFilter(this);
-	
-			// Store instance of this application object in servlet context to make
+
+			// Store instance of this application object in servlet context to
+			// make
 			// integration with outside world easier
 			String contextKey = "wicket:" + filterConfig.getFilterName();
 			filterConfig.getServletContext().setAttribute(contextKey, this.webApplication);
-	
+
 			filterPath = filterConfig.getInitParameter(FILTER_PATH_PARAM);
 
 			Application.set(webApplication);
@@ -380,6 +380,83 @@
 	}
 
 	/**
+	 * Is this a Wicket request?
+	 * 
+	 * @param request
+	 *            The servlet request
+	 * @return True if this is a Wicket request
+	 */
+	private boolean isWicketRequest(HttpServletRequest request)
+	{
+		String fullRootPath = getRootPath(request);
+		String url = request.getRequestURI();
+
+		// Homepage
+		if (url.startsWith(fullRootPath))
+		{
+			// url == "/"
+			// fullRootPath == ""
+			if (url.equals("/"))
+			{
+				return true;
+			}
+			// url == fullRootPath
+			if (url.length() == fullRootPath.length())
+			{
+				return true;
+			}
+			// NOTE: a semicolon may be delimiting the jsessionid in the URI
+			if ((url.length() > fullRootPath.length())
+					&& (url.charAt(fullRootPath.length()) == ';'))
+			{
+				return true;
+			}
+		}
+		// SharedResources
+		String tmp = Strings.join("/", fullRootPath, RESOURCES_PATH_PREFIX);
+		if (url.startsWith(tmp))
+		{
+			return true;
+		}
+		// Mounted url
+		String path = null;
+		if (fullRootPath.length() < url.length())
+		{
+			path = url.substring(fullRootPath.length());
+		}
+		else
+		{
+			path = url;
+		}
+
+		if (!path.startsWith("/"))
+		{
+			path = "/" + path;
+		}
+		return webApplication.getRequestCycleProcessor().getRequestCodingStrategy()
+				.urlCodingStrategyForPath(path) != null;
+	}
+
+	/**
+	 * If the response has not already a 'lastModified' header set and if
+	 * 'lastModified' >= 0 than set the response header accordingly.
+	 * 
+	 * @param resp
+	 * @param lastModified
+	 */
+	private void maybeSetLastModified(final HttpServletResponse resp, final long lastModified)
+	{
+		if (resp.containsHeader("Last-Modified"))
+		{
+			return;
+		}
+		if (lastModified >= 0)
+		{
+			resp.setDateHeader("Last-Modified", lastModified);
+		}
+	}
+
+	/**
 	 * Creates the web application factory instance.
 	 * 
 	 * If no APP_FACT_PARAM is specified in web.xml
@@ -403,8 +480,8 @@
 			try
 			{
 				// Try to find the specified factory class
-				final Class factoryClass = Thread.currentThread().getContextClassLoader().loadClass(
-						appFactoryClassName);
+				final Class factoryClass = Thread.currentThread().getContextClassLoader()
+						.loadClass(appFactoryClassName);
 
 				// Instantiate the factory
 				return (IWebApplicationFactory)factoryClass.newInstance();
@@ -434,6 +511,14 @@
 	}
 
 	/**
+	 * @return The class loader
+	 */
+	protected ClassLoader getClassLoader()
+	{
+		return Thread.currentThread().getContextClassLoader();
+	}
+
+	/**
 	 * Gets the last modified time stamp for the given request.
 	 * 
 	 * @param servletRequest
@@ -494,82 +579,5 @@
 			}
 		}
 		return -1;
-	}
-
-	/**
-	 * Is this a Wicket request?
-	 * 
-	 * @param request
-	 *            The servlet request
-	 * @return True if this is a Wicket request
-	 */
-	private boolean isWicketRequest(HttpServletRequest request)
-	{
-		String fullRootPath = getRootPath(request);
-		String url = request.getRequestURI();
-
-		// Homepage
-		if (url.startsWith(fullRootPath))
-		{
-			// url == "/"
-			// fullRootPath == ""
-			if (url.equals("/"))
-			{
-				return true;
-			}
-			// url == fullRootPath
-			if (url.length() == fullRootPath.length())
-			{
-				return true;
-			}
-			// NOTE: a semicolon may be delimiting the jsessionid in the URI
-			if ((url.length() > fullRootPath.length())
-					&& (url.charAt(fullRootPath.length()) == ';'))
-			{
-				return true;
-			}
-		}
-		// SharedResources
-		String tmp = Strings.join("/", fullRootPath, RESOURCES_PATH_PREFIX);
-		if (url.startsWith(tmp))
-		{
-			return true;
-		}
-		// Mounted url
-		String path = null;
-		if (fullRootPath.length() < url.length())
-		{
-			path = url.substring(fullRootPath.length());
-		}
-		else
-		{
-			path = url;
-		}
-
-		if (!path.startsWith("/"))
-		{
-			path = "/" + path;
-		}
-		return webApplication.getRequestCycleProcessor().getRequestCodingStrategy()
-				.urlCodingStrategyForPath(path) != null;
-	}
-
-	/**
-	 * If the response has not already a 'lastModified' header set and if
-	 * 'lastModified' >= 0 than set the response header accordingly.
-	 * 
-	 * @param resp
-	 * @param lastModified
-	 */
-	private void maybeSetLastModified(final HttpServletResponse resp, final long lastModified)
-	{
-		if (resp.containsHeader("Last-Modified"))
-		{
-			return;
-		}
-		if (lastModified >= 0)
-		{
-			resp.setDateHeader("Last-Modified", lastModified);
-		}
 	}
 }