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


Java Builder.addHttpsListener方法代码示例

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


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

示例1: 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

示例2: 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

示例3: start

import io.undertow.Undertow.Builder; //导入方法依赖的package包/类
@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)));

    Collection<Class<?>> endpoints = extension.getEndpointClasses();
    if(!endpoints.isEmpty()) {
        WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
        endpoints.forEach(webSocketDeploymentInfo::addEndpoint);
        di.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSocketDeploymentInfo);
    }

    getServletContextAttributes().forEach(di::addServletContextAttribute);
    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()) {
                filterInfo.addInitParam(param.name(), param.value());
            }
        }
        di.addFilter(filterInfo);
        for(String url : filterDescriptor.urlPatterns()) {
            for(DispatcherType dispatcherType : filterDescriptor.dispatcherTypes()) {
                di.addFilterUrlMapping(filterDescriptor.displayName(), url, dispatcherType);
            }
        }
    });

    getInitParams().forEach(di::addInitParameter);

    DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(di);
    deploymentManager.deploy();
    try {
        HttpHandler servletHandler = deploymentManager.start();
        PathHandler path = path(Handlers.redirect("/"))
                .addPrefixPath("/", servletHandler);
        Builder undertowBuilder = Undertow.builder()
                .addHttpListener(webServerConfiguration.getPort(), webServerConfiguration.getAddress())
                .setHandler(path);
        if (hammockRuntime.isSecuredConfigured()){
        	KeyManager[] keyManagers = loadKeyManager();
        	TrustManager[] trustManagers = loadTrustManager();
        	SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagers, trustManagers, null);
        	undertowBuilder = undertowBuilder.addHttpsListener(webServerConfiguration.getSecuredPort(), webServerConfiguration.getAddress(), sslContext);
        }
        this.undertow = undertowBuilder.build();
        this.undertow.start();
    } catch (ServletException | GeneralSecurityException | IOException e) {
        throw new RuntimeException("Unable to start server", e);
    }
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:59,代码来源:UndertowWebServer.java


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