本文整理汇总了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;
}
示例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();
}
示例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);
}
}