|
@@ -46,6 +46,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
+import org.apache.hadoop.HadoopIllegalArgumentException;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.conf.ConfServlet;
|
|
import org.apache.hadoop.conf.ConfServlet;
|
|
@@ -118,18 +119,117 @@ public class HttpServer implements FilterContainer {
|
|
protected final Map<Context, Boolean> defaultContexts =
|
|
protected final Map<Context, Boolean> defaultContexts =
|
|
new HashMap<Context, Boolean>();
|
|
new HashMap<Context, Boolean>();
|
|
protected final List<String> filterNames = new ArrayList<String>();
|
|
protected final List<String> filterNames = new ArrayList<String>();
|
|
- private static final int MAX_RETRIES = 10;
|
|
|
|
static final String STATE_DESCRIPTION_ALIVE = " - alive";
|
|
static final String STATE_DESCRIPTION_ALIVE = " - alive";
|
|
static final String STATE_DESCRIPTION_NOT_LIVE = " - not live";
|
|
static final String STATE_DESCRIPTION_NOT_LIVE = " - not live";
|
|
|
|
|
|
private final boolean listenerStartedExternally;
|
|
private final boolean listenerStartedExternally;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Class to construct instances of HTTP server with specific options.
|
|
|
|
+ */
|
|
|
|
+ public static class Builder {
|
|
|
|
+ String name;
|
|
|
|
+ String bindAddress;
|
|
|
|
+ Integer port;
|
|
|
|
+ Boolean findPort;
|
|
|
|
+ Configuration conf;
|
|
|
|
+ Connector connector;
|
|
|
|
+ String[] pathSpecs;
|
|
|
|
+ AccessControlList adminsAcl;
|
|
|
|
+ boolean securityEnabled = false;
|
|
|
|
+ String usernameConfKey = null;
|
|
|
|
+ String keytabConfKey = null;
|
|
|
|
+
|
|
|
|
+ public Builder setName(String name){
|
|
|
|
+ this.name = name;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setBindAddress(String bindAddress){
|
|
|
|
+ this.bindAddress = bindAddress;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setPort(int port) {
|
|
|
|
+ this.port = port;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setFindPort(boolean findPort) {
|
|
|
|
+ this.findPort = findPort;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setConf(Configuration conf) {
|
|
|
|
+ this.conf = conf;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setConnector(Connector connector) {
|
|
|
|
+ this.connector = connector;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setPathSpec(String[] pathSpec) {
|
|
|
|
+ this.pathSpecs = pathSpec;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setACL(AccessControlList acl) {
|
|
|
|
+ this.adminsAcl = acl;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setSecurityEnabled(boolean securityEnabled) {
|
|
|
|
+ this.securityEnabled = securityEnabled;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setUsernameConfKey(String usernameConfKey) {
|
|
|
|
+ this.usernameConfKey = usernameConfKey;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Builder setKeytabConfKey(String keytabConfKey) {
|
|
|
|
+ this.keytabConfKey = keytabConfKey;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public HttpServer build() throws IOException {
|
|
|
|
+ if (this.name == null) {
|
|
|
|
+ throw new HadoopIllegalArgumentException("name is not set");
|
|
|
|
+ }
|
|
|
|
+ if (this.bindAddress == null) {
|
|
|
|
+ throw new HadoopIllegalArgumentException("bindAddress is not set");
|
|
|
|
+ }
|
|
|
|
+ if (this.port == null) {
|
|
|
|
+ throw new HadoopIllegalArgumentException("port is not set");
|
|
|
|
+ }
|
|
|
|
+ if (this.findPort == null) {
|
|
|
|
+ throw new HadoopIllegalArgumentException("findPort is not set");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.conf == null) {
|
|
|
|
+ conf = new Configuration();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ HttpServer server = new HttpServer(this.name, this.bindAddress, this.port,
|
|
|
|
+ this.findPort, this.conf, this.adminsAcl, this.connector, this.pathSpecs);
|
|
|
|
+ if (this.securityEnabled) {
|
|
|
|
+ server.initSpnego(this.conf, this.usernameConfKey, this.keytabConfKey);
|
|
|
|
+ }
|
|
|
|
+ return server;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/** Same as this(name, bindAddress, port, findPort, null); */
|
|
/** Same as this(name, bindAddress, port, findPort, null); */
|
|
|
|
+ @Deprecated
|
|
public HttpServer(String name, String bindAddress, int port, boolean findPort
|
|
public HttpServer(String name, String bindAddress, int port, boolean findPort
|
|
) throws IOException {
|
|
) throws IOException {
|
|
this(name, bindAddress, port, findPort, new Configuration());
|
|
this(name, bindAddress, port, findPort, new Configuration());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ @Deprecated
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
boolean findPort, Configuration conf, Connector connector) throws IOException {
|
|
boolean findPort, Configuration conf, Connector connector) throws IOException {
|
|
this(name, bindAddress, port, findPort, conf, null, connector, null);
|
|
this(name, bindAddress, port, findPort, conf, null, connector, null);
|
|
@@ -149,6 +249,7 @@ public class HttpServer implements FilterContainer {
|
|
* @param pathSpecs Path specifications that this httpserver will be serving.
|
|
* @param pathSpecs Path specifications that this httpserver will be serving.
|
|
* These will be added to any filters.
|
|
* These will be added to any filters.
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
boolean findPort, Configuration conf, String[] pathSpecs) throws IOException {
|
|
boolean findPort, Configuration conf, String[] pathSpecs) throws IOException {
|
|
this(name, bindAddress, port, findPort, conf, null, null, pathSpecs);
|
|
this(name, bindAddress, port, findPort, conf, null, null, pathSpecs);
|
|
@@ -163,11 +264,13 @@ public class HttpServer implements FilterContainer {
|
|
* increment by 1 until it finds a free port.
|
|
* increment by 1 until it finds a free port.
|
|
* @param conf Configuration
|
|
* @param conf Configuration
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
boolean findPort, Configuration conf) throws IOException {
|
|
boolean findPort, Configuration conf) throws IOException {
|
|
this(name, bindAddress, port, findPort, conf, null, null, null);
|
|
this(name, bindAddress, port, findPort, conf, null, null, null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Deprecated
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
boolean findPort, Configuration conf, AccessControlList adminsAcl)
|
|
boolean findPort, Configuration conf, AccessControlList adminsAcl)
|
|
throws IOException {
|
|
throws IOException {
|
|
@@ -185,6 +288,7 @@ public class HttpServer implements FilterContainer {
|
|
* @param conf Configuration
|
|
* @param conf Configuration
|
|
* @param adminsAcl {@link AccessControlList} of the admins
|
|
* @param adminsAcl {@link AccessControlList} of the admins
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
public HttpServer(String name, String bindAddress, int port,
|
|
boolean findPort, Configuration conf, AccessControlList adminsAcl,
|
|
boolean findPort, Configuration conf, AccessControlList adminsAcl,
|
|
Connector connector) throws IOException {
|
|
Connector connector) throws IOException {
|
|
@@ -528,7 +632,7 @@ public class HttpServer implements FilterContainer {
|
|
/**
|
|
/**
|
|
* Define a filter for a context and set up default url mappings.
|
|
* Define a filter for a context and set up default url mappings.
|
|
*/
|
|
*/
|
|
- protected void defineFilter(Context ctx, String name,
|
|
|
|
|
|
+ public void defineFilter(Context ctx, String name,
|
|
String classname, Map<String,String> parameters, String[] urls) {
|
|
String classname, Map<String,String> parameters, String[] urls) {
|
|
|
|
|
|
FilterHolder holder = new FilterHolder();
|
|
FilterHolder holder = new FilterHolder();
|
|
@@ -568,6 +672,10 @@ public class HttpServer implements FilterContainer {
|
|
public Object getAttribute(String name) {
|
|
public Object getAttribute(String name) {
|
|
return webAppContext.getAttribute(name);
|
|
return webAppContext.getAttribute(name);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public WebAppContext getWebAppContext(){
|
|
|
|
+ return this.webAppContext;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Get the pathname to the webapps files.
|
|
* Get the pathname to the webapps files.
|