Search in sources :

Example 36 with XmlConfiguration

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

the class SPARQLServer method configServer.

private static Server configServer(String jettyConfig) {
    try {
        serverLog.info("Jetty server config file = " + jettyConfig);
        Server server = new Server();
        XmlConfiguration configuration = new XmlConfiguration(new FileInputStream(jettyConfig));
        configuration.configure(server);
        return server;
    } catch (Exception ex) {
        serverLog.error("SPARQLServer: Failed to configure server: " + ex.getMessage(), ex);
        throw new FusekiException("Failed to configure a server using configuration file '" + jettyConfig + "'");
    }
}
Also used : Server(org.eclipse.jetty.server.Server) FusekiException(org.apache.jena.fuseki.FusekiException) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) FileInputStream(java.io.FileInputStream) FusekiException(org.apache.jena.fuseki.FusekiException)

Example 37 with XmlConfiguration

use of org.eclipse.jetty.xml.XmlConfiguration in project cuba by cuba-platform.

the class CubaJettyServer method createServer.

protected Server createServer() throws Exception {
    ClassLoader serverClassLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader sharedClassLoader = new URLClassLoader(pathsToURLs(serverClassLoader, SHARED_CLASS_PATH_IN_JAR), serverClassLoader);
    Server server;
    if (jettyConfUrl != null) {
        XmlConfiguration xmlConfiguration = new XmlConfiguration(jettyConfUrl);
        server = (Server) xmlConfiguration.configure();
    } else {
        server = new Server(port);
    }
    server.setStopAtShutdown(true);
    List<Handler> handlers = new ArrayList<>();
    if (CubaJettyUtils.hasCoreApp(serverClassLoader)) {
        String coreContextPath = contextPath;
        if (isSingleJar(serverClassLoader)) {
            if (PATH_DELIMITER.equals(contextPath)) {
                coreContextPath = PATH_DELIMITER + "app-core";
            } else {
                coreContextPath = contextPath + "-core";
            }
        }
        handlers.add(createAppContext(serverClassLoader, sharedClassLoader, CORE_PATH_IN_JAR, coreContextPath));
    }
    if (hasWebApp(serverClassLoader)) {
        handlers.add(createAppContext(serverClassLoader, sharedClassLoader, WEB_PATH_IN_JAR, contextPath));
    }
    if (hasPortalApp(serverClassLoader)) {
        String portalContextPath = contextPath;
        if (isSingleJar(serverClassLoader)) {
            portalContextPath = this.portalContextPath;
        }
        handlers.add(createAppContext(serverClassLoader, sharedClassLoader, PORTAL_PATH_IN_JAR, portalContextPath));
    }
    if (hasFrontApp(serverClassLoader)) {
        handlers.add(createFrontAppContext(serverClassLoader, sharedClassLoader));
    }
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(handlers.toArray(new Handler[handlers.size()]));
    server.setHandler(handlerCollection);
    return server;
}
Also used : Server(org.eclipse.jetty.server.Server) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) Handler(org.eclipse.jetty.server.Handler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) WebXmlConfiguration(org.eclipse.jetty.webapp.WebXmlConfiguration) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration)

Example 38 with XmlConfiguration

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

the class GridJettyRestProtocol method loadJettyConfiguration.

/**
 * Loads jetty configuration from the given URL.
 *
 * @param cfgUrl URL to load configuration from.
 * @throws IgniteCheckedException if load failed.
 */
private void loadJettyConfiguration(@Nullable URL cfgUrl) throws IgniteCheckedException {
    if (cfgUrl == null) {
        HttpConfiguration httpCfg = new HttpConfiguration();
        httpCfg.setSecureScheme("https");
        httpCfg.setSecurePort(8443);
        httpCfg.setSendServerVersion(true);
        httpCfg.setSendDateHeader(true);
        String srvPortStr = System.getProperty(IGNITE_JETTY_PORT, "8080");
        int srvPort;
        try {
            srvPort = Integer.parseInt(srvPortStr);
        } catch (NumberFormatException ignore) {
            throw new IgniteCheckedException("Failed to start Jetty server because IGNITE_JETTY_PORT system property " + "cannot be cast to integer: " + srvPortStr);
        }
        httpSrv = new Server(new QueuedThreadPool(200, 20));
        ServerConnector srvConn = new ServerConnector(httpSrv, new HttpConnectionFactory(httpCfg));
        srvConn.setHost(System.getProperty(IGNITE_JETTY_HOST, "localhost"));
        srvConn.setPort(srvPort);
        srvConn.setIdleTimeout(30000L);
        srvConn.setReuseAddress(true);
        httpSrv.addConnector(srvConn);
        httpSrv.setStopAtShutdown(false);
    } else {
        XmlConfiguration cfg;
        try {
            cfg = new XmlConfiguration(cfgUrl);
        } catch (FileNotFoundException e) {
            throw new IgniteSpiException("Failed to find configuration file: " + cfgUrl, e);
        } catch (SAXException e) {
            throw new IgniteSpiException("Failed to parse configuration file: " + cfgUrl, e);
        } catch (IOException e) {
            throw new IgniteSpiException("Failed to load configuration file: " + cfgUrl, e);
        } catch (Exception e) {
            throw new IgniteSpiException("Failed to start HTTP server with configuration file: " + cfgUrl, e);
        }
        try {
            httpSrv = (Server) cfg.configure();
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start Jetty HTTP server.", e);
        }
    }
    assert httpSrv != null;
    httpSrv.setHandler(jettyHnd);
    override(getJettyConnector());
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FileNotFoundException(java.io.FileNotFoundException) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) IOException(java.io.IOException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketException(java.net.SocketException) MultiException(org.eclipse.jetty.util.MultiException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) ServerConnector(org.eclipse.jetty.server.ServerConnector) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 39 with XmlConfiguration

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

the class JettyFusekiWebapp method configServer.

private void configServer(String jettyConfig) {
    try {
        serverLog.info("Jetty server config file = " + jettyConfig);
        server = new Server();
        Resource configXml = Resource.newResource(jettyConfig);
        XmlConfiguration configuration = new XmlConfiguration(configXml);
        configuration.configure(server);
        serverConnector = (ServerConnector) server.getConnectors()[0];
    } catch (Exception ex) {
        serverLog.error("SPARQLServer: Failed to configure server: " + ex.getMessage(), ex);
        throw new FusekiException("Failed to configure a server using configuration file '" + jettyConfig + "'");
    }
}
Also used : FusekiException(org.apache.jena.fuseki.FusekiException) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) FusekiException(org.apache.jena.fuseki.FusekiException)

Example 40 with XmlConfiguration

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

the class JettyServer method jettyServer.

// Jetty Server
public static Server jettyServer(String jettyConfig) {
    try {
        Server server = new Server();
        Resource configXml = Resource.newResource(jettyConfig);
        XmlConfiguration configuration = new XmlConfiguration(configXml);
        configuration.configure(server);
        return server;
    } catch (Exception ex) {
        serverLog.error("JettyServer: Failed to configure server: " + ex.getMessage(), ex);
        throw new JettyConfigException("Failed to configure a server using configuration file '" + jettyConfig + "'");
    }
}
Also used : Server(org.eclipse.jetty.server.Server) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) IOException(java.io.IOException) FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException)

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