Search in sources :

Example 61 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project Ebselen by Ardesco.

the class JettyServer method startJettyServer.

public void startJettyServer(int port) throws Exception {
    String resourceBasePath = this.getClass().getResource("/web").toExternalForm();
    jettyServer = new Server(port);
    WebAppContext webapp = new WebAppContext();
    webapp.setResourceBase(resourceBasePath);
    jettyServer.setHandler(webapp);
    jettyServer.start();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server)

Example 62 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.

the class Activator method start.

/**
     * 
     * @param context
     */
public void start(BundleContext context) throws Exception {
    //Create webappA as a Service and target it at the default server
    WebAppContext webapp = new WebAppContext();
    webapp.addServlet(new ServletHolder(new TestServlet()), "/mime");
    Dictionary props = new Hashtable();
    props.put("war", "webappA");
    props.put("contextPath", "/acme");
    props.put("managedServerName", "defaultJettyServer");
    _srA = context.registerService(WebAppContext.class.getName(), webapp, props);
    //Create a second webappB as a Service and target it at a custom Server
    //deployed by another bundle
    WebAppContext webappB = new WebAppContext();
    Dictionary propsB = new Hashtable();
    propsB.put("war", "webappB");
    propsB.put("contextPath", "/acme");
    propsB.put("managedServerName", "fooServer");
    _srB = context.registerService(WebAppContext.class.getName(), webappB, propsB);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Dictionary(java.util.Dictionary) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Hashtable(java.util.Hashtable)

Example 63 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project apjp by jvansteirteghem.

the class Main method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(Integer.valueOf(System.getenv("PORT")));
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setDescriptor("src/main/webapp/WEB-INF/web.xml");
    webAppContext.setResourceBase("src/main/webapp/");
    webAppContext.setParentLoaderPriority(true);
    server.setHandler(webAppContext);
    server.start();
    server.join();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server)

Example 64 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project ats-framework by Axway.

the class ContainerStarter method startServer.

/**
     * Method for starting the Jetty server with the ATS Agent webapp.
     * @param port the port on which to start the server.
     * @return the started server.
     * @throws IOException
     */
private static Server startServer() throws IOException {
    addAppender();
    final int agentPort = getAgentDefaultPort();
    log.info("Starting ATS agent at port: " + agentPort);
    final String jettyHome = getJettyHome();
    logSystemInformation(jettyHome);
    // start the server
    Connector connector = new SelectChannelConnector();
    connector.setPort(agentPort);
    Server server = new Server();
    server.setConnectors(new Connector[] { connector });
    WebAppContext webApp = new WebAppContext();
    webApp.setContextPath("/agentapp");
    webApp.setWar(jettyHome + "/webapp/agentapp.war");
    server.setHandler(webApp);
    server.setStopAtShutdown(true);
    setExtraClasspath(webApp, jettyHome);
    try {
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    log.info("ATS agent started");
    return server;
}
Also used : SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Server(org.eclipse.jetty.server.Server) SocketException(java.net.SocketException) AgentException(com.axway.ats.agentapp.standalone.exceptions.AgentException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 65 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project incubator-atlas by apache.

the class EmbeddedServer method getWebAppContext.

protected WebAppContext getWebAppContext(String path) {
    WebAppContext application = new WebAppContext(path, "/");
    application.setClassLoader(Thread.currentThread().getContextClassLoader());
    // Disable directory listing
    application.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    return application;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)142 Server (org.eclipse.jetty.server.Server)58 File (java.io.File)37 Test (org.junit.Test)29 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)18 URL (java.net.URL)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 URI (java.net.URI)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)9 FileWriter (java.io.FileWriter)7 Configuration (org.apache.hadoop.conf.Configuration)7 HashLoginService (org.eclipse.jetty.security.HashLoginService)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)7 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)7 BeforeClass (org.junit.BeforeClass)7 OutputStream (java.io.OutputStream)6 InitialContext (javax.naming.InitialContext)6