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.qwazr.graph.test.FullTest.java

@Test
public void test999DeleteDatabase() throws IOException {
    HttpResponse response = Request.Delete(BASE_URL + '/' + TEST_BASE).connectTimeout(60000)
            .socketTimeout(60000).execute().returnResponse();
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());

}

From source file:org.exist.xquery.RestBinariesTest.java

@Override
protected void removeCollection(final XmldbURI collectionUri) throws Exception {
    final HttpResponse response = executor.execute(Request.Delete(getRestUrl() + collectionUri.toString()))
            .returnResponse();/*from w  ww.  j ava2s.  c  o m*/

    if (response.getStatusLine().getStatusCode() != SC_OK) {
        throw new Exception("Unable to delete collection: " + collectionUri);
    }
}

From source file:com.softinstigate.restheart.integrationtest.SecurityIT.java

@Test
public void testDeleteUnauthenticated() throws Exception {
    // *** DELETE root
    Response resp = unauthExecutor.execute(Request.Delete(rootUri));
    check("check delete root unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** DELETE db
    resp = unauthExecutor.execute(Request.Delete(dbUri));
    check("check delete db unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** DELETE coll1
    resp = unauthExecutor.execute(Request.Delete(collection1Uri));
    check("check delete coll1 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** DELETE doc1
    resp = unauthExecutor.execute(Request.Delete(document1Uri));
    check("check delete doc1 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** DELETE coll2
    resp = unauthExecutor.execute(Request.Delete(collection2Uri));
    check("check delete coll2 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** DELETE doc2
    resp = unauthExecutor.execute(Request.Delete(document2Uri));
    check("check delete doc2 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);
}

From source file:org.restheart.test.integration.SecurityAuthTokenIT.java

@Test
public void testAuthTokenInvalidation() throws Exception {
    Response resp = adminExecutor.execute(Request.Get(rootUri));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);/*  w  w w.j  av  a 2s.  c o  m*/

    StatusLine statusLine = httpResp.getStatusLine();
    assertNotNull(statusLine);

    assertEquals("check authorized", HttpStatus.SC_OK, statusLine.getStatusCode());

    Header[] _authToken = httpResp.getHeaders(AUTH_TOKEN_HEADER.toString());
    Header[] _authTokenValid = httpResp.getHeaders(AUTH_TOKEN_VALID_HEADER.toString());
    Header[] _authTokenLocation = httpResp.getHeaders(AUTH_TOKEN_LOCATION_HEADER.toString());

    assertNotNull("check not null auth token header", _authToken);
    assertNotNull("check not null auth token valid header", _authTokenValid);
    assertNotNull("check not null auth token location header", _authTokenLocation);

    assertTrue("check not empty array auth token header array ", _authToken.length == 1);
    assertTrue("check not empty array auth token valid header", _authTokenValid.length == 1);
    assertTrue("check not empty array auth token location header", _authTokenLocation.length == 1);

    String locationURI = _authTokenLocation[0].getValue();

    URI authTokenResourceUri = rootUri.resolve(locationURI);

    Response resp2 = unauthExecutor.auth(new Credentials() {
        @Override
        public Principal getUserPrincipal() {
            return new BasicUserPrincipal("admin");
        }

        @Override
        public String getPassword() {
            return _authToken[0].getValue();
        }
    }).execute(Request.Delete(authTokenResourceUri));

    HttpResponse httpResp2 = resp2.returnResponse();
    assertNotNull(httpResp2);

    StatusLine statusLine2 = httpResp2.getStatusLine();
    assertNotNull(statusLine2);

    assertEquals("check auth token resource URI", HttpStatus.SC_NO_CONTENT, statusLine2.getStatusCode());

    Response resp3 = unauthExecutor.auth(new Credentials() {
        @Override
        public Principal getUserPrincipal() {
            return new BasicUserPrincipal("admin");
        }

        @Override
        public String getPassword() {
            return _authToken[0].getValue();
        }
    }).execute(Request.Get(rootUri));

    HttpResponse httpResp3 = resp3.returnResponse();
    assertNotNull(httpResp3);

    StatusLine statusLine3 = httpResp3.getStatusLine();
    assertNotNull(statusLine3);

    assertEquals("check auth token resource URI", HttpStatus.SC_UNAUTHORIZED, statusLine3.getStatusCode());
}

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

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

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

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

@Override
public Response deleteAnalyzer(String schema_name, String index_name, String analyzer_name) {
    try {/*from   w w w . j av a 2 s  .  com*/
        UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/analyzers/",
                analyzer_name);
        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:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java

/**
 * @see eu.esdihumboldt.hale.io.geoserver.rest.ResourceManager#delete(java.util.Map)
 *///www.  j  av  a 2s.c  o  m
@Override
public void delete(Map<String, String> parameters) {
    checkResourceSet();

    try {
        URI requestUri = buildRequestUri(getResourceURL(), parameters);
        executor.execute(Request.Delete(requestUri)).handleResponse(new EmptyResponseHandler());
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}

From source file:org.eclipse.userstorage.internal.Session.java

public boolean deleteBlob(String applicationToken, String key, final Map<String, String> properties,
        ICredentialsProvider credentialsProvider) throws IOException, ConflictException {
    URI uri = StringUtil.newURI(service.getServiceURI(), "api/blob/" + applicationToken + "/" + key);

    boolean deleted = new RequestTemplate<Boolean>(uri) {
        @Override//from ww  w  . jav  a 2s .c  o m
        protected Request prepareRequest() throws IOException {
            Request request = configureRequest(Request.Delete(uri), uri);

            String eTag = properties.get(Blob.ETAG);
            if (!StringUtil.isEmpty(eTag)) {
                request.setHeader(IF_MATCH, "\"" + eTag + "\"");
            }

            return request;
        }

        @Override
        protected Boolean handleResponse(HttpResponse response, HttpEntity responseEntity) throws IOException {
            int statusCode = getStatusCode("DELETE", uri, response, NO_CONTENT, CONFLICT, NOT_FOUND);
            String eTag = getETag(response);

            if (statusCode == CONFLICT) {
                StatusLine statusLine = response.getStatusLine();
                throw new ConflictException("DELETE", uri, getProtocolVersion(statusLine),
                        statusLine.getReasonPhrase(), eTag);
            }

            properties.put(Blob.ETAG, "<deleted_etag>");
            return statusCode == NO_CONTENT;
        }
    }.send(credentialsProvider);

    return deleted;
}

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

@Override
public Response deleteIndex(String schema_name, String index_name) {
    try {/*from   w  w w .  jav  a2s . c om*/
        UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name);
        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:de.elomagic.maven.http.HTTPMojo.java

private Request createRequestMethod() throws Exception {
    switch (method) {
    case DELETE://from   w  w  w.j a  v  a  2s  .  c  o  m
        return Request.Delete(url.toURI());
    case GET:
        return Request.Get(url.toURI());
    case HEAD:
        return Request.Head(url.toURI());
    case POST:
        return Request.Post(url.toURI());
    case PUT:
        return Request.Put(url.toURI());
    }

    throw new Exception("Unsupported HTTP method \"" + method + "\".");
}