org.eclipse.jetty.webapp.WebAppContext.addServlet()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中org.eclipse.jetty.webapp.WebAppContext.addServlet()方法的一些代码示例,展示了WebAppContext.addServlet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebAppContext.addServlet()方法的具体详情如下:
包路径:org.eclipse.jetty.webapp.WebAppContext
类名称:WebAppContext
方法名:addServlet

WebAppContext.addServlet介绍

暂无

代码示例

代码示例来源:origin: gocd/gocd

private void addlatestAgentStatusCall(WebAppContext wac) {
  wac.addServlet(AgentStatusApi.class, "/admin/latest-agent.status");
}

代码示例来源:origin: apache/hive

/**
  * 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);
 }
}

代码示例来源:origin: gocd/gocd

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);
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * 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);
}

代码示例来源:origin: apache/hbase

/**
 * 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);
}

代码示例来源:origin: jersey/jersey

ServletHolder holder;
if (c != null) {
  holder = context.addServlet(c, "/*");
} else {
  holder = new ServletHolder(servlet);
  context.addServlet(holder, "/*");

代码示例来源:origin: apache/nifi

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);
  }
}

代码示例来源:origin: apache/hbase

context.addServlet(new ServletHolder(redirect), "/*");
context.setServer(masterJettyServer);

代码示例来源:origin: gocd/gocd

wac.addServlet(holder, "/hello");
addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT, this);
addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER, this);

代码示例来源:origin: org.apache.hadoop/hadoop-common

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;
}

代码示例来源:origin: apache/hbase

/**
 * 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);
 }
}

代码示例来源:origin: yahoo/mysql_perf_analyzer

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;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

webAppContext.addServlet(sh, pathSpec);

代码示例来源:origin: org.apache.hadoop/hadoop-common

webAppContext.addServlet(holder, pathSpec);

代码示例来源:origin: jamesagnew/hapi-fhir

root.addServlet("ca.uhn.fhir.jpa.demo.JpaServerDemo", path + "*");

代码示例来源:origin: opensourceBIM/BIMserver

context.addServlet(servletHolder, "/*");

代码示例来源:origin: stackoverflow.com

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/*");

代码示例来源:origin: org.eclipse.jetty/test-jetty-servlet

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();
}

代码示例来源:origin: org.unidal.framework/test-framework

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;
}

代码示例来源:origin: epam/Wilma

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;
}

相关文章

WebAppContext类方法