private void addlatestAgentStatusCall(WebAppContext wac) { wac.addServlet(AgentStatusApi.class, "/admin/latest-agent.status"); }
/** * Add a servlet in the server. * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class */ public void addServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); } }
private static void addFakeAgentBinaryServlet(WebAppContext wac, final String pathSpec, final TestResource resource, FakeGoServer fakeGoServer) { ServletHolder holder = new ServletHolder(); holder.setServlet(new AgentBinariesServlet(resource, fakeGoServer)); wac.addServlet(holder, pathSpec); }
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); ResourceConfig application = new ResourceConfig().packages(packageName); final ServletHolder sh = new ServletHolder(new ServletContainer(application)); webAppContext.addServlet(sh, pathSpec); }
ServletHolder holder; if (c != null) { holder = context.addServlet(c, "/*"); } else { holder = new ServletHolder(servlet); context.addServlet(holder, "/*");
private void addDocsServlets(WebAppContext docsContext) { try { // Load the nifi/docs directory final File docsDir = getDocsDir("docs"); // load the component documentation working directory final File componentDocsDirPath = props.getComponentDocumentationWorkingDirectory(); final File workingDocsDirectory = getWorkingDocsDirectory(componentDocsDirPath); // Load the API docs final File webApiDocsDir = getWebApiDocsDir(); // Create the servlet which will serve the static resources ServletHolder defaultHolder = new ServletHolder("default", DefaultServlet.class); defaultHolder.setInitParameter("dirAllowed", "false"); ServletHolder docs = new ServletHolder("docs", DefaultServlet.class); docs.setInitParameter("resourceBase", docsDir.getPath()); ServletHolder components = new ServletHolder("components", DefaultServlet.class); components.setInitParameter("resourceBase", workingDocsDirectory.getPath()); ServletHolder restApi = new ServletHolder("rest-api", DefaultServlet.class); restApi.setInitParameter("resourceBase", webApiDocsDir.getPath()); docsContext.addServlet(docs, "/html/*"); docsContext.addServlet(components, "/components/*"); docsContext.addServlet(restApi, "/rest-api/*"); docsContext.addServlet(defaultHolder, "/"); logger.info("Loading documents web app with context path set to " + docsContext.getContextPath()); } catch (Exception ex) { logger.error("Unhandled Exception in createDocsWebApp: " + ex.getMessage()); startUpFailure(ex); } }
context.addServlet(new ServletHolder(redirect), "/*"); context.setServer(masterJettyServer);
wac.addServlet(holder, "/hello"); addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT, this); addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER, this);
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; }
/** * Add an internal servlet in the server, specifying whether or not to * protect with Kerberos authentication. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For + * servlets added using this method, filters (except internal Kerberos * filters) are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class * @param requireAuth Require Kerberos authenticate to access servlet */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) { ServletHolder holder = new ServletHolder(clazz); if (name != null) { holder.setName(name); } webAppContext.addServlet(holder, pathSpec); if(requireAuth && UserGroupInformation.isSecurityEnabled()) { LOG.info("Adding Kerberos (SPNEGO) filter to " + name); ServletHandler handler = webAppContext.getServletHandler(); FilterMapping fmap = new FilterMapping(); fmap.setPathSpec(pathSpec); fmap.setFilterName(SPNEGO_FILTER); fmap.setDispatches(FilterMapping.ALL); handler.addFilterMapping(fmap); } }
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.addServlet(sh, pathSpec);
webAppContext.addServlet(holder, pathSpec);
root.addServlet("ca.uhn.fhir.jpa.demo.JpaServerDemo", path + "*");
context.addServlet(servletHolder, "/*");
Server server = new Server(1111); WebAppContext root = new WebAppContext(); root.setAttribute(AxisServlet.CONFIGURATION_CONTEXT, context); AxisServlet s = new AxisServlet(); ServletHolder holder = new ServletHolder(s); root.addServlet(holder, "/axis2/*");
private static void initJetty() throws SAXException, IOException, MalformedURLException, Exception { Server jetty = new Server(8080); // configure your web application WebAppContext appContext = new WebAppContext(); appContext.setContextPath("/flub"); appContext.addServlet(Jetty400Repro.class, "/servlet/"); appContext.setResourceBase("."); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { appContext, new DefaultHandler() }); jetty.setHandler(handlers); jetty.start(); }
protected void startServer() throws Exception { Server server = new Server(getServerPort()); WebAppContext context = new ResourceFallbackWebAppContext(); configure(context); server.setHandler(context); server.start(); context.addServlet(new ServletHolder(new WebModuleServlet(m_resource)), "/"); postConfigure(context); m_server = server; }
private WebAppContext configureWebAppContext() { final WebAppContext context = new WebAppContext(); String baseUrl = getBaseUrl(); context.setDescriptor(baseUrl + WEB_XML_LOCATION); context.setResourceBase(baseUrl + ""); context.setContextPath("/"); context.setParentLoaderPriority(true); WebAppStopper webAppStopper = new WebAppStopper(this, Executors.newSingleThreadExecutor()); Servlet shutdownServlet = new ShutdownServlet(webAppStopper); context.addServlet(new ServletHolder(shutdownServlet), SHUTDOWN_URL); return context; }