当前位置: 首页>>代码示例>>Java>>正文


Java Builder.addHttpListener方法代码示例

本文整理汇总了Java中io.undertow.Undertow.Builder.addHttpListener方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.addHttpListener方法的具体用法?Java Builder.addHttpListener怎么用?Java Builder.addHttpListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.undertow.Undertow.Builder的用法示例。


在下文中一共展示了Builder.addHttpListener方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
public static void start(String[] args) throws ServletException {
    Map<String, String> commands = Arrays.stream(args)
            .map(cmd -> cmd.split(REGEX_EQ))
            .collect(toMap(cmdArray -> cmdArray[IDX_ZERO], cmdArray -> cmdArray[IDX_ONE]));
    Config undertowConf = Configs.DEFAULT.undertow();
    Config httpConf = undertowConf.getConfig(KEY_HTTP);
    Logger logger = LoggerFactory.getLogger(Server.class);
    logger.debug("Commands to AdeptJ Runtime: {}", commands);
    int httpPort = handlePortAvailability(httpConf, logger);
    logger.info("Starting AdeptJ Runtime @port: [{}]", httpPort);
    printBanner(logger);
    DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo(undertowConf));
    manager.deploy();
    Builder builder = Undertow.builder();
    optimizeWorkerOptions(builder, undertowConf, logger);
    ServerOptions.build(builder, undertowConf);
    builder.addHttpListener(httpPort, httpConf.getString(KEY_HOST));
    enableHttp2(undertowConf, builder, logger);
    enableAJP(undertowConf, builder, logger);
    GracefulShutdownHandler rootHandler = rootHandler(headersHandler(manager.start(), undertowConf), undertowConf);
    Undertow server = builder.setHandler(rootHandler).build();
    server.start();
    Runtime.getRuntime().addShutdownHook(new ShutdownHook(server, manager, rootHandler));
    launchBrowser(commands, httpPort, logger);
    if (!Environment.isServerConfFileExists()) {
        createServerConfFile(logger);
    }
}
 
开发者ID:AdeptJ,项目名称:adeptj-runtime,代码行数:29,代码来源:Server.java

示例2: start

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
public void start() throws ServletException, IOException {
	DeploymentInfo servletInfo = LuceeServletBuilder.build( libDirs, webroot, webXmlPath, webInfPath );

	deploymentManager = defaultContainer().addDeployment( servletInfo );
	deploymentManager.deploy();

	HttpHandler httpHandler = deploymentManager.start();
	PathHandler pathHandler = Handlers.path( Handlers.redirect( "/" ) ).addPrefixPath( "/", httpHandler );
	Builder     builder     = Undertow.builder();

	builder.addHttpListener( port, host );
	builder.setHandler( pathHandler );

	undertowServer = builder.build();
	undertowServer.start();
}
 
开发者ID:DominicWatson,项目名称:embedded-lucee-undertow-factory,代码行数:17,代码来源:LuceeUndertowServer.java

示例3: main

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
public static void main(String[] args) {
  final Builder builder = Undertow
      .builder()
      .setDirectBuffers(true)
      .setServerOption(UndertowOptions.ENABLE_HTTP2 , true);

  final Application jaxRsActivator = new Application() {
    @Override
    public Set<Class<?>> getClasses() {
      final Set<Class<?>> classes = new HashSet<>();
      classes.add(ServiceREST.class);
      classes.add(LoginREST.class);
      return classes;
    }
  };

  final String realRestPort = System.getProperty(REST_PORT_PROPERTY , DEFAULT_REST_PORT + "");
  final String realRestHost = System.getProperty(REST_HOST_PROPERTY , MainRest.DEFAULT_HOST);

  System.setProperty(RESTEASY_PORT_PROPERTY , realRestPort);
  System.setProperty(RESTEASY_HOST_PROPERTY , realRestHost);

  builder.addHttpListener(Integer.parseInt(realRestPort) , realRestHost);
  jaxrsServer = new UndertowJaxrsServer().start(builder);
  final ResteasyDeployment deployment = new ResteasyDeployment();
  deployment.setApplication(jaxRsActivator);
  jaxrsServer.deploy(jaxrsServer.undertowDeployment(deployment)
                                .setDeploymentName("Rest")
                                .setContextPath(CONTEXT_PATH_REST)
                                .setClassLoader(MainRest.class.getClassLoader()));
}
 
开发者ID:Java-Publications,项目名称:javamagazin-009-microkernel,代码行数:32,代码来源:MainRest.java

示例4: createBuilder

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
private Builder createBuilder(int port) {
	Builder builder = Undertow.builder();
	if (this.bufferSize != null) {
		builder.setBufferSize(this.bufferSize);
	}
	if (this.buffersPerRegion != null) {
		builder.setBuffersPerRegion(this.buffersPerRegion);
	}
	if (this.ioThreads != null) {
		builder.setIoThreads(this.ioThreads);
	}
	if (this.workerThreads != null) {
		builder.setWorkerThreads(this.workerThreads);
	}
	if (this.directBuffers != null) {
		builder.setDirectBuffers(this.directBuffers);
	}
	if (getSsl() != null && getSsl().isEnabled()) {
		configureSsl(getSsl(), port, builder);
	}
	else {
		builder.addHttpListener(port, getListenAddress());
	}
	for (UndertowBuilderCustomizer customizer : this.builderCustomizers) {
		customizer.customize(builder);
	}
	return builder;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:29,代码来源:UndertowEmbeddedServletContainerFactory.java

示例5: createServer

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
protected io.undertow.Undertow createServer(HttpHandler contextHandler) {

        int ports = settings.getHttpPort() + settings.getHttpsPort() + settings.getAjpPort();
        Preconditions.checkState(ports > 0, "No port specified! Please review your server port settings!");

        log.debug("Configuring Undertow engine");

        Builder builder = io.undertow.Undertow.builder();

        if (settings.getHttpPort() > 0) {
            // HTTP
            builder.addHttpListener(settings.getHttpPort(), settings.getHttpListenAddress());
            logSetting(Settings.Setting.undertow_httpPort, settings.getHttpPort());
        }

        if (settings.getHttpsPort() > 0) {
            // HTTPS
            builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true);
            try {
                KeyStore keyStore = loadKeyStore(settings.getKeystoreFile(), settings.getKeystorePassword());
                KeyStore trustStore = loadKeyStore(settings.getTruststoreFile(), settings.getTruststorePassword());
                SSLContext sslContext = createSSLContext(keyStore, trustStore);
                builder.addHttpsListener(settings.getHttpsPort(), settings.getHttpsListenAddress(), sslContext);
                logSetting(Settings.Setting.undertow_httpsPort, settings.getHttpsPort());
            } catch (Exception e) {
                throw new FathomException(e, "Failed to setup an Undertow SSL listener!");
            }
        }

        if (settings.getAjpPort() > 0) {
            // AJP
            builder.addAjpListener(settings.getAjpPort(), settings.getAjpListenAddress());
            logSetting(Settings.Setting.undertow_ajpPort, settings.getAjpPort());
        }

        int ioThreads = settings.getInteger(Settings.Setting.undertow_ioThreads, 0);
        if (ioThreads > 0) {
            builder.setIoThreads(ioThreads);
            logSetting(Settings.Setting.undertow_ioThreads, ioThreads);
        }

        int workerThreads = settings.getInteger(Settings.Setting.undertow_workerThreads, 0);
        if (workerThreads > 0) {
            builder.setWorkerThreads(workerThreads);
            logSetting(Settings.Setting.undertow_workerThreads, workerThreads);
        }

        long bufferSize = settings.getBytes(Settings.Setting.undertow_bufferSize, null);
        if (bufferSize > 0) {
            builder.setBufferSize((int) bufferSize);
            logSetting(Settings.Setting.undertow_bufferSize, bufferSize);
        }

        builder.setHandler(contextHandler);
        io.undertow.Undertow server = builder.build();
        return server;
    }
 
开发者ID:gitblit,项目名称:fathom,代码行数:58,代码来源:Server.java

示例6: prepareUndertow

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
private static void prepareUndertow() {
    if (!error) {
        Config config = injector.getInstance(Config.class);
        
        HttpHandler httpHandler;
        if (config.isMetricsEnabled()) {
            httpHandler = MetricsHandler.HANDLER_WRAPPER.wrap(Handlers.exceptionHandler(pathHandler)
                    .addExceptionHandler(Throwable.class, Application.getInstance(ExceptionHandler.class)));
        } else {
            httpHandler = Handlers.exceptionHandler(pathHandler)
                    .addExceptionHandler(Throwable.class, Application.getInstance(ExceptionHandler.class));
        }
        
        Builder builder = Undertow.builder()
                .setServerOption(UndertowOptions.MAX_ENTITY_SIZE, config.getUndertowMaxEntitySize())
                .setHandler(httpHandler);

        httpHost = config.getConnectorHttpHost();
        httpPort = config.getConnectorHttpPort();
        ajpHost = config.getConnectorAjpHost();
        ajpPort = config.getConnectorAjpPort();

        boolean hasConnector = false;
        if (httpPort > 0 && StringUtils.isNotBlank(httpHost)) {
            builder.addHttpListener(httpPort, httpHost);
            hasConnector = true;
        }
        
        if (ajpPort > 0 && StringUtils.isNotBlank(ajpHost)) {
            builder.addAjpListener(ajpPort, ajpHost);
            hasConnector = true;
        }
                
        if (hasConnector) {
            undertow = builder.build();
            undertow.start();
        } else {
            LOG.error("No connector found! Please configure a HTTP and/or AJP connector in your application.yaml");
            error = true;
        }
    }
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:43,代码来源:Application.java

示例7: createServer

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
protected Undertow createServer(HttpHandler contextHandler) {
    Builder builder = Undertow.builder();
    // TODO is it a better option?
    if (getSettings().getBufferSize() > 0) {
        builder.setBufferSize(getSettings().getBufferSize());
    }
    // method builder.setBuffersPerRegion is deprecated
    /*
    if (getSettings().getBuffersPerRegion() > 0) {
        builder.setBuffersPerRegion(getSettings().getBuffersPerRegion());
    }
    */
    if (getSettings().getDirectBuffers()) {
        builder.setDirectBuffers(getSettings().getDirectBuffers());
    }
    if (getSettings().getIoThreads() > 0) {
        builder.setIoThreads(getSettings().getIoThreads());
    }
    if (getSettings().getWorkerThreads() > 0) {
        builder.setWorkerThreads(getSettings().getWorkerThreads());
    }

    if (getSettings().getKeystoreFile() == null) {
        // HTTP
        builder.addHttpListener(getSettings().getPort(), getSettings().getHost());
    } else {
        // HTTPS
        builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true);
        try {
            KeyStore keyStore = loadKeyStore(getSettings().getKeystoreFile(), getSettings().getKeystorePassword());
            KeyStore trustStore = loadKeyStore(getSettings().getTruststoreFile(), getSettings().getTruststorePassword());
            SSLContext sslContext = createSSLContext(keyStore, trustStore);
            builder.addHttpsListener(getSettings().getPort(), getSettings().getHost(), sslContext);
        } catch (Exception e) {
            throw new PippoRuntimeException(e, "Failed to setup an Undertow SSL listener!");
        }
    }

    // add undertow options
    getSettings().addUndertowOptions(builder);
    builder.setHandler(contextHandler);

    return builder.build();
}
 
开发者ID:decebals,项目名称:pippo,代码行数:45,代码来源:UndertowServer.java

示例8: start

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
/**
    * Start the management interface.
    *
    */
public void start() {
	
	Builder builder = Undertow.builder();
	
	// add listener
	builder.addHttpListener(this.managementPort, this.managementInterface);
	
	// set up resource handler
	ClassPathResourceManager classPathManager = new ClassPathResourceManager(Thread.currentThread().getContextClassLoader(), "web");
	ResourceHandler resources = Handlers.resource(classPathManager);
	resources.setWelcomeFiles("index.html");
	resources.setDirectoryListingEnabled(false);
	
	// set up servlet handler
	DeploymentInfo servletBuilder = Servlets.deployment()
			.setClassLoader(Thread.currentThread().getContextClassLoader())
			.setContextPath("/services")
			.setDeploymentName("pincushion-services.war")
			;
	
	// add context parameters
	//servletBuilder.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX, "/");
	
	// add context listener for bootstrap
	ListenerInfo restBootstrapListener = Servlets.listener(ResteasyBootstrap.class, new ResteasyBootstrapInstanceFactory(this.manager));
	servletBuilder.addListener(restBootstrapListener);
	
	// create and add servlet to servlet handler
	ServletInfo restServletInfo = Servlets.servlet("restEasyHandler", HttpServletDispatcher.class);
	restServletInfo.addInitParam("javax.ws.rs.Application", ManagementApplication.class.getName());
	restServletInfo.addMapping("/*");
	restServletInfo.setLoadOnStartup(1);
	servletBuilder.addServlet(restServletInfo);
	
	// deploy servlets
	DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(servletBuilder);
	
	deploymentManager.deploy();
	HttpHandler services = null;
	try {
		services = deploymentManager.start();
	} catch (ServletException e) {
		this.logger.error("Could not start services deployment: {}", e.getLocalizedMessage());
	}

	// create paths
	PathHandler path = Handlers.path(resources);
	if(services != null) {
		path.addPrefixPath("/services", services);
	}
	
	// create encoding repository
	ContentEncodingRepository repo = new ContentEncodingRepository();

       // permit gzip and deflate
	repo.addEncodingHandler("gzip", new GzipEncodingProvider(), 1000);
	repo.addEncodingHandler("deflate", new DeflateEncodingProvider(), 10);
	
	// ensure that everything can be encoded with appropriate compression
	EncodingHandler encoder = new EncodingHandler(path, repo);
	
	// add path handler to server
	builder.setHandler(encoder);
	
	// start undertow server
	this.server = builder.build();
	this.server.start();
	
	this.logger.info("Started undertow management interface at {} on port {}", this.managementInterface, this.managementPort);
}
 
开发者ID:chrisruffalo,项目名称:pincushion,代码行数:75,代码来源:ManagementInterface.java


注:本文中的io.undertow.Undertow.Builder.addHttpListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。