本文整理汇总了Java中io.netty.handler.codec.http.HttpScheme类的典型用法代码示例。如果您正苦于以下问题:Java HttpScheme类的具体用法?Java HttpScheme怎么用?Java HttpScheme使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpScheme类属于io.netty.handler.codec.http包,在下文中一共展示了HttpScheme类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHeadersForPushNotification
import io.netty.handler.codec.http.HttpScheme; //导入依赖的package包/类
protected Http2Headers getHeadersForPushNotification(final ApnsPushNotification pushNotification, final int streamId) {
final Http2Headers headers = new DefaultHttp2Headers()
.method(HttpMethod.POST.asciiName())
.authority(this.authority)
.path(APNS_PATH_PREFIX + pushNotification.getToken())
.scheme(HttpScheme.HTTPS.name())
.addInt(APNS_EXPIRATION_HEADER, pushNotification.getExpiration() == null ? 0 : (int) (pushNotification.getExpiration().getTime() / 1000));
if (pushNotification.getCollapseId() != null) {
headers.add(APNS_COLLAPSE_ID_HEADER, pushNotification.getCollapseId());
}
if (pushNotification.getPriority() != null) {
headers.addInt(APNS_PRIORITY_HEADER, pushNotification.getPriority().getCode());
}
if (pushNotification.getTopic() != null) {
headers.add(APNS_TOPIC_HEADER, pushNotification.getTopic());
}
return headers;
}
示例2: HTTP2Client
import io.netty.handler.codec.http.HttpScheme; //导入依赖的package包/类
public HTTP2Client(boolean ssl, String host, int port) throws Exception {
try {
final SslContext sslCtx;
if (ssl) {
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
sslCtx = SslContextBuilder.forClient()
.sslProvider(provider)
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocolConfig(new ApplicationProtocolConfig(
Protocol.ALPN,
// NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
SelectorFailureBehavior.NO_ADVERTISE,
// ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2,
ApplicationProtocolNames.HTTP_1_1))
.build();
} else {
sslCtx = null;
}
workerGroup = new NioEventLoopGroup();
HTTP2ClientInitializer initializer = new HTTP2ClientInitializer(sslCtx, Integer.MAX_VALUE);
// Configure the client.
Bootstrap b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
b.option(ChannelOption.SO_KEEPALIVE, true);
b.remoteAddress(host, port);
b.handler(initializer);
// Start the client.
channel = b.connect().syncUninterruptibly().channel();
log.info("Connected to [" + host + ':' + port + ']');
// Wait for the HTTP/2 upgrade to occur.
HTTP2SettingsHandler http2SettingsHandler = initializer.settingsHandler();
http2SettingsHandler.awaitSettings(TestUtil.HTTP2_RESPONSE_TIME_OUT, TestUtil.HTTP2_RESPONSE_TIME_UNIT);
responseHandler = initializer.responseHandler();
scheme = ssl ? HttpScheme.HTTPS : HttpScheme.HTTP;
hostName = new AsciiString(host + ':' + port);
} catch (Exception ex) {
log.error("Error while initializing http2 client " + ex);
this.close();
}
}