Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java (revision 600612) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java (working copy) @@ -19,16 +19,23 @@ */ package org.apache.hadoop.hbase.rest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import java.io.IOException; - import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.mortbay.http.SocketListener; -import org.apache.hadoop.hbase.HBaseAdmin; -import org.apache.hadoop.hbase.HBaseConfiguration; +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URL; +import org.mortbay.http.HttpContext; + +import org.apache.hadoop.hbase.*; + /** * Servlet implementation class for hbase REST interface. * Presumes container ensures single thread through here at any one time @@ -160,4 +167,54 @@ int context_len = request.getContextPath().length() + 1; return request.getRequestURI().substring(context_len).split("/"); } + + public static void main(String[] args) throws Exception{ + int port = 60050; + String bindAddress = "0.0.0.0"; + + // grab the port and bind addresses from the command line if supplied + for(int i = 0; i < args.length; i++){ + if(args[i].equals("--port")){ + port = Integer.parseInt(args[++i]); + } + + if(args[i].equals("--bind")){ + bindAddress = args[++i]; + } + } + + org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server(); + + SocketListener listener = new SocketListener(); + listener.setPort(port); + listener.setHost(bindAddress); + webServer.addListener(listener); + + webServer.addWebApplication("/api", getWebAppDir("rest")); + + webServer.start(); + } + + /** + * Get the pathname to the patch files. + * @param path Path to find. + * @return the pathname as a URL + */ + private static String getWebAppsPath(final String path) throws IOException { + URL url = Dispatcher.class.getClassLoader().getResource(path); + if (url == null) + throw new IOException("webapps not found in CLASSPATH"); + return url.toString(); + } + + private static String getWebAppDir(final String webappName) throws IOException { + String webappDir = null; + try { + webappDir = getWebAppsPath("webapps" + File.separator + webappName); + } catch (FileNotFoundException e) { + // Retry. Resource may be inside jar on a windows machine. + webappDir = getWebAppsPath("webapps/" + webappName); + } + return webappDir; + } }