Search in sources :

Example 21 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project otter by alibaba.

the class JettyEmbedIntegration method main.

public static void main(String[] args) throws Exception {
    Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
    XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
    Server server = (Server) configuration.configure();
    int port = 8081;
    Connector[] connectors = server.getConnectors();
    for (Connector connector : connectors) {
        connector.setPort(port);
    }
    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
    }
    server.start();
    server.join();
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) Resource(org.eclipse.jetty.util.resource.Resource) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 22 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project gocd by gocd.

the class Jetty9Server method performCustomConfiguration.

private void performCustomConfiguration() throws Exception {
    File jettyConfig = systemEnvironment.getJettyConfigFile();
    if (jettyConfig.exists()) {
        replaceJettyXmlIfItBelongsToADifferentVersion(jettyConfig);
        LOG.info("Configuring Jetty using {}", jettyConfig.getAbsolutePath());
        XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(jettyConfig));
        configuration.configure(server);
    } else {
        String message = String.format("No custom jetty configuration (%s) found, using defaults.", jettyConfig.getAbsolutePath());
        LOG.info(message);
    }
}
Also used : WebXmlConfiguration(org.eclipse.jetty.webapp.WebXmlConfiguration) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) JettyWebXmlConfiguration(org.eclipse.jetty.webapp.JettyWebXmlConfiguration) File(java.io.File)

Example 23 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project hive by apache.

the class Main method runServer.

public Server runServer(int port) throws Exception {
    // Authenticate using keytab
    if (UserGroupInformation.isSecurityEnabled()) {
        String serverPrincipal = SecurityUtil.getServerPrincipal(conf.kerberosPrincipal(), "0.0.0.0");
        UserGroupInformation.loginUserFromKeytab(serverPrincipal, conf.kerberosKeytab());
    }
    // Create the Jetty server. If jetty conf file exists, use that to create server
    // to have more control.
    Server server = null;
    if (StringUtils.isEmpty(conf.jettyConfiguration())) {
        server = new Server(port);
    } else {
        FileInputStream jettyConf = new FileInputStream(conf.jettyConfiguration());
        XmlConfiguration configuration = new XmlConfiguration(jettyConf);
        server = (Server) configuration.configure();
    }
    ServletContextHandler root = new ServletContextHandler(server, "/");
    // Add the Auth filter
    FilterHolder fHolder = makeAuthFilter();
    EnumSet<DispatcherType> dispatches = EnumSet.of(DispatcherType.REQUEST);
    /* 
     * We add filters for each of the URIs supported by templeton.
     * If we added the entire sub-structure using '/*', the mapreduce 
     * notification cannot give the callback to templeton in secure mode.
     * This is because mapreduce does not use secure credentials for 
     * callbacks. So jetty would fail the request as unauthorized.
     */
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/ddl/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/pig/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/hive/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/sqoop/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/queue/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/jobs/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/mapreduce/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/status/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/version/*", dispatches);
    if (conf.getBoolean(AppConfig.XSRF_FILTER_ENABLED, false)) {
        root.addFilter(makeXSRFFilter(), "/" + SERVLET_PATH + "/*", dispatches);
        LOG.debug("XSRF filter enabled");
    } else {
        LOG.warn("XSRF filter disabled");
    }
    root.addFilter(makeFrameOptionFilter(), "/" + SERVLET_PATH + "/*", dispatches);
    // Connect Jersey
    ServletHolder h = new ServletHolder(new ServletContainer(makeJerseyConfig()));
    root.addServlet(h, "/" + SERVLET_PATH + "/*");
    // Add any redirects
    addRedirects(server);
    // Set handling for low resource conditions.
    final LowResourceMonitor low = new LowResourceMonitor(server);
    low.setLowResourcesIdleTimeout(10000);
    server.addBean(low);
    server.addConnector(createChannelConnector());
    // Start the server
    server.start();
    this.server = server;
    return server;
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) LowResourceMonitor(org.eclipse.jetty.server.LowResourceMonitor) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType) FileInputStream(java.io.FileInputStream)

Example 24 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.

the class FileServerXml method main.

public static void main(String[] args) throws Exception {
    Resource fileserverXml = Resource.newSystemResource("fileserver.xml");
    XmlConfiguration configuration = new XmlConfiguration(fileserverXml.getInputStream());
    Server server = (Server) configuration.configure();
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration)

Example 25 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.

the class ServerProxyImpl method applyJettyXml.

/**
     * Applies jetty.xml configuration to the Jetty server instance.
     */
private void applyJettyXml() {
    if (jettyXml != null && jettyXml.exists()) {
        TaskLog.log("Configuring jetty from xml configuration file = " + jettyXml.getAbsolutePath());
        XmlConfiguration configuration;
        try {
            configuration = new XmlConfiguration(Resource.toURL(jettyXml));
            configuration.configure(server);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        } catch (SAXException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Aggregations

XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)43 Server (org.eclipse.jetty.server.Server)24 Resource (org.eclipse.jetty.util.resource.Resource)18 URL (java.net.URL)12 File (java.io.File)9 IOException (java.io.IOException)9 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 Handler (org.eclipse.jetty.server.Handler)5 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 FileInputStream (java.io.FileInputStream)4 URLClassLoader (java.net.URLClassLoader)4 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)4 JettyWebXmlConfiguration (org.eclipse.jetty.webapp.JettyWebXmlConfiguration)4 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)4 FileNotFoundException (java.io.FileNotFoundException)3 HttpURLConnection (java.net.HttpURLConnection)3 MalformedURLException (java.net.MalformedURLException)3