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


Java ClientProperties类代码示例

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


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

示例1: connect

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
public synchronized void connect(String server) {
    /**
     * Only connect once, which is intended to stay connected forever. If
     * manually disconnecting/connecting again should be a thing, some stuff
     * may have to be changed.
     */
    if (connecting) {
        return;
    }
    connecting = true;
    try {
        LOGGER.info("[PubSub] Connecting to "+server);
        ClientManager clientManager = ClientManager.createClient();
        clientManager.getProperties().put(ClientProperties.RECONNECT_HANDLER, new Reconnect());
        clientManager.asyncConnectToServer(this, new URI(server));
    } catch (Exception ex) {
        LOGGER.warning("[PubSub] Error connecting "+ex);
    }
}
 
开发者ID:chatty,项目名称:chatty,代码行数:20,代码来源:Client.java

示例2: prepareConnection

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的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

示例3: testCreateWebSoketClientWithProxy

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
@Test
public void testCreateWebSoketClientWithProxy() throws Exception {
    SlackWebsocketConnection slack = new SlackWebsocketConnection("token", "proxy", 8080);

    SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
    PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
    PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);

    ClientManager clientManager = PowerMockito.mock(ClientManager.class);
    PowerMockito.mockStatic(ClientManager.class);
    PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);
    Map<String, Object> properties = Mockito.mock(Map.class);
    PowerMockito.when(clientManager.getProperties()).thenReturn(properties);

    boolean connect = slack.connect();
    assertThat(connect, is(true));

    Mockito.verify(clientManager.getProperties()).put(Mockito.eq(ClientProperties.PROXY_URI), Mockito.anyString());
    PowerMockito.verifyStatic();
    ClientManager.createClient();
}
 
开发者ID:mockupcode,项目名称:slack-rtm-api,代码行数:22,代码来源:SlackWebsocketConnectionTest.java

示例4: run

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
@Override
public void run() {
    ClientManager client = ClientManager.createClient();
    try {
        URI uri = new URI(ApiAware.withUrl(apiProvider.getBaseUri()).getWebSocketUrl("mail"));
        client.getProperties().put(ClientProperties.RECONNECT_HANDLER, new ReconnectHandler());
        client.connectToServer(
                new MailClientEndpoint(),
                ClientEndpointConfig.Builder.create().build(),
                uri
        );
        countDownLatch.await();
        client.shutdown();
    } catch (Exception e) {
        logger.warn(String.format(
                "Failed to connect to mail endpoint. Mail functionality is disabled. Error is: %s",
                e.getMessage()
        ));
    }
}
 
开发者ID:meridor,项目名称:perspective-backend,代码行数:21,代码来源:MailRepositoryImpl.java

示例5: setUp

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
@Before
    public void setUp() throws Exception {

        this.client = HttpClients.custom()
                .setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(3, 2000))
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(10000)
                        .setConnectTimeout(10000)
                        .setConnectionRequestTimeout(10000)
                        .build()).build();
        this.om = new ObjectMapper();
        this.wsClient = ClientManager.createClient();
        wsClient.getProperties().put(ClientProperties.HANDSHAKE_TIMEOUT, 10000);        
            if (System.getProperty(TRAVIS_ENV) != null) {
                System.out.println("waiting for Travis machine");
                waitUrlAvailable(String.format("http://%s:%d/api?name=foo", LOCALHOST, PORT));
//                Thread.sleep(1); // Ugly sleep to debug travis            
            }
    }
 
开发者ID:LivePersonInc,项目名称:dropwizard-websockets,代码行数:20,代码来源:DropWizardWebsocketsTest.java

示例6: getWebSocketContainer

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
@Override
public WebSocketContainer getWebSocketContainer()
{
    ClientManager clientManager = ClientManager.createClient();
    if (proxyAddress != null)
    {
        clientManager.getProperties().put(ClientProperties.PROXY_URI, "http://" + proxyAddress + ":" + proxyPort);
    }
    return clientManager;
}
 
开发者ID:riversun,项目名称:slacklet,代码行数:11,代码来源:DefaultWebSocketContainerProvider.java

示例7: openConnection

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
/**
 * Open websocket connection
 *
 * @throws Exception connect to server
 */
public void openConnection() throws Exception {
    if (session != null && session.isOpen()) {
        LOGGER.warn("Profile already connected!");
    } else {
        LOGGER.info("Connecting to {} ...", endpointURI.getHost());
        if (endpointURI.getScheme().equals("wss") && !sslValidate) {
            client.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
        }
        session = client.connectToServer(this, config, endpointURI);
    }
}
 
开发者ID:alexandr85,项目名称:javafx-ws-client,代码行数:17,代码来源:WsClient.java

示例8: SecureWebsocketClientEndpoint

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
/**
 * Instantiates a new secure websocket client endpoint.
 *
 * @param wsUrl the ws url (e.g., wss://wot.arces.unibo.it:9443/secure/sparql)
 */
public SecureWebsocketClientEndpoint(String wsUrl) {
	super(wsUrl);
		
	client.getProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sm.getWssConfigurator());
}
 
开发者ID:vaimee,项目名称:sepatools,代码行数:11,代码来源:SecureWebsocketClientEndpoint.java

示例9: open

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的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

示例10: connectImpl

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的package包/类
private void connectImpl() throws IOException, ClientProtocolException, ConnectException
{
    LOGGER.info("connecting to slack");
    lastPingSent = 0;
    lastPingAck = 0;
    HttpClient httpClient = getHttpClient();
    HttpGet request = new HttpGet(SLACK_HTTPS_AUTH_URL + authToken);
    HttpResponse response;
    response = httpClient.execute(request);
    LOGGER.debug(response.getStatusLine().toString());
    String jsonResponse = CharStreams.toString(new InputStreamReader(response.getEntity().getContent()));
    SlackJSONSessionStatusParser sessionParser = new SlackJSONSessionStatusParser(jsonResponse);
    try
    {
        sessionParser.parse();
    }
    catch (ParseException e1)
    {
        LOGGER.error(e1.toString());
    }
    if (sessionParser.getError() != null)
    {
        LOGGER.error("Error during authentication : " + sessionParser.getError());
        throw new ConnectException(sessionParser.getError());
    }
    users = sessionParser.getUsers();
    channels = sessionParser.getChannels();
    sessionPersona = sessionParser.getSessionPersona();
    team = sessionParser.getTeam();
    LOGGER.info("Team " + team.getId() + " : " + team.getName());
    LOGGER.info("Self " + sessionPersona.getId() + " : " + sessionPersona.getUserName());
    LOGGER.info(users.size() + " users found on this session");
    LOGGER.info(channels.size() + " channels found on this session");
    String wssurl = sessionParser.getWebSocketURL();

    LOGGER.debug("retrieved websocket URL : " + wssurl);
    ClientManager client = ClientManager.createClient();
    if (proxyAddress != null)
    {
        client.getProperties().put(ClientProperties.PROXY_URI, "http://" + proxyAddress + ":" + proxyPort);
    }
    final MessageHandler handler = this;
    LOGGER.debug("initiating connection to websocket");
    try
    {
        websocketSession = client.connectToServer(new Endpoint()
        {
            @Override
            public void onOpen(Session session, EndpointConfig config)
            {
                session.addMessageHandler(handler);
            }

        }, URI.create(wssurl));
    }
    catch (DeploymentException e)
    {
        LOGGER.error(e.toString());
    }
    if (websocketSession != null)
    {
        SlackConnectedImpl slackConnectedImpl = new SlackConnectedImpl(sessionPersona);
        dispatcher.dispatch(slackConnectedImpl);
        LOGGER.debug("websocket connection established");
        LOGGER.info("slack session ready");
    }
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:68,代码来源:SlackWebSocketSessionImpl.java

示例11: TyrusClient

import org.glassfish.tyrus.client.ClientProperties; //导入依赖的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.ClientProperties类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。