Search in sources :

Example 16 with SocketConnector

use of org.mortbay.jetty.bio.SocketConnector in project nhin-d by DirectProject.

the class ConfigServiceRunner method startConfigService.

public static synchronized void startConfigService() throws Exception {
    if (server == null) {
        /*
			 * Setup the configuration service server
			 */
        server = new Server();
        SocketConnector connector = new SocketConnector();
        HTTPPort = AvailablePortFinder.getNextAvailable(1024);
        connector.setPort(HTTPPort);
        WebAppContext context = new WebAppContext("src/test/resources/webapp", "/");
        server.setSendServerVersion(false);
        server.addConnector(connector);
        server.addHandler(context);
        server.start();
        txsServiceURL = "http://localhost:" + HTTPPort + "/";
    }
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 17 with SocketConnector

use of org.mortbay.jetty.bio.SocketConnector in project nutch by apache.

the class TestProtocolHttpClient method startServer.

/**
 * Starts the Jetty server at a specified port.
 *
 * Will try up to 10 ports to find an available port to use.
 *
 * @param portno
 *          Port number.
 * @throws Exception
 *           When an error occurs.
 */
private void startServer(int portno) throws Exception {
    SocketConnector listener = new SocketConnector();
    listener.setHost("127.0.0.1");
    server.addConnector(listener);
    for (int p = portno; p < portno + 10; p++) {
        port = portno;
        listener.setPort(port);
        try {
            server.start();
            break;
        } catch (Exception e) {
            if (p == portno + 9) {
                throw e;
            }
        }
    }
}
Also used : SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 18 with SocketConnector

use of org.mortbay.jetty.bio.SocketConnector in project nutch by apache.

the class ProxyTestbed method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.err.println("TestbedProxy [-seg <segment_name> | -segdir <segments>] [-port <nnn>] [-forward] [-fake] [-delay nnn] [-debug]");
        System.err.println("-seg <segment_name>\tpath to a single segment (can be specified multiple times)");
        System.err.println("-segdir <segments>\tpath to a parent directory of multiple segments (as above)");
        System.err.println("-port <nnn>\trun the proxy on port <nnn> (special permissions may be needed for ports < 1024)");
        System.err.println("-forward\tif specified, requests to all unknown urls will be passed to");
        System.err.println("\t\toriginal servers. If false (default) unknown urls generate 404 Not Found.");
        System.err.println("-delay\tdelay every response by nnn seconds. If delay is negative use a random value up to nnn");
        System.err.println("-fake\tif specified, requests to all unknown urls will succeed with fake content");
        System.exit(-1);
    }
    Configuration conf = NutchConfiguration.create();
    int port = conf.getInt("segment.proxy.port", 8181);
    boolean forward = false;
    boolean fake = false;
    boolean delay = false;
    boolean debug = false;
    int delayVal = 0;
    HashSet<Path> segs = new HashSet<Path>();
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-segdir")) {
            FileSystem fs = FileSystem.get(conf);
            FileStatus[] fstats = fs.listStatus(new Path(args[++i]));
            Path[] paths = HadoopFSUtil.getPaths(fstats);
            segs.addAll(Arrays.asList(paths));
        } else if (args[i].equals("-port")) {
            port = Integer.parseInt(args[++i]);
        } else if (args[i].equals("-forward")) {
            forward = true;
        } else if (args[i].equals("-delay")) {
            delay = true;
            delayVal = Integer.parseInt(args[++i]);
        } else if (args[i].equals("-fake")) {
            fake = true;
        } else if (args[i].equals("-debug")) {
            debug = true;
        } else if (args[i].equals("-seg")) {
            segs.add(new Path(args[++i]));
        } else {
            LOG.error("Unknown argument: " + args[i]);
            System.exit(-1);
        }
    }
    // Create the server
    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    connector.setPort(port);
    connector.setResolveNames(false);
    server.addConnector(connector);
    // create a list of handlers
    HandlerList list = new HandlerList();
    server.addHandler(list);
    if (debug) {
        LOG.info("* Added debug handler.");
        list.addHandler(new LogDebugHandler());
    }
    if (delay) {
        LOG.info("* Added delay handler: " + (delayVal < 0 ? "random delay up to " + (-delayVal) : "constant delay of " + delayVal));
        list.addHandler(new DelayHandler(delayVal));
    }
    // XXX alternatively, we can add the DispatchHandler as the first one,
    // XXX to activate handler plugins and redirect requests to appropriate
    // XXX handlers ... Here we always load these handlers
    Iterator<Path> it = segs.iterator();
    while (it.hasNext()) {
        Path p = it.next();
        try {
            SegmentHandler segment = new SegmentHandler(conf, p);
            list.addHandler(segment);
            LOG.info("* Added segment handler for: " + p);
        } catch (Exception e) {
            LOG.warn("Skipping segment '" + p + "': " + StringUtils.stringifyException(e));
        }
    }
    if (forward) {
        LOG.info("* Adding forwarding proxy for all unknown urls ...");
        ServletHandler servlets = new ServletHandler();
        servlets.addServletWithMapping(AsyncProxyServlet.class, "/*");
        servlets.addFilterWithMapping(LogDebugHandler.class, "/*", Handler.ALL);
        list.addHandler(servlets);
    }
    if (fake) {
        LOG.info("* Added fake handler for remaining URLs.");
        list.addHandler(new FakeHandler());
    }
    list.addHandler(new NotFoundHandler());
    // Start the http server
    server.start();
    server.join();
}
Also used : Path(org.apache.hadoop.fs.Path) HandlerList(org.mortbay.jetty.handler.HandlerList) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FileStatus(org.apache.hadoop.fs.FileStatus) NutchConfiguration(org.apache.nutch.util.NutchConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Server(org.mortbay.jetty.Server) FileSystem(org.apache.hadoop.fs.FileSystem) SocketConnector(org.mortbay.jetty.bio.SocketConnector) HashSet(java.util.HashSet)

Aggregations

SocketConnector (org.mortbay.jetty.bio.SocketConnector)18 Server (org.mortbay.jetty.Server)16 WebAppContext (org.mortbay.jetty.webapp.WebAppContext)11 Context (org.mortbay.jetty.servlet.Context)3 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)3 File (java.io.File)2 IOException (java.io.IOException)2 Repository (javax.jcr.Repository)2 Connector (org.mortbay.jetty.Connector)2 HandlerList (org.mortbay.jetty.handler.HandlerList)2 ResourceHandler (org.mortbay.jetty.handler.ResourceHandler)2 TearDown (com.google.common.testing.TearDown)1 ThreadPoolExecutorAdapter (com.google.util.threads.ThreadPoolExecutorAdapter)1 BindException (java.net.BindException)1 ServerSocket (java.net.ServerSocket)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1