io.undertow.servlet.Servlets类的使用及代码示例

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

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

Servlets介绍

[英]Utility class for building servlet deployments.
[中]用于构建servlet部署的实用程序类。

代码示例

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

final DeploymentInfo d = new DeploymentInfo();
d.setContextPath(resolveContextPath());
if (mergedMetaData.getDescriptionGroup() != null) {
    if(!jspServlet.getMappings().contains(mapping)) {
      jspServlet.addMapping(mapping);
    s.setMultipartConfig(Servlets.multipartConfig(mp.getLocation(), mp.getMaxFileSize(), mp.getMaxRequestSize(), mp.getFileSizeThreshold()));
  ServletInfo defaultServlet = Servlets.servlet(DEFAULT_SERVLET_NAME, DefaultServlet.class);
  handleServletMappings(is22OrOlder, seenMappings, servletMappings, defaultServlet);

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

ServletInfo servletInfo = servlet("DispatcherServlet", DispatcherServlet.class, servletFactory)
    .addMapping("/").setAsyncSupported(true);
DeploymentInfo servletBuilder = deployment()
    .setClassLoader(UndertowTestServer.class.getClassLoader())
    .setDeploymentName("undertow-websocket-test")
    .setContextPath("/")
    .addServlet(servletInfo)
    .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, info);
  this.manager = defaultContainer().addDeployment(servletBuilder);
  this.manager.deploy();
  HttpHandler httpHandler = this.manager.start();

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

private void handleAuthManagerLogout(DeploymentInfo deploymentInfo, JBossWebMetaData mergedMetaData) {
  AuthenticationManager manager = securityDomainContextValue.getValue().getAuthenticationManager();
  deploymentInfo.addNotificationReceiver(new LogoutNotificationReceiver(manager, securityDomain));
  if(mergedMetaData.isFlushOnSessionInvalidation()) {
    LogoutSessionListener listener = new LogoutSessionListener(manager);
    deploymentInfo.addListener(Servlets.listener(LogoutSessionListener.class, new ImmediateInstanceFactory<EventListener>(listener)));
  }
}

代码示例来源: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: org.springframework.boot/spring-boot

private DeploymentManager createDeploymentManager(
    ServletContextInitializer... initializers) {
  DeploymentInfo deployment = Servlets.deployment();
  registerServletContainerInitializerToDriveServletContextInitializers(deployment,
      initializers);
  deployment.setClassLoader(getServletClassLoader());
  deployment.setContextPath(getContextPath());
  deployment.setDisplayName(getDisplayName());
  deployment.setDeploymentName("spring-boot");
  if (isRegisterDefaultServlet()) {
    deployment.addServlet(Servlets.servlet("default", DefaultServlet.class));
  DeploymentManager manager = Servlets.newContainer().addDeployment(deployment);
  manager.deploy();
  SessionManager sessionManager = manager.getDeployment().getSessionManager();

代码示例来源: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/server-undertow

@Override
public DeploymentInfo configuration(ServerDescriptor descriptor) {
  try {
    App app = descriptor.getApp();
    Set<Class<?>> handles = descriptor.getHandlesType();
    String name = descriptor.getTestClassName();
    ServletContainerInitializer initializer = descriptor.getServletContainerInitializer();
    ImmediateInstanceFactory<ServletContainerInitializer> factory = new ImmediateInstanceFactory<>(initializer);
    URI uri = URI.create("http://0.0.0.0:0/");
    ServletContainerInitializerInfo initInfo
        = new ServletContainerInitializerInfo(initializer.getClass(),
            factory, handles);
    ServletInfo servletInfo = Servlets.servlet(name, DefaultServlet.class)
        .setAsyncSupported(true);
    DeploymentInfo deploymentInfo = Servlets.deployment()
        .addServletContainerInitalizer(initInfo)
        .setClassLoader(descriptor.getTestClass().getClassLoader())
        .setHostName(uri.getHost())
        .setContextPath(uri.getPath())
        .setDeploymentName(name)
        .addServlet(servletInfo);
    return deploymentInfo;
  } catch (Exception e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: ws.ament.hammock/web-undertow

@Override
public void start() {
  DeploymentInfo di = new DeploymentInfo()
      .setContextPath("/")
      .setDeploymentName("Undertow")
      .setResourceManager(new ClassPathResourceManager(getClass().getClassLoader()))
      .setClassLoader(ClassLoader.getSystemClassLoader());
  super.getListeners().forEach(c ->di.addListener(listener(c)));
  servlets.forEach(di::addServlet);
  getFilterDescriptors().forEach(filterDescriptor -> {
    FilterInfo filterInfo = filter(filterDescriptor.displayName(), filterDescriptor.getClazz()).setAsyncSupported(filterDescriptor.asyncSupported());
    if(filterDescriptor.initParams() != null) {
      for (WebInitParam param : filterDescriptor.initParams()) {
  DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(di);
  deploymentManager.deploy();
  try {

代码示例来源:origin: org.commonjava.indy/indy-subsys-jaxrs

deployment.setInjectorFactoryClass( CdiInjectorFactoryImpl.class.getName() );
final ServletInfo resteasyServlet = Servlets.servlet( "REST", HttpServlet30Dispatcher.class )
                      .setAsyncSupported( true )
                      .setLoadOnStartup( 1 )
                      .addMapping( "/api*" )
                      .addMapping( "/api/*" )
                      .addMapping( "/api-docs*" )
    Servlets.filter( "Naming and Resource Management", ResourceManagementFilter.class,
             new ImmediateInstanceFactory<ResourceManagementFilter>(
                 this.resourceManagementFilter ) );
final FilterInfo apiVersioningFilter =
        Servlets.filter( "ApiVersioning", ApiVersioningFilter.class,
                 new ImmediateInstanceFactory<ApiVersioningFilter>(
                         this.apiVersioningFilter ) );
final DeploymentInfo di = new DeploymentInfo().addListener( Servlets.listener( RequestScopeListener.class ) )
                       .setContextPath( contextRoot )
                       .addServletContextAttribute( ResteasyDeployment.class.getName(),
                                      deployment )
  final ServletInfo uiServlet = Servlets.servlet( "UI", UIServlet.class )
                     .setAsyncSupported( true )
                     .setLoadOnStartup( 99 )

代码示例来源:origin: yangfuhai/jboot

private DeploymentInfo buildDeploymentInfo(JbootServerClassloader classloader) {
  DeploymentInfo deploymentInfo = Servlets.deployment()
      .setClassLoader(classloader)
      .setResourceManager(new ClassPathResourceManager(classloader))
      .setContextPath(config.getContextPath())
    deploymentInfo.addListeners(Servlets.listener(EnvironmentLoaderListener.class));
    deploymentInfo.addFilter(
        Servlets.filter("shiro", JbootShiroFilter.class))
      Servlets.filter("jfinal", JFinalFilter.class)
        Servlets.servlet("HystrixMetricsStreamServlet", HystrixMetricsStreamServlet.class)
            .addMapping(hystrixConfig.getUrl()));
        Servlets.servlet("MetricsAdminServlet", AdminServlet.class)
            .addMapping(metricsConfig.getMappingUrl()));
    deploymentInfo.addListeners(Servlets.listener(JbootMetricServletContextListener.class));
    deploymentInfo.addListeners(Servlets.listener(JbootHealthCheckServletContextListener.class));
    ServletInfo servletInfo = Servlets.servlet(entry.getKey(), entry.getValue().getServletClass()).addMappings(entry.getValue().getUrlMapping());
    deploymentInfo.addListeners(Servlets.listener(listenerClass));
      Servlets.servlet("JbootResourceServlet", JbootResourceServlet.class)

代码示例来源:origin: com.github.wuic/wuic-test

final io.undertow.servlet.api.ServletContainer container = io.undertow.servlet.api.ServletContainer.Factory.newInstance();
final DeploymentInfo builder = new DeploymentInfo()
    .setClassLoader(clazz.getClassLoader())
    .setContextPath("/")
    .setDeploymentName("ServletContainer.war")
    .setResourceManager(new FileResourceManager(new File(resource.getFile()), 100));
  builder.addServlet(Servlets.servlet("WuicServlet", installServlet).addMapping(WUIC_SERVLET_MAPPING));

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

DeploymentInfo servletBuilder = Servlets.deployment()
    .setClassLoader(Application.class.getClassLoader())
    .setContextPath("/")
    .addListeners(listener(Listener.class))
    .setResourceManager(new ClassPathResourceManager(Application.class.getClassLoader()))
    .addServlets(
        Servlets.servlet("jerseyServlet", ServletContainer.class)
            .setLoadOnStartup(1)
            .addInitParam("javax.ws.rs.Application", JerseyConfig.class.getName())
            .addMapping("/api/*"))
    .setDeploymentName("application.war");
deploymentManager = Servlets.defaultContainer().addDeployment(servletBuilder);
deploymentManager.deploy();

代码示例来源: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: org.rapidpm.microservice/rapidpm-microservice-modules-core

.map(c -> {
   Class<HttpServlet> servletClass = (Class<HttpServlet>) c;
   final ServletInfo servletInfo = servlet(c.getSimpleName() , servletClass , new ServletInstanceFactory<>(servletClass));
   if (c.isAnnotationPresent(WebInitParam.class)) {
    final WebInitParam[] annotationsByType = c.getAnnotationsByType(WebInitParam.class);
     final String value = webInitParam.value();
     final String name = webInitParam.name();
     servletInfo.addInitParam(name , value);
   final String[] urlPatterns = annotation.urlPatterns();
   for (String urlPattern : urlPatterns) {
    servletInfo.addMapping(urlPattern);
   servletInfo.setAsyncSupported(annotation.asyncSupported());
   return servletInfo;
  })
final DeploymentInfo deploymentInfo = deployment()
  .setClassLoader(Main.class.getClassLoader())
  .setContextPath(MYAPP)
  .setDeploymentName("ROOT" + ".war")
  .setDefaultEncoding("UTF-8");

代码示例来源: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: io.squark.yggdrasil.yggdrasil-framework-provider/yggdrasil-servlet-provider

Servlets.deployment().setClassLoader(this.getClass().getClassLoader()).setContextPath(contextPath)
  .setDeploymentName(deploymentName).addListener(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class))
  .addInitParameter(WeldServletLifecycle.class.getPackage().getName() + ".archive.isolation", "false")
  .addServletContextAttribute(WeldServletLifecycle.BEAN_MANAGER_ATTRIBUTE_NAME, beanManager);
  ServletInfo servletInfo = convertServletInfo(yggdrasilServletInfo);
  deployment.addServlet(servletInfo);
  mappings.addAll(servletInfo.getMappings());
 });
 di.getWelcomePages().forEach(deployment::addWelcomePage);
 di.getInitParameters().forEach(deployment::addInitParameter);
 di.getListeners().forEach(listenerClass -> deployment.addListener(Servlets.listener(listenerClass)));
 di.getServletContextAttributes().forEach(deployment::addServletContextAttribute);
 di.getClassPathResources().forEach(path -> combinedResourceManager.addResourceManager(new ClassPathResourceManager(this.getClass().getClassLoader(), path)));
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
manager.deploy();
HttpHandler servletHandler;

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

manager = new UndertowEndpointManager(scanner, config.idleTimeoutMillis, config, listener);
final DeploymentInfo servletBuilder = Servlets.deployment()
  .setClassLoader(UndertowServer.class.getClassLoader())
  .setDeploymentName("servlet").setContextPath("");
for (XMappedServlet servlet : config.servlets) {
 final ServletInfo info = Servlets.servlet(servlet.getName(), servlet.getServletClass())
   .addMapping(servlet.getPath());
 servletBuilder.addServlet(info);
final DeploymentManager servletManager = Servlets.defaultContainer().addDeployment(servletBuilder);
servletManager.deploy();

代码示例来源:origin: org.commonjava.indy/indy-subsys-jaxrs

@Override
  public DeploymentInfo getDeploymentInfo( String contextRoot, Application application )
  {
    if ( !config.isMetricsEnabled() )
    {
      return null;
    }

    final ServletInfo servlet =
            Servlets.servlet( "healthcheck", HealthCheckServlet.class ).addMapping( "/healthcheck" );

    final DeploymentInfo di = new DeploymentInfo().addListener(
            Servlets.listener( IndyHealthCheckServletContextListener.class ) )
                           .setContextPath( contextRoot )
                           .addServlet( servlet )
                           .setDeploymentName( "HealthCheck Deployment" )
                           .setClassLoader( ClassLoader.getSystemClassLoader() );

    logger.info( "Returning deployment info for health check" );
    return di;
  }
}

代码示例来源:origin: io.silverware/http-server-microservice-provider

@Override
@SuppressWarnings("unchecked")
public void deployServlet(final String contextPath, final String deploymentName,
   final List<ServletDescriptor> servletDescriptors) throws SilverWareException {
 final DeploymentInfo servletBuilder = Servlets
    .deployment()
    .setClassLoader(this.getClass().getClassLoader())
    .setContextPath(contextPath)
    .setDeploymentName(deploymentName);
 if (servletDescriptors != null) {
   servletDescriptors.forEach(servletDescriptor -> {
    final ServletInfo servletInfo = Servlets
       .servlet(servletDescriptor.getName(), (Class<Servlet>) servletDescriptor.getServletClass());
    servletInfo.addMapping(servletDescriptor.getMapping());
    servletDescriptor
       .getProperties()
       .forEach((key, value) -> servletInfo.addInitParam((String) key, (String) value));
    servletBuilder.addServlet(servletInfo);
   });
 }
 this.server.deploy(servletBuilder);
}

代码示例来源:origin: io.digdag/digdag-guice-rs-server-undertow

DeploymentInfo servletBuilder = Servlets.deployment()
  .setClassLoader(bootstrap.getClass().getClassLoader())
  .setContextPath("/rs")
  .setDeploymentName("rs.war")
  .addFilter(new FilterInfo("AddListenAddressName", SetListenAddressNameServletFilter.class))
  .addFilterUrlMapping("AddListenAddressName", "/*", DispatcherType.REQUEST)
DeploymentManager deployment = Servlets.defaultContainer()
  .addDeployment(servletBuilder);

相关文章