Search in sources :

Example 6 with Connector

use of org.mortbay.jetty.Connector in project maven-plugins by apache.

the class ProjectInfoReportUtilsTest method startJetty.

private void startJetty(boolean isSSL, boolean withAuth) throws Exception {
    jettyServer = new Server();
    jettyServer.setStopAtShutdown(true);
    Connector connector = (isSSL ? getSSLConnector() : getDefaultConnector());
    jettyServer.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setResourceBase(getBasedir() + "/target/classes/");
    webapp.setServer(jettyServer);
    if (withAuth) {
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(new String[] { "user", "admin" });
        constraint.setAuthenticate(true);
        ConstraintMapping cm = new ConstraintMapping();
        cm.setConstraint(constraint);
        cm.setPathSpec("/*");
        SecurityHandler sh = new SecurityHandler();
        sh.setUserRealm(new HashUserRealm("MyRealm", getBasedir() + "/src/test/resources/realm.properties"));
        sh.setConstraintMappings(new ConstraintMapping[] { cm });
        webapp.addHandler(sh);
    }
    DefaultHandler defaultHandler = new DefaultHandler();
    defaultHandler.setServer(jettyServer);
    Handler[] handlers = new Handler[2];
    handlers[0] = webapp;
    handlers[1] = defaultHandler;
    jettyServer.setHandlers(handlers);
    jettyServer.start();
    port = connector.getLocalPort();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) SslSocketConnector(org.mortbay.jetty.security.SslSocketConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) ConstraintMapping(org.mortbay.jetty.security.ConstraintMapping) Server(org.mortbay.jetty.Server) Constraint(org.mortbay.jetty.security.Constraint) Handler(org.mortbay.jetty.Handler) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler) HashUserRealm(org.mortbay.jetty.security.HashUserRealm) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 7 with Connector

use of org.mortbay.jetty.Connector in project voldemort by voldemort.

the class HttpService method stopInner.

@Override
public void stopInner() {
    try {
        if (httpServer != null) {
            httpServer.stop();
            for (Connector c : httpServer.getConnectors()) {
                c.close();
            }
        }
        if (context != null)
            context.destroy();
    } catch (Exception e) {
        throw new VoldemortException(e);
    }
    this.httpServer = null;
    this.context = null;
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException)

Example 8 with Connector

use of org.mortbay.jetty.Connector in project tomee by apache.

the class JettyHttpServer method init.

@Override
public void init(final Properties props) throws Exception {
    final Options options = new Options(props);
    port = options.get("port", 8080);
    // Create all the Jetty objects but dont' start them
    server = new Server();
    final Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.setConnectors(new Connector[] { connector });
    final ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    final ServletContext servletContext = context.getServletContext();
    server.setHandler(context);
    final Handler handler = new AbstractHandler() {

        @Override
        public void handle(final String target, final HttpServletRequest req, final HttpServletResponse res, final int dispatch) throws IOException, ServletException {
            try {
                ((Request) req).setHandled(true);
                final HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
                final HttpResponse httpResponse = new ServletResponseAdapter(res);
                JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
            } catch (IOException | ServletException e) {
                throw e;
            } catch (Exception e) {
                throw new ServletException(e);
            }
        }
    };
    final SessionHandler sessionHandler = new SessionHandler();
    final SessionManager sessionManager = new HashSessionManager();
    sessionManager.setIdManager(new HashSessionIdManager());
    sessionHandler.setSessionManager(sessionManager);
    sessionHandler.setHandler(handler);
    context.setHandler(sessionHandler);
}
Also used : SessionHandler(org.mortbay.jetty.servlet.SessionHandler) Options(org.apache.openejb.loader.Options) Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server) HashSessionManager(org.mortbay.jetty.servlet.HashSessionManager) SessionManager(org.mortbay.jetty.SessionManager) HashSessionManager(org.mortbay.jetty.servlet.HashSessionManager) Request(org.mortbay.jetty.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.mortbay.jetty.Handler) SessionHandler(org.mortbay.jetty.servlet.SessionHandler) ContextHandler(org.mortbay.jetty.handler.ContextHandler) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) HashSessionIdManager(org.mortbay.jetty.servlet.HashSessionIdManager) AbstractHandler(org.mortbay.jetty.handler.AbstractHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ServiceException(org.apache.openejb.server.ServiceException) ContextHandler(org.mortbay.jetty.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletContext(javax.servlet.ServletContext)

Example 9 with Connector

use of org.mortbay.jetty.Connector in project gradle by gradle.

the class Jetty6PluginServer method setConnectors.

/**
     * @see Jetty6PluginServer#setConnectors(Object[])
     */
public void setConnectors(Object[] connectors) {
    if (connectors == null || connectors.length == 0) {
        return;
    }
    for (int i = 0; i < connectors.length; i++) {
        Connector connector = (Connector) connectors[i];
        LOGGER.debug("Setting Connector: {} on port {}", connector.getClass().getName(), connector.getPort());
        this.server.addConnector(connector);
    }
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector)

Example 10 with Connector

use of org.mortbay.jetty.Connector in project roboguice by roboguice.

the class Main method main.

public static void main(String[] args) throws Exception {
    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext("./root", "/example");
    server.addHandler(webapp);
    server.start();
    server.join();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server)

Aggregations

Connector (org.mortbay.jetty.Connector)14 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)12 Server (org.mortbay.jetty.Server)8 WebAppContext (org.mortbay.jetty.webapp.WebAppContext)5 IOException (java.io.IOException)4 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)4 SslSocketConnector (org.mortbay.jetty.security.SslSocketConnector)4 Handler (org.mortbay.jetty.Handler)3 ArrayList (java.util.ArrayList)2 SocketConnector (org.mortbay.jetty.bio.SocketConnector)2 HandlerList (org.mortbay.jetty.handler.HandlerList)2 Constraint (org.mortbay.jetty.security.Constraint)2 ThreadPoolExecutorAdapter (com.google.util.threads.ThreadPoolExecutorAdapter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 BindException (java.net.BindException)1 ServerSocket (java.net.ServerSocket)1 URL (java.net.URL)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1