Search in sources :

Example 11 with HttpDelete

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);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpClientException(org.apache.olingo.client.api.http.HttpClientException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) HttpPatch(org.apache.olingo.client.core.http.HttpPatch) URISyntaxException(java.net.URISyntaxException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ODataClientErrorException(org.apache.olingo.client.api.communication.ODataClientErrorException) HttpClientException(org.apache.olingo.client.api.http.HttpClientException)

Example 12 with HttpDelete

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) URL(java.net.URL)

Example 13 with 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);
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 14 with HttpDelete

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);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 15 with HttpDelete

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());
        }
    });
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpEntity(org.apache.http.HttpEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)108 HttpResponse (org.apache.http.HttpResponse)25 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)22 Test (org.junit.Test)21 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpPut (org.apache.http.client.methods.HttpPut)16 HttpPost (org.apache.http.client.methods.HttpPost)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)14 IOException (java.io.IOException)12 Deployment (org.activiti.engine.test.Deployment)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 Task (org.activiti.engine.task.Task)9 StringEntity (org.apache.http.entity.StringEntity)9 URI (java.net.URI)7 RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)7 URISyntaxException (java.net.URISyntaxException)6 Header (org.apache.http.Header)6 HttpEntity (org.apache.http.HttpEntity)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 User (org.activiti.engine.identity.User)5