Refine search
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; public class JettyServer { public static void main(String[] args) { Server server = new Server(8080); WebAppContext context = new WebAppContext(); context.setResourceBase("../webapp-project/WebContent"); context.setDescriptor("../webapp-project/WebContent/WEB-INF/web.xml"); context.setContextPath("/"); context.setParentLoaderPriority(true); server.setHandler(context); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); } } }
public static void main(String[] args) throws Exception { String weppAppHome = args[0]; Integer port = 8080; Server server = new Server(port); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setCompactPath(true); webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml"); webapp.setResourceBase(weppAppHome); webapp.setParentLoaderPriority(true); server.setHandler(webapp); server.start(); server.join(); }
@Override public void start() { LOG.info("Starting Kaa Admin Web Server..."); server = new Server(adminPort); webAppContext = new WebAppContext(); webAppContext.setEventListeners(new EventListener[]{adminContextLoaderListener}); webAppContext.setContextPath("/"); String webXmlLocation = AdminInitializationService.class.getResource("/admin-web/WEB-INF/" + webXmlFile).toString(); webAppContext.setDescriptor(webXmlLocation); String resLocation = AdminInitializationService.class.getResource("/admin-web").toString(); webAppContext.setResourceBase(resLocation); webAppContext.setParentLoaderPriority(true); server.setHandler(webAppContext); try { server.start(); LOG.info("Kaa Admin Web Server started."); } catch (Exception ex) { LOG.error("Error starting Kaa Admin Web Server!", ex); } }
private static void startServer() throws Exception { File warFile = findWar(); server = new Server(8080); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setWar(warFile.getAbsolutePath()); server.setHandler(webapp); server.start(); eurekaServiceUrl = "http://localhost:8080/v2"; }
/** * Create the web context for the application of specified name */ WebAppContext createWebAppContext(Builder b) { WebAppContext ctx = new WebAppContext(); setContextAttributes(ctx.getServletContext(), b.contextAttrs); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); return ctx; }
public static void main(String[] args) throws Exception { String configPort = "8080"; if(args.length > 0){ configPort = args[0]; } String port = System.getProperty("server.http.port", configPort); System.out.println("Server started on port: " + port); Server server = new Server(); server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))}); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/api"); ServletHolder servletHolder = new ServletHolder(createJerseyServlet()); servletHolder.setInitOrder(1); context.addServlet(servletHolder, "/*"); WebAppContext webAppContext = new WebAppContext(); webAppContext.setServer(server); webAppContext.setContextPath("/"); String resourceBase = System.getProperty("resourceBase"); if(resourceBase != null){ webAppContext.setResourceBase(resourceBase); } else { webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm()); } HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{context, webAppContext}); server.setHandler(handlers); server.start(); server.join(); }
WebAppContext context = new WebAppContext(); context.setDisplayName("JettyContext"); context.setContextPath(path); context.setConfigurations(new Configuration[]{new WebXmlConfiguration()}); ServletHolder holder;
server.setConnectors(new Connector[] { connector }); WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp");
webAppContext = new WebAppContext(); webXmlPath = webappUrl + "/WEB-INF/web.xml"; webAppContext.setDescriptor(webXmlPath); webAppContext.setContextPath(contextPath); webAppContext.setResourceBase(webappUrl);
WebAppContext webapp = new WebAppContext(); webapp.setContextPath(webAppContext); webapp.setWar(warFilePath); webapp.setParentLoaderPriority(false);
private WebAppContext loadWar(final File warFile, final String contextPath, final ClassLoader parentClassLoader) { final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath); webappContext.setContextPath(contextPath); webappContext.setDisplayName(contextPath);
private WebAppContext createWebAppContext() { webAppContext = new WebAppContext(); webAppContext.setDefaultsDescriptor(GoWebXmlConfiguration.configuration(getWarFile())); webAppContext.setConfigurationClasses(new String[]{ WebInfConfiguration.class.getCanonicalName(), WebXmlConfiguration.class.getCanonicalName(), JettyWebXmlConfiguration.class.getCanonicalName() }); webAppContext.setContextPath(systemEnvironment.getWebappContextPath()); // delegate all logging to parent classloader to avoid initialization of loggers in multiple classloaders webAppContext.addSystemClass("org.apache.log4j."); webAppContext.addSystemClass("org.slf4j."); webAppContext.addSystemClass("org.apache.commons.logging."); webAppContext.setWar(getWarFile()); webAppContext.setParentLoaderPriority(systemEnvironment.getParentLoaderPriority()); return webAppContext; }
Server server = new Server(); // Note: if you don't want control over type of connector, etc. you can simply // call new Server(<port>); ServerConnector connector = new ServerConnector(server); connector.setHost("0.0.0.0"); connector.setPort(8085); // Setting the name allows you to serve different app contexts from different connectors. connector.setName("main"); server.addConnector(connector); WebAppContext context = new WebAppContext(); context.setContextPath("/"); // For development within an IDE like Eclipse, you can directly point to the web.xml context.setWar("src/main/webapp"); context.addFilter(MyFilter.class, "/", 1); HandlerCollection collection = new HandlerCollection(); RequestLogHandler rlh = new RequestLogHandler(); // Slf4j - who uses anything else? Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setExtended(false); rlh.setRequestLog(requestLog); collection.setHandlers(new Handler[] { context, rlh }); server.setHandler(collection); try { server.start(); server.join(); } catch (Exception e) { // Google guava way throw Throwables.propagate(e); }
Server server = new Server(); WebAppContext servletContextHandler = new WebAppContext(); servletContextHandler.setContextPath("/"); servletContextHandler.setResourceBase("src/main/resources/" + webFolder); ClassList clist = ClassList.setServerDefault(server);
private static WebAppContext createWebAppContext(Builder b, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDefaultsDescriptor(null); ServletHolder holder = new ServletHolder(new DefaultServlet()); Map<String, String> params = ImmutableMap. <String, String> builder() .put("acceptRanges", "true") .put("dirAllowed", "false") .put("gzip", "true") .put("useFileMappedBuffer", "true") .build(); holder.setInitParameters(params); ctx.setWelcomeFiles(new String[] {"index.html"}); ctx.addServlet(holder, "/"); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY); if (tempDirectory != null && !tempDirectory.isEmpty()) { ctx.setTempDirectory(new File(tempDirectory)); ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory); } ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
final WebAppContext staticContext = new WebAppContext(); staticContext.setServer( getJetty() ); staticContext.setContextPath( mountPoint ); staticContext.setSessionHandler( sessionHandler ); staticContext.setInitParameter( "org.eclipse.jetty.servlet.Default.dirAllowed", "false" );
private static WebAppContext createWebAppContext(String name, Configuration conf, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDisplayName(name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + name); ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); // for org.apache.hadoop.metrics.MetricsServlet ctx.getServletContext().setAttribute( org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE, conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
private WebAppContext createDeployedApplicationInstance(File workDirectory, String deployedApplicationPath) { WebAppContext deployedApplication = new WebAppContext(); deployedApplication.setContextPath(this.getContextPath()); deployedApplication.setWar(deployedApplicationPath); deployedApplication.setAttribute("javax.servlet.context.tempdir", workDirectory.getAbsolutePath()); deployedApplication .setAttribute( "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$"); deployedApplication.setAttribute( "org.eclipse.jetty.containerInitializers", jspInitializers()); deployedApplication.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); deployedApplication.addBean(new ServletContainerInitializersStarter( deployedApplication), true); // webapp.setClassLoader(new URLClassLoader(new // URL[0],App.class.getClassLoader())); deployedApplication.addServlet(jspServletHolder(), "*.jsp"); return deployedApplication; }
WebAppContext htrootContext = new WebAppContext(); htrootContext.setContextPath("/");
Server server.setConnectors(new Connector[] { socketConnector }); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); // For root webapp.setWar("/"); // Appropriate file system path.