You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2008/11/11 02:32:56 UTC
svn commit: r712904 - in /hadoop/core/branches/branch-0.19: CHANGES.txt
src/core/org/apache/hadoop/http/HttpServer.java
src/test/org/apache/hadoop/http/TestServletFilter.java
Author: szetszwo
Date: Mon Nov 10 17:32:55 2008
New Revision: 712904
URL: http://svn.apache.org/viewvc?rev=712904&view=rev
Log:
HADOOP-4282. Some user facing URLs are not filtered by user filters. (szetszwo)
Modified:
hadoop/core/branches/branch-0.19/CHANGES.txt
hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/http/HttpServer.java
hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/http/TestServletFilter.java
Modified: hadoop/core/branches/branch-0.19/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/CHANGES.txt?rev=712904&r1=712903&r2=712904&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.19/CHANGES.txt Mon Nov 10 17:32:55 2008
@@ -858,9 +858,6 @@
HADOOP-4288. Fixes a NPE problem in CapacityScheduler.
(Amar Kamat via ddas)
- HADOOP-3883. Limit namenode to assign at most one generation stamp for
- a particular block within a short period. (szetszwo)
-
HADOOP-4014. Create hard links with 'fsutil hardlink' on Windows. (shv)
HADOOP-4393. Merged org.apache.hadoop.fs.permission.AccessControlException
@@ -968,6 +965,9 @@
to reflect the information being displayed. (Sreekanth Ramakrishnan via
yhemanth)
+ HADOOP-4282. Some user facing URLs are not filtered by user filters.
+ (szetszwo)
+
Release 0.18.3 - Unreleased
BUG FIXES
@@ -983,6 +983,9 @@
HADOOP-4610. Always calculate mis-replicated blocks when safe-mode is
turned off. (shv)
+ HADOOP-3883. Limit namenode to assign at most one generation stamp for
+ a particular block within a short period. (szetszwo)
+
HADOOP-4556. Block went missing. (hairong)
Release 0.18.2 - 2008-11-03
Modified: hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/http/HttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/http/HttpServer.java?rev=712904&r1=712903&r2=712904&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/http/HttpServer.java (original)
+++ hadoop/core/branches/branch-0.19/src/core/org/apache/hadoop/http/HttpServer.java Mon Nov 10 17:32:55 2008
@@ -22,6 +22,7 @@
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,10 +36,8 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.log.LogLevel;
import org.apache.hadoop.util.ReflectionUtils;
-import org.mortbay.http.HttpContext;
import org.mortbay.http.SocketListener;
import org.mortbay.http.SslListener;
-import org.mortbay.http.handler.ResourceHandler;
import org.mortbay.jetty.servlet.Dispatcher;
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.jetty.servlet.WebApplicationContext;
@@ -60,6 +59,8 @@
protected final org.mortbay.jetty.Server webServer;
protected final WebApplicationContext webAppContext;
+ protected final Map<WebApplicationContext, Boolean> defaultContexts =
+ new HashMap<WebApplicationContext, Boolean>();
protected final boolean findPort;
protected final SocketListener listener;
private SslListener sslListener;
@@ -91,6 +92,7 @@
final String appDir = getWebAppsPath();
webAppContext = webServer.addWebApplication("/", appDir + "/" + name);
+ addDefaultApps(appDir);
final FilterInitializer[] initializers = getFilterInitializers(conf);
if (initializers != null) {
@@ -98,7 +100,7 @@
c.initFilter(this);
}
}
- addWebapps(appDir);
+ addDefaultServlets();
}
/** Get an array of FilterConfiguration specified in the conf */
@@ -121,11 +123,11 @@
}
/**
- * Add webapps and servlets.
+ * Add default apps.
* @param appDir The application directory
* @throws IOException
*/
- protected void addWebapps(final String appDir) throws IOException {
+ protected void addDefaultApps(final String appDir) throws IOException {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined.
String logDir = System.getProperty("hadoop.log.dir");
if (logDir != null) {
@@ -134,7 +136,12 @@
// set up the context for "/static/*"
addContext("/static/*", appDir + "/static", true);
-
+ }
+
+ /**
+ * Add default servlets.
+ */
+ protected void addDefaultServlets() {
// set up default servlets
addServlet("stacks", "/stacks", StackServlet.class);
addServlet("logLevel", "/logLevel", LogLevel.Servlet.class);
@@ -145,16 +152,11 @@
* @param pathSpec The path spec for the context
* @param dir The directory containing the context
* @param isFiltered if true, the servlet is added to the filter path mapping
+ * @throws IOException
*/
- protected void addContext(String pathSpec, String dir, boolean isFiltered) {
- HttpContext context = new HttpContext();
- context.setContextPath(pathSpec);
- context.setResourceBase(dir);
- context.addHandler(new ResourceHandler());
- webServer.addContext(context);
- if (isFiltered) {
- addFilterPathMapping(pathSpec);
- }
+ protected void addContext(String pathSpec, String dir, boolean isFiltered) throws IOException {
+ WebApplicationContext webAppCtx = webServer.addWebApplication(pathSpec, dir);
+ defaultContexts.put(webAppCtx, isFiltered);
}
/**
@@ -207,11 +209,30 @@
/** {@inheritDoc} */
public void addFilter(String name, String classname,
Map<String, String> parameters) {
- WebApplicationHandler handler = webAppContext.getWebApplicationHandler();
- LOG.info("adding " + name + " (class=" + classname + ")");
+ final String[] USER_FACING_URLS = {"*.html", "*.jsp"};
+ defineFilter(webAppContext, name, classname, parameters, USER_FACING_URLS);
+
+ final String[] ALL_URLS = { "/*" };
+ for (Map.Entry<WebApplicationContext, Boolean> e : defaultContexts
+ .entrySet()) {
+ if (e.getValue()) {
+ WebApplicationContext ctx = e.getKey();
+ defineFilter(ctx, name, classname, parameters, ALL_URLS);
+ LOG.info("Added filter " + name + " (class=" + classname
+ + ") to context " + ctx.getName());
+ }
+ }
filterNames.add(name);
+ }
+ /**
+ * Define a filter for a context and set up default url mappings.
+ */
+ protected void defineFilter(WebApplicationContext ctx, String name,
+ String classname, Map<String, String> parameters, String[] urls) {
+
+ WebApplicationHandler handler = ctx.getWebApplicationHandler();
FilterHolder holder = handler.defineFilter(name, classname);
if (parameters != null) {
for(Map.Entry<String, String> e : parameters.entrySet()) {
@@ -219,8 +240,7 @@
}
}
- final String[] USER_FACING_URLS = {"*.html", "*.jsp"};
- for(String url : USER_FACING_URLS) {
+ for (String url : urls) {
handler.addFilterPathMapping(url, name, Dispatcher.__ALL);
}
}
Modified: hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/http/TestServletFilter.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/http/TestServletFilter.java?rev=712904&r1=712903&r2=712904&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/http/TestServletFilter.java (original)
+++ hadoop/core/branches/branch-0.19/src/test/org/apache/hadoop/http/TestServletFilter.java Mon Nov 10 17:32:55 2008
@@ -110,9 +110,12 @@
final String fsckURL = "/fsck";
final String stacksURL = "/stacks";
final String ajspURL = "/a.jsp";
- final String[] urls = {fsckURL, stacksURL, ajspURL};
+ final String logURL = "/logs/a.log";
+ final String hadooplogoURL = "/static/hadoop-logo.jpg";
+
+ final String[] urls = {fsckURL, stacksURL, ajspURL, logURL, hadooplogoURL};
final Random ran = new Random();
- final int[] sequence = new int[20];
+ final int[] sequence = new int[50];
final int[] counts = new int[urls.length];
//generate a random sequence and update counts
@@ -140,7 +143,8 @@
if (counts[i] == 0) {
assertFalse(COUNTS.containsKey(urls[i]));
} else {
- assertEquals(counts[i], COUNTS.remove(urls[i]).intValue());
+ assertEquals("url[" + i + "]=" + urls[i],
+ Integer.valueOf(counts[i]), COUNTS.remove(urls[i]));
}
}
assertTrue(COUNTS.isEmpty());