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"); } }