io.undertow.servlet.Servlets.defaultContainer()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(121)

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

Servlets.defaultContainer介绍

[英]Returns the default servlet container. For most embedded use cases this will be sufficient.
[中]返回默认的servlet容器。对于大多数嵌入式用例来说,这就足够了。

代码示例

代码示例来源:origin: openzipkin/brave

protected int initServer() throws Exception {
 DeploymentInfo servletBuilder = Servlets.deployment()
   .setClassLoader(getClass().getClassLoader())
   .setContextPath("/")
   .setDeploymentName("test.war");
 init(servletBuilder);
 DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
 manager.deploy();
 server = Undertow.builder()
   .addHttpListener(0, "127.0.0.1")
   .setHandler(manager.start()).build();
 server.start();
 return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
}

代码示例来源:origin: spring-projects/spring-framework

this.manager = defaultContainer().addDeployment(servletBuilder);
this.manager.deploy();
HttpHandler httpHandler = this.manager.start();

代码示例来源:origin: pippo-java/pippo

protected DeploymentManager createPippoDeploymentManager() {
  DeploymentInfo info = Servlets.deployment();
  info.setDeploymentName("Pippo");
  info.setClassLoader(this.getClass().getClassLoader());
  info.setContextPath(getSettings().getContextPath());
  info.setIgnoreFlush(true);
  // inject application as context attribute
  info.addServletContextAttribute(PIPPO_APPLICATION, getApplication());
  // add pippo filter
  addPippoFilter(info);
  // add initializers
  info.addListener(new ListenerInfo(PippoServletContextListener.class));
  // add listeners
  listeners.forEach(listener -> info.addListener(new ListenerInfo(listener)));
  ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class);
  defaultServlet.addMapping("/");
  MultipartConfigElement multipartConfig = createMultipartConfigElement();
  defaultServlet.setMultipartConfig(multipartConfig);
  info.addServlets(defaultServlet);
  DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info);
  deploymentManager.deploy();
  return deploymentManager;
}

代码示例来源:origin: org.seedstack.seed/seed-web-undertow

DeploymentManager createDeploymentManager() {
  DeploymentInfo servletBuilder = configureDeploymentInfo();
  return Servlets.defaultContainer().addDeployment(servletBuilder);
}

代码示例来源:origin: org.rapidpm.microservice/rapidpm-microservice-modules-core

static void deployServlets(final Builder builder , final DeploymentInfo deploymentInfo) throws ServletException {
 final ServletContainer servletContainer = defaultContainer();
 final DeploymentManager manager = servletContainer.addDeployment(deploymentInfo);
 manager.deploy();
 final HttpHandler servletHandler = manager.start();
 final PathHandler pathServlet = Handlers
   .path(Handlers.redirect(MYAPP))
   .addPrefixPath(MYAPP , servletHandler);
 final String realServletPort = System.getProperty(SERVLET_PORT_PROPERTY , DEFAULT_SERVLET_PORT + "");
 final String realServletHost = System.getProperty(SERVLET_HOST_PROPERTY , Main.DEFAULT_HOST);
 builder.addHttpListener(Integer.parseInt(realServletPort) , realServletHost , pathServlet);
}

代码示例来源:origin: org.projectodd.wunderboss/wunderboss-web-undertow

public void run() {
        try {
          manager.stop();
          manager.undeploy();
          Servlets.defaultContainer().removeDeployment(servletBuilder);
        } catch (ServletException e) {
          e.printStackTrace();
        }}});
} catch (ServletException e) {

代码示例来源:origin: cassiomolin/jersey-jwt

deploymentManager = Servlets.defaultContainer().addDeployment(servletBuilder);
deploymentManager.deploy();

代码示例来源:origin: com.github.skjolber.mockito-rest-spring/undertow

private Undertow configureUndertow(MockitoSpringWebApplicationContext context, URL url) throws ServletException {
  // https://github.com/yarosla/spring-undertow/blob/master/src/main/java/ys/undertow/UndertowMain.java
  DeploymentInfo servletBuilder = Servlets.deployment()
      .setClassLoader(Undertow.class.getClassLoader())
      .setContextPath(url.getPath())
      .setDeploymentName("mock")
      .addServlet(createDispatcherServlet(context))
      .addListener(createContextLoaderListener(context));
  DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
  manager.deploy();
  PathHandler path = Handlers.path(Handlers.redirect("/"))
      .addPrefixPath(CONTEXT_PATH, manager.start());
  return Undertow.builder()
      .addHttpListener(url.getPort(), url.getHost())
      .setHandler(path)
      .build();
}

代码示例来源:origin: com.jwebmp/jwebmp-undertow

.getContextClassLoader());
DeploymentManager manager = Servlets.defaultContainer()
                  .addDeployment(websocketDeployment);

代码示例来源:origin: arun-gupta/wildfly-samples

public SimpleServletServer() {
  DeploymentInfo deploymentInfo = deployment()
      .setClassLoader(SimpleServletServer.class.getClassLoader())
      .setContextPath("/helloworld")
      .setDeploymentName("helloworld.war")
      .addServlets(
          Servlets.servlet("MyServlet", MyServlet.class)
            .addInitParam("message", "Hello World")
            .addMapping("/MyServlet"),
          Servlets.servlet("MyAnotherServlet", MyAnotherServlet.class)
            .addMapping("/MyAnotherServlet")
      );
  DeploymentManager manager = defaultContainer().addDeployment(deploymentInfo);
  manager.deploy ();
  try {
    server = Undertow.builder()
        .addListener(8080, "localhost")
        .setHandler(manager.start())
        .build();
  } catch (ServletException ex) {
    Logger.getLogger(SimpleServletServer.class.getName()).log(Level.SEVERE, null, ex);
  }
}

代码示例来源:origin: com.fitbur.testify/server-undertow

@Override
public ServerInstance init(ServerDescriptor descriptor, DeploymentInfo deploymentInfo) {
  try {
    DeploymentManager manager = Servlets.defaultContainer()
        .addDeployment(deploymentInfo);
    manager.deploy();
    HttpHandler httpHandler = manager.start();
    RedirectHandler defaultHandler = Handlers.redirect(deploymentInfo.getContextPath());
    PathHandler pathHandler = Handlers.path(defaultHandler);
    pathHandler.addPrefixPath(deploymentInfo.getContextPath(), httpHandler);
    Undertow undertow = Undertow.builder()
        .addHttpListener(0, deploymentInfo.getHostName(), pathHandler)
        .build();
    return new UndertowServerInstance(undertow, deploymentInfo);
  } catch (Exception e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: com.fitbur.testify.server/server-undertow

@Override
public ServerInstance init(ServerDescriptor descriptor, DeploymentInfo deploymentInfo) {
  try {
    DeploymentManager manager = Servlets.defaultContainer()
        .addDeployment(deploymentInfo);
    manager.deploy();
    HttpHandler httpHandler = manager.start();
    RedirectHandler defaultHandler = Handlers.redirect(deploymentInfo.getContextPath());
    PathHandler pathHandler = Handlers.path(defaultHandler);
    pathHandler.addPrefixPath(deploymentInfo.getContextPath(), httpHandler);
    Undertow undertow = Undertow.builder()
        .addHttpListener(0, deploymentInfo.getHostName(), pathHandler)
        .build();
    return new UndertowServerInstance(undertow, deploymentInfo);
  } catch (Exception e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: org.jboss.arquillian.container/undertow-embedded

private HTTPContext registerDeploymentInfo(Archive<?> archive) {
  UndertowWebArchive servletBuilder = (UndertowWebArchive) archive;
  final DeploymentInfo deploymentInfo = servletBuilder
      .getDeploymentInfo();
  deploymentManager = defaultContainer().addDeployment(
      deploymentInfo);
  deploymentManager.deploy();
  try {
    this.undertow = createUndertow(deploymentManager.start());
    this.undertow.start();
  } catch (ServletException e) {
    throw new IllegalArgumentException(e);
  }
  HTTPContext httpContext = new HTTPContext(
      configuration.getBindAddress(), configuration.getBindHttpPort());
  final Map<String, ServletInfo> servlets = deploymentInfo.getServlets();
  final Collection<ServletInfo> servletsInfo = servlets.values();
  for (ServletInfo servletInfo : servletsInfo) {
    httpContext.add(new Servlet(servletInfo.getName(),
        deploymentManager.getDeployment().getDeploymentInfo()
            .getContextPath()));
  }
  return httpContext;
}

代码示例来源:origin: allegro/hermes

private PathHandler createPathHandler() {
  try {
    Servlet tokenServlet = new OAuthAccessTokenServlet(storage);
    Servlet resourceServlet = new OAuthResourceServlet(storage);
    DeploymentInfo deploymentInfo = Servlets.deployment()
        .setClassLoader(OAuthTestServer.class.getClassLoader())
        .setContextPath("/")
        .setDeploymentName("OAuthTestServer")
        .addServlets(
            Servlets.servlet("AuthTokenServlet", OAuthAccessTokenServlet.class,
                new ImmediateInstanceFactory<>(tokenServlet))
                .addMapping(OAUTH2_TOKEN_ENDPOINT),
            Servlets.servlet("ResourceServlet", OAuthResourceServlet.class,
                new ImmediateInstanceFactory<>(resourceServlet))
                .addMapping(OAUTH2_RESOURCE_ENDPOINT)
        );
    DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(deploymentInfo);
    deploymentManager.deploy();
    HttpHandler servletHandler = deploymentManager.start();
    return Handlers.path().addPrefixPath("/", servletHandler);
  } catch (ServletException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: pl.allegro.tech.hermes/hermes-test-helper

private PathHandler createPathHandler() {
  try {
    Servlet tokenServlet = new OAuthAccessTokenServlet(storage);
    Servlet resourceServlet = new OAuthResourceServlet(storage);
    DeploymentInfo deploymentInfo = Servlets.deployment()
        .setClassLoader(OAuthTestServer.class.getClassLoader())
        .setContextPath("/")
        .setDeploymentName("OAuthTestServer")
        .addServlets(
            Servlets.servlet("AuthTokenServlet", OAuthAccessTokenServlet.class,
                new ImmediateInstanceFactory<>(tokenServlet))
                .addMapping(OAUTH2_TOKEN_ENDPOINT),
            Servlets.servlet("ResourceServlet", OAuthResourceServlet.class,
                new ImmediateInstanceFactory<>(resourceServlet))
                .addMapping(OAUTH2_RESOURCE_ENDPOINT)
        );
    DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(deploymentInfo);
    deploymentManager.deploy();
    HttpHandler servletHandler = deploymentManager.start();
    return Handlers.path().addPrefixPath("/", servletHandler);
  } catch (ServletException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.testifyproject.server/undertow

DeploymentInfo deploymentInfo) {
try {
  DeploymentManager deploymentManager = Servlets.defaultContainer()
      .addDeployment(deploymentInfo);

代码示例来源:origin: gitblit/fathom

protected DeploymentManager createFathomDeploymentManager() throws ServletException {
  DeploymentInfo info = Servlets.deployment();
  info.setDeploymentName("Fathom");
  info.setClassLoader(this.getClass().getClassLoader());
  info.setContextPath(settings.getContextPath());
  info.setIgnoreFlush(true);
  info.setDefaultEncoding("UTF-8");
  FilterInfo guiceFilter = new FilterInfo("GuiceFilter", GuiceFilter.class);
  guiceFilter.setAsyncSupported(true);
  info.addFilterUrlMapping("GuiceFilter", "/*", DispatcherType.REQUEST);
  info.addFilters(guiceFilter);
  ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class);
  defaultServlet.setAsyncSupported(true);
  defaultServlet.addMapping("/");
  ServletContextListener fathomListener = new ServletContextListener(settings);
  info.addListeners(new ListenerInfo(ServletContextListener.class, new ImmediateInstanceFactory<>(fathomListener)));
  MultipartConfigElement multipartConfig = new MultipartConfigElement(settings.getUploadFilesLocation(), settings.getUploadFilesMaxSize(), -1L, 0);
  defaultServlet.setMultipartConfig(multipartConfig);
  info.addServlets(defaultServlet);
  DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info);
  deploymentManager.deploy();
  return deploymentManager;
}

代码示例来源:origin: fstab/http2-examples

public static void main(final String[] args) throws Exception {
  assertJavaVersion8();
  DeploymentInfo servletBuilder = deployment()
      .setClassLoader(HelloWorldServlet.class.getClassLoader())
      .setContextPath(MYAPP)
      .setDeploymentName("hello-world.war")
      .addServlets(
          servlet("HelloWorldServlet", HelloWorldServlet.class)
              .addInitParam("message", "Hello World")
              .addMapping("/api/hello-world"));
  DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
  manager.deploy();
  HttpHandler servletHandler = manager.start();
  PathHandler path = Handlers.path(Handlers.redirect(MYAPP))
      .addPrefixPath(MYAPP, servletHandler);
  String bindAddress = System.getProperty("bind.address", "localhost");
  SSLContext sslContext = createSSLContext(loadKeyStore("server.keystore"), loadKeyStore("server.truststore"));
  Undertow server = Undertow.builder()
      .setServerOption(UndertowOptions.ENABLE_HTTP2, true)
      .addHttpsListener(8443, bindAddress, sslContext)
      .setHandler(path)
      .build();
  server.start();
}

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

protected void run() {
  try {
    final DeploymentInfo servletBuilder = deployment()
      .setClassLoader(AbstractUndertowServer.class.getClassLoader())
      .setContextPath(contextPath)
      .setDeploymentName("sse-test")
      .addServlets(
        servlet("MessageServlet", CXFNonSpringJaxrsServlet.class)
          .addInitParam("jaxrs.providers", JacksonJsonProvider.class.getName())
          .addInitParam("jaxrs.serviceClasses", BookStore.class.getName())
          .setAsyncSupported(true)
          .setLoadOnStartup(1)
          .addMapping("/rest/*")
       );
    final DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
    manager.deploy();
    PathHandler path = Handlers
      .path(Handlers.redirect("/"))
      .addPrefixPath("/", manager.start());
    server = Undertow.builder()
      .addHttpListener(port, "localhost")
      .setHandler(path)
      .build();
    server.start();
  } catch (final Exception ex) {
    ex.printStackTrace();
    fail(ex.getMessage());
  }
}

代码示例来源:origin: com.obsidiandynamics.socketx/socketx-undertow

servletBuilder.addServlet(info);
final DeploymentManager servletManager = Servlets.defaultContainer().addDeployment(servletBuilder);
servletManager.deploy();

相关文章