public SlackInfo tokenAuthen(String token, String proxyUrl, int proxyPort) {
HttpClient client = new HttpClient();
if (proxyUrl != null) {
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setProxyHost(new ProxyHost(proxyUrl, proxyPort));
client.setHostConfiguration(hostConfiguration);
}
GetMethod getMethod = new GetMethod(SLACK_RTM_AUTHEN_URL + token);
SlackInfo slackInfo = new SlackInfo();
try {
int httpStatus = client.executeMethod(getMethod);
if (httpStatus == HttpStatus.SC_OK) {
ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper.readValue(getMethod.getResponseBodyAsStream(), SlackInfo.class);
} else {
slackInfo.setError("http_status_" + httpStatus);
return slackInfo;
}
} catch (IOException ex) {
slackInfo.setError("exception " + ex.getMessage());
Logger.getLogger(SlackAuthen.class.getName()).log(Level.SEVERE, null, ex);
} finally {
getMethod.releaseConnection();
}
return slackInfo;
}
SlackAuthen.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:slack-rtm-api
作者:
评论列表
文章目录