Search in sources :

Example 6 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();
        context.setContextPath("/config");
        context.setServer(server);
        context.setWar("war/config-service.war");
        server.setSendServerVersion(false);
        server.addConnector(connector);
        server.addHandler(context);
        server.start();
        configServiceURL = "http://localhost:" + HTTPPort + "/config/ConfigurationService";
    }
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 7 with SocketConnector

use of org.mortbay.jetty.bio.SocketConnector in project OpenRefine by OpenRefine.

the class ShutdownSignalHandler method init.

public void init(String host, int port) throws Exception {
    logger.info("Starting Server bound to '" + host + ":" + port + "'");
    String memory = Configurations.get("refine.memory");
    if (memory != null) {
        logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
    }
    int maxThreads = Configurations.getInteger("refine.queue.size", 30);
    int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
    long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
    threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);
    this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));
    Connector connector = new SocketConnector();
    connector.setPort(port);
    connector.setHost(host);
    connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
    connector.setStatsOn(false);
    this.addConnector(connector);
    File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));
    if (!isWebapp(webapp)) {
        webapp = new File("main/webapp");
        if (!isWebapp(webapp)) {
            webapp = new File("webapp");
            if (!isWebapp(webapp)) {
                logger.warn("Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
                System.exit(-1);
            }
        }
    }
    final String contextPath = Configurations.get("refine.context_path", "/");
    final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);
    logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
    WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
    context.setMaxFormContentSize(maxFormContentSize);
    this.setHandler(context);
    this.setStopAtShutdown(true);
    this.setSendServerVersion(true);
    // Enable context autoreloading
    if (Configurations.getBoolean("refine.autoreload", false)) {
        scanForUpdates(webapp, context);
    }
    // start the server
    try {
        this.start();
    } catch (BindException e) {
        logger.error("Failed to start server - is there another copy running already on this port/address?");
        throw e;
    }
    configure(context);
}
Also used : Connector(org.mortbay.jetty.Connector) SocketConnector(org.mortbay.jetty.bio.SocketConnector) ThreadPoolExecutorAdapter(com.google.util.threads.ThreadPoolExecutorAdapter) BindException(java.net.BindException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SocketConnector(org.mortbay.jetty.bio.SocketConnector) File(java.io.File)

Example 8 with SocketConnector

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

the class RepositoryStubImpl method getRepository.

@Override
public Repository getRepository() throws RepositoryStubException {
    if (repository == null) {
        repository = super.getRepository();
    }
    if (connector == null) {
        connector = new SocketConnector();
        connector.setHost("localhost");
        String pvalue = System.getProperty("org.apache.jackrabbit.jcr2dav.RepositoryStubImpl.port", "0");
        int port = pvalue.equals("") ? 0 : Integer.parseInt(pvalue);
        connector.setPort(port);
    }
    if (server == null) {
        server = new Server();
        server.addConnector(connector);
        ServletHolder holder = new ServletHolder(new JcrRemotingServlet() {

            protected Repository getRepository() {
                return repository;
            }
        });
        holder.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "");
        holder.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_MISSING_AUTH_MAPPING, "");
        holder.setInitParameter(JcrRemotingServlet.INIT_PARAM_PROTECTED_HANDLERS_CONFIG, protectedRemoveImplClass);
        Context context = new Context(server, "/");
        context.addServlet(holder, "/*");
        server.addHandler(context);
        try {
            server.start();
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    if (client == null) {
        try {
            Map<String, String> parameters = new HashMap<String, String>();
            String uri = "http://localhost:" + connector.getLocalPort() + "/";
            String parmName = System.getProperty(this.getClass().getName() + ".REPURIPARM", JcrUtils.REPOSITORY_URI);
            parameters.put(parmName, uri);
            parameters.put(PROP_ACCESSCONTROL_PROVIDER_CLASS, acProviderImplClass);
            client = JcrUtils.getRepository(parameters);
        } catch (Exception e) {
            throw new RepositoryStubException(e);
        }
    }
    return client;
}
Also used : Context(org.mortbay.jetty.servlet.Context) Repository(javax.jcr.Repository) Server(org.mortbay.jetty.Server) HashMap(java.util.HashMap) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) SocketConnector(org.mortbay.jetty.bio.SocketConnector) JcrRemotingServlet(org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 9 with SocketConnector

use of org.mortbay.jetty.bio.SocketConnector in project ambrose by twitter.

the class ScriptStatusServer method run.

/**
   * Run the server in the current thread.
   */
@Override
public void run() {
    // override newServerSocket to log local port once bound
    Connector connector = new SocketConnector() {

        @Override
        protected ServerSocket newServerSocket(String host, int port, int backlog) throws IOException {
            ServerSocket ss = super.newServerSocket(host, port, backlog);
            int localPort = ss.getLocalPort();
            LOG.info("Ambrose web server listening on port {}", localPort);
            LOG.info("Browse to http://localhost:{}/ to see job progress", localPort);
            return ss;
        }
    };
    connector.setPort(port);
    server = new Server();
    server.setConnectors(new Connector[] { connector });
    // this needs to be loaded via the jar'ed resources, not the relative dir
    String resourcePath = "com/twitter/ambrose/server/web";
    URL resourceUrl = checkNotNull(APIHandler.class.getClassLoader().getResource(resourcePath), "Failed to find resource '%s'", resourcePath);
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setWelcomeFiles(new String[] { "workflow.html" });
    resourceHandler.setResourceBase(resourceUrl.toExternalForm());
    HandlerList handler = new HandlerList();
    handler.setHandlers(new Handler[] { resourceHandler, new APIHandler(workflowIndexReadService, statsReadService), new DefaultHandler() });
    server.setHandler(handler);
    server.setStopAtShutdown(false);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        LOG.error("Error launching ScriptStatusServer", e);
    }
}
Also used : HandlerList(org.mortbay.jetty.handler.HandlerList) Connector(org.mortbay.jetty.Connector) SocketConnector(org.mortbay.jetty.bio.SocketConnector) Server(org.mortbay.jetty.Server) ServerSocket(java.net.ServerSocket) ResourceHandler(org.mortbay.jetty.handler.ResourceHandler) SocketConnector(org.mortbay.jetty.bio.SocketConnector) URL(java.net.URL) IOException(java.io.IOException) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 10 with SocketConnector

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

the class MonitorServiceRunner method startMonitorService.

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

Aggregations

SocketConnector (org.mortbay.jetty.bio.SocketConnector)15 Server (org.mortbay.jetty.Server)14 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 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 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 ServletException (javax.servlet.ServletException)1