Example usage for org.apache.http.client.fluent Request Delete

List of usage examples for org.apache.http.client.fluent Request Delete

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Request Delete.

Prototype

public static Request Delete(final String uri) 

Source Link

Usage

From source file:com.helger.peppol.bdxrclient.BDXRClient.java

/**
 * Deletes a service meta data object given by its service group id and its
 * document type.//from w w  w . ja  v a  2  s.co  m
 *
 * @param aServiceGroupID
 *        The service group id of the service meta data to delete.
 * @param aDocumentTypeID
 *        The document type of the service meta data to delete.
 * @param aCredentials
 *        The user name and password to use as aCredentials.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         The user name or password was not correct.
 * @throws SMPClientNotFoundException
 *         The service meta data object did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 */
public void deleteServiceRegistration(@Nonnull final IParticipantIdentifier aServiceGroupID,
        @Nonnull final IDocumentTypeIdentifier aDocumentTypeID,
        @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    ValueEnforcer.notNull(aCredentials, "Credentials");

    try {
        final Request aRequest = Request
                .Delete(getSMPHostURI() + IdentifierHelper.getIdentifierURIPercentEncoded(aServiceGroupID)
                        + "/services/" + IdentifierHelper.getIdentifierURIPercentEncoded(aDocumentTypeID))
                .addHeader(CHTTPHeader.AUTHORIZATION, aCredentials.getRequestValue());
        executeRequest(aRequest).handleResponse(new SMPHttpResponseHandlerWriteOperations());
    } catch (final Exception ex) {
        throw getConvertedException(ex);
    }
}

From source file:org.kie.smoke.wb.util.RestUtil.java

public static <T, G> T delete(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class... responseTypes) {
    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Delete(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:off

    Response resp = null;/*w w w . j av  a2 s.co m*/
    try {
        logOp("DELETE", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        logAndFail("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        logAndFail("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.remote.tests.base.RestUtil.java

public static <T, G> T delete(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user,
        String password, Class... responseTypes) {
    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);

    // @formatter:off
    Request request = Request.Delete(uriStr).addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:off

    Response resp = null;//from   w w w.j  av  a2  s.  c o m
    try {
        logOp("DELETE", uriStr);
        resp = request.execute();
    } catch (Exception e) {
        failAndLog("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        failAndLog("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:com.qwazr.search.index.IndexSingleClient.java

@Override
public Response deleteAll(String schema_name, String index_name) {
    try {//from w  w  w .  j av  a  2 s .c o m
        UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/docs");
        Request request = Request.Delete(uriBuilder.build());
        HttpResponse response = execute(request, null, null);
        HttpUtils.checkStatusCodes(response, 200);
        return Response.status(response.getStatusLine().getStatusCode()).build();
    } catch (HttpResponseEntityException e) {
        throw e.getWebApplicationException();
    } catch (IOException e) {
        throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.talend.components.datastewardship.connection.TdsConnection.java

/**
 * Executes Http Delete request/*w  w w.  ja  va  2s.c om*/
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param parameters http query parameters
 * @return http status code
 * @throws IOException
 */
public int delete(String resource, Map<String, Object> parameters) throws IOException {
    try {
        URIBuilder builder = new URIBuilder(hostPort + resource);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue().toString());
        }
        URI uri = builder.build();
        Request delete = Request.Delete(uri).addHeader(authorization);
        return executor.execute(delete).returnResponse().getStatusLine().getStatusCode();
    } catch (URISyntaxException e) {
        LOG.debug("Wrong URI. {}", e.getMessage()); //$NON-NLS-1$
        throw new IOException("Wrong URI", e); //$NON-NLS-1$
    }
}

From source file:org.talend.components.jira.connection.Rest.java

/**
 * Executes Http Delete request/*  ww  w.  j  a  v a 2 s  .com*/
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param parameters http query parameters
 * @return http status code
 * @throws IOException
 */
public int delete(String resource, Map<String, Object> parameters) throws IOException {
    try {
        URIBuilder builder = new URIBuilder(hostPort + resource);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue().toString());
        }
        URI uri = builder.build();
        Request delete = Request.Delete(uri);
        for (Header header : headers) {
            delete.addHeader(header);
        }
        executor.clearCookies();
        return executor.execute(delete).returnResponse().getStatusLine().getStatusCode();
    } catch (URISyntaxException e) {
        LOG.debug("Wrong URI. {}", e.getMessage());
        throw new IOException("Wrong URI", e);
    }
}