use of org.apache.http.client.methods.HttpDelete in project tdi-studio-se by Talend.
the class DynamicsCRMClient method createAndExecuteRequest.
/**
* Created and executes a request
*
* @param uri the request URI
* @param httpEntity the entity to send.
* @param method HTTP method
*
* @return the response to the request.
* @throws ServiceUnavailableException
*/
protected HttpResponse createAndExecuteRequest(URI uri, HttpEntity httpEntity, HttpMethod method) throws ServiceUnavailableException {
boolean hasRetried = false;
while (true) {
try {
httpClient = (DefaultHttpClient) httpClientFactory.create(null, null);
HttpRequestBase request = null;
if (method == HttpMethod.POST) {
request = new HttpPost(uri);
} else if (method == HttpMethod.PATCH) {
request = new HttpPatch(uri);
} else if (method == HttpMethod.DELETE) {
request = new HttpDelete(uri);
} else {
throw new HttpClientException("Unsupported operation:" + method);
}
request.addHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
if (request instanceof HttpEntityEnclosingRequestBase) {
((HttpEntityEnclosingRequestBase) request).setEntity(httpEntity);
}
HttpResponse response = httpClient.execute(request);
if (isResponseSuccess(response.getStatusLine().getStatusCode())) {
request.releaseConnection();
EntityUtils.consume(response.getEntity());
return response;
} else {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && !hasRetried) {
refreshToken();
hasRetried = true;
continue;
}
HttpEntity entity = response.getEntity();
String message = null;
if (entity != null) {
message = odataClient.getDeserializer(ContentType.JSON).toError(entity.getContent()).getMessage();
} else {
message = response.getStatusLine().getReasonPhrase();
}
throw new HttpClientException(message);
}
} catch (Exception e) {
throw new HttpClientException(e);
}
}
}
use of org.apache.http.client.methods.HttpDelete in project selenium-tests by Wikia.
the class GraphApi method deleteTestUser.
private HttpResponse deleteTestUser(String userId) throws IOException, URISyntaxException {
URL url = new URL(getURLdeleteUser(userId));
CloseableHttpClient httpClient = HttpClientBuilder.create().disableAutomaticRetries().build();
HttpDelete httpDelete = getHttpDelete(url);
return httpClient.execute(httpDelete);
}
use of org.apache.http.client.methods.HttpDelete in project selenium-tests by Wikia.
the class Helios method deleteAllTokens.
public static void deleteAllTokens(User user) {
String heliosGetTokenURL = HeliosConfig.getUrl(HeliosConfig.HeliosController.USERS);
HttpDelete httpDelete = new HttpDelete(String.format("%s/%s/tokens", heliosGetTokenURL, user.getUserId()));
httpDelete.setHeader("THE-SCHWARTZ", Configuration.getCredentials().apiToken);
CloseableHttpResponse response = null;
try {
response = getDefaultClient().execute(httpDelete);
PageObjectLogging.log("DELETE HEADERS: ", response.toString(), true);
} catch (ClientProtocolException e) {
PageObjectLogging.log("CLIENT PROTOCOL EXCEPTION", ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(e);
} catch (IOException e) {
PageObjectLogging.log(IOEXCEPTION_COMMAND, IOEXCEPTION_ERROR_MESSAGE + ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(e);
}
}
use of org.apache.http.client.methods.HttpDelete in project ats-framework by Axway.
the class HttpClient method delete.
/**
* Invoke the endpoint URL using a HTTP DELETE.
*
* @return The response
* @throws HttpException
*/
@PublicAtsApi
public HttpResponse delete() throws HttpException {
HttpDelete method = new HttpDelete(constructURI());
log.info("We will DELETE from " + constructURI());
return execute(method);
}
use of org.apache.http.client.methods.HttpDelete in project intellij-community by JetBrains.
the class CCStepicConnector method deleteTask.
public static void deleteTask(@NotNull final Integer task) {
final HttpDelete request = new HttpDelete(EduStepicNames.STEPIC_API_URL + EduStepicNames.STEP_SOURCES + task);
ApplicationManager.getApplication().invokeLater(() -> {
try {
final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
if (client == null)
return;
final CloseableHttpResponse response = client.execute(request);
final HttpEntity responseEntity = response.getEntity();
final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
EntityUtils.consume(responseEntity);
final StatusLine line = response.getStatusLine();
if (line.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
LOG.error("Failed to delete task " + responseString);
}
} catch (IOException e) {
LOG.error(e.getMessage());
}
});
}
Aggregations