use of org.apache.http.impl.client.BasicResponseHandler in project ddf by codice.
the class LogoutMessageImpl method sendSamlLogoutRequest.
@Override
public String sendSamlLogoutRequest(@NotNull LogoutRequest request, @NotNull String targetUri) throws IOException, WSSecurityException {
Element requestElement = getElementFromSaml(request);
String requestMessage = DOM2Writer.nodeToString(requestElement);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost post = new HttpPost(targetUri);
post.addHeader("Cache-Control", "no-cache, no-store");
post.addHeader("Pragma", "no-cache");
post.addHeader("SOAPAction", SAML_SOAP_ACTION);
post.setEntity(new StringEntity(requestMessage, "utf-8"));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
return httpClient.execute(post, responseHandler);
}
}
use of org.apache.http.impl.client.BasicResponseHandler in project libresonic by Libresonic.
the class VersionService method readLatestVersion.
/**
* Resolves the latest available Libresonic version by screen-scraping a web page.
*
* @throws IOException If an I/O error occurs.
*/
private void readLatestVersion() throws IOException {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build();
HttpGet method = new HttpGet(VERSION_URL + "?v=" + getLocalVersion());
method.setConfig(requestConfig);
String content;
try (CloseableHttpClient client = HttpClients.createDefault()) {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
content = client.execute(method, responseHandler);
}
Pattern finalPattern = Pattern.compile("LIBRESONIC_FULL_VERSION_BEGIN(.*)LIBRESONIC_FULL_VERSION_END");
Pattern betaPattern = Pattern.compile("LIBRESONIC_BETA_VERSION_BEGIN(.*)LIBRESONIC_BETA_VERSION_END");
try (BufferedReader reader = new BufferedReader(new StringReader(content))) {
String line = reader.readLine();
while (line != null) {
Matcher finalMatcher = finalPattern.matcher(line);
if (finalMatcher.find()) {
latestFinalVersion = new Version(finalMatcher.group(1));
LOG.info("Resolved latest Libresonic final version to: " + latestFinalVersion);
}
Matcher betaMatcher = betaPattern.matcher(line);
if (betaMatcher.find()) {
latestBetaVersion = new Version(betaMatcher.group(1));
LOG.info("Resolved latest Libresonic beta version to: " + latestBetaVersion);
}
line = reader.readLine();
}
}
}
use of org.apache.http.impl.client.BasicResponseHandler in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method getAccessToken.
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
if (forceRefresh) {
wxCpConfigStorage.expireAccessToken();
}
if (wxCpConfigStorage.isAccessTokenExpired()) {
synchronized (globalAccessTokenRefreshLock) {
if (wxCpConfigStorage.isAccessTokenExpired()) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" + "&corpid=" + wxCpConfigStorage.getCorpId() + "&corpsecret=" + wxCpConfigStorage.getCorpSecret();
try {
HttpGet httpGet = new HttpGet(url);
if (httpProxy != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
httpGet.setConfig(config);
}
CloseableHttpClient httpclient = getHttpclient();
String resultContent = null;
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
resultContent = new BasicResponseHandler().handleResponse(response);
}
WxError error = WxError.fromJson(resultContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
wxCpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
return wxCpConfigStorage.getAccessToken();
}
use of org.apache.http.impl.client.BasicResponseHandler in project cw-andtutorials by commonsguy.
the class Patchy method updateStatus.
private void updateStatus() {
try {
String s = status.getText().toString();
HttpPost post = new HttpPost("https://identi.ca/api/statuses/update.json");
post.addHeader("Authorization", "Basic " + getCredentials());
List<NameValuePair> form = new ArrayList<NameValuePair>();
form.add(new BasicNameValuePair("status", s));
post.setEntity(new UrlEncodedFormEntity(form, HTTP.UTF_8));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = client.execute(post, responseHandler);
JSONObject response = new JSONObject(responseBody);
} catch (Throwable t) {
Log.e("Patchy", "Exception in updateStatus()", t);
goBlooey(t);
}
}
use of org.apache.http.impl.client.BasicResponseHandler in project musiccabinet by hakko.
the class AbstractWSGetClient method invokeSingleCall.
/*
* Make a single call to a Last.fm web service, and return a packaged result.
*/
private WSResponse invokeSingleCall(List<NameValuePair> params) throws ApplicationException {
if (throttleService != null) {
throttleService.awaitAllowance();
}
WSResponse wsResponse;
HttpClient httpClient = getHttpClient();
try {
HttpGet httpGet = new HttpGet(getURI(params));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpClient.execute(httpGet, responseHandler);
wsResponse = new WSResponse(responseBody);
} catch (HttpResponseException e) {
wsResponse = new WSResponse(isHttpRecoverable(e.getStatusCode()), e.getStatusCode(), e.getMessage());
} catch (IOException e) {
LOG.warn("Could not fetch data from Last.fm!", e);
wsResponse = new WSResponse(true, -1, "Call failed due to " + e.getMessage());
}
return wsResponse;
}
Aggregations