• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SslEngineConfigurator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.glassfish.tyrus.client.SslEngineConfigurator的典型用法代码示例。如果您正苦于以下问题:Java SslEngineConfigurator类的具体用法?Java SslEngineConfigurator怎么用?Java SslEngineConfigurator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: prepareConnection

import org.glassfish.tyrus.client.SslEngineConfigurator; //导入依赖的package包/类
/**
 * Create and configure a Client Manager.
 */
private void prepareConnection() {
    clientManager = ClientManager.createClient();
    clientManager.getProperties().put(ClientProperties.RECONNECT_HANDLER, new Reconnect());

    // Try to add Let's Encrypt cert for SSL
    try {
        SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(
                SSLUtil.getSSLContextWithLE(), true, false, false);
        clientManager.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
        ssl = true;
    } catch (Exception ex) {
        LOGGER.warning("Failed adding support for Lets Encrypt: " + ex);
        ssl = false;
    }
}
 
开发者ID:chatty,项目名称:chatty,代码行数:19,代码来源:WebsocketClient.java


示例2: open

import org.glassfish.tyrus.client.SslEngineConfigurator; //导入依赖的package包/类
public void open(ClientHandler clientEndpoint) throws IOException, DeploymentException, URISyntaxException {

        Cookie sessionCookie = null;
        if (doLogin) {
            BasicCookieStore cookieJar = new BasicCookieStore();
            try (CloseableHttpClient client = HttpClient.get(ssl, cookieJar, hostVerificationEnabled)) {

                String target = "https://" + timelyHostname + ":" + timelyHttpsPort + "/login";

                HttpRequestBase request = null;
                if (StringUtils.isEmpty(timelyUsername)) {
                    // HTTP GET to /login to use certificate based login
                    request = new HttpGet(target);
                    LOG.trace("Performing client certificate login");
                } else {
                    // HTTP POST to /login to use username/password
                    BasicAuthLogin login = new BasicAuthLogin();
                    login.setUsername(timelyUsername);
                    login.setPassword(timelyPassword);
                    String payload = JsonSerializer.getObjectMapper().writeValueAsString(login);
                    HttpPost post = new HttpPost(target);
                    post.setEntity(new StringEntity(payload));
                    request = post;
                    LOG.trace("Performing BasicAuth login");
                }

                HttpResponse response = null;
                try {
                    response = client.execute(request);
                    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                        throw new HttpResponseException(response.getStatusLine().getStatusCode(), response
                                .getStatusLine().getReasonPhrase());
                    }
                    for (Cookie c : cookieJar.getCookies()) {
                        if (c.getName().equals("TSESSIONID")) {
                            sessionCookie = c;
                            break;
                        }
                    }
                    if (null == sessionCookie) {
                        throw new IllegalStateException(
                                "Unable to find TSESSIONID cookie header in Timely login response");
                    }
                } finally {
                    HttpClientUtils.closeQuietly(response);
                }
            }
        }

        SslEngineConfigurator sslEngine = new SslEngineConfigurator(ssl);
        sslEngine.setClientMode(true);
        sslEngine.setHostVerificationEnabled(hostVerificationEnabled);

        webSocketClient = ClientManager.createClient();
        webSocketClient.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngine);
        webSocketClient.getProperties().put(ClientProperties.INCOMING_BUFFER_SIZE, bufferSize);
        String wssPath = "wss://" + timelyHostname + ":" + timelyWssPort + "/websocket";
        session = webSocketClient.connectToServer(clientEndpoint, new TimelyEndpointConfig(sessionCookie), new URI(
                wssPath));

        final ByteBuffer pingData = ByteBuffer.allocate(0);
        webSocketClient.getScheduledExecutorService().scheduleAtFixedRate(() -> {
            try {
                session.getBasicRemote().sendPing(pingData);
            } catch (Exception e) {
                LOG.error("Error sending ping", e);
            }
        }, 30, 60, TimeUnit.SECONDS);
        closed = false;
    }
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:71,代码来源:WebSocketClient.java


示例3: TyrusClient

import org.glassfish.tyrus.client.SslEngineConfigurator; //导入依赖的package包/类
public TyrusClient(ExpandedConnectionParams connectionParams) throws URISyntaxException {

        ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();

        if (connectionParams.hasSubprotocols())
            builder.preferredSubprotocols(Arrays.asList(connectionParams.subprotocols.split(",")));
        cec = builder.build();

        ClientManager client = ClientManager
                .createClient("org.glassfish.tyrus.container.jdk.client.JdkClientContainer");
        client.setDefaultMaxSessionIdleTimeout(-1);

        client.getProperties().put(ClientProperties.REDIRECT_ENABLED, Boolean.TRUE);
        if (LOGGER.isTraceEnabled())
            client.getProperties().put(ClientProperties.LOG_HTTP_UPGRADE, Boolean.TRUE);

        if (connectionParams.hasCredentials())
            client.getProperties().put(
                    ClientProperties.CREDENTIALS,
                    new Credentials(connectionParams.login, connectionParams.password == null ? ""
                            : connectionParams.password));

        Settings settings = SoapUI.getSettings();

        String keyStoreUrl = System.getProperty(SoapUISystemProperties.SOAPUI_SSL_KEYSTORE_LOCATION,
                settings.getString(SSLSettings.KEYSTORE, null));

        String pass = System.getProperty(SoapUISystemProperties.SOAPUI_SSL_KEYSTORE_PASSWORD,
                settings.getString(SSLSettings.KEYSTORE_PASSWORD, ""));

        if (!StringUtils.isNullOrEmpty(keyStoreUrl)) {
            SslContextConfigurator sslContextConfigurator = new SslContextConfigurator(true);
            sslContextConfigurator.setKeyStoreFile(keyStoreUrl);
            sslContextConfigurator.setKeyStorePassword(pass);
            sslContextConfigurator.setKeyStoreType("JKS");
            if (sslContextConfigurator.validateConfiguration()) {
                SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(sslContextConfigurator, true,
                        false, false);
                client.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
            } else
                LOGGER.warn("error validating keystore configuration");
        }

        this.client = client;

        uri = new URI(connectionParams.getNormalizedServerUri());
    }
 
开发者ID:hschott,项目名称:ready-websocket-plugin,代码行数:48,代码来源:TyrusClient.java



注:本文中的org.glassfish.tyrus.client.SslEngineConfigurator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AdapterViewCompat类代码示例发布时间:2022-05-22
下一篇:
Java OnErrorFailedException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap