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

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

Introduction

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

Prototype

public static Request Put(final String uri) 

Source Link

Usage

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

@Test
public void testPostCollectionString() throws Exception {
    try {//from ww  w.j ava2 s . c  o  m
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // *** PUT tmpcoll
        resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put coll1", resp, HttpStatus.SC_CREATED);

        URI collectionTmpUriInt = buildURI("/" + dbTmpName + "/" + collectionTmpName,
                new NameValuePair[] { new BasicNameValuePair(DOC_ID_TYPE_KEY, DOC_ID_TYPE.STRING.name()) });

        // *** POST tmpcoll
        resp = adminExecutor.execute(Request.Post(collectionTmpUriInt)
                .bodyString("{_id:{'$oid':'54c965cbc2e64568e235b711'}, a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        HttpResponse httpResp = check("check post coll1 again", resp, HttpStatus.SC_CREATED);

        Header[] headers = httpResp.getHeaders(Headers.LOCATION_STRING);

        assertNotNull("check loocation header", headers);
        assertTrue("check loocation header", headers.length > 0);

        Header locationH = headers[0];
        String location = locationH.getValue();

        //assertTrue("check location header value", location.endsWith("/54c965cbc2e64568e235b711?id_type=STRING"));
        URI createdDocUri = URI.create(location);

        resp = adminExecutor.execute(Request.Get(createdDocUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());
        assertTrue("check created doc content",
                content.get("_id").asObject().get("$oid").asString().equals("54c965cbc2e64568e235b711"));
        assertNotNull("check created doc content", content.get("_etag"));
        assertNotNull("check created doc content", content.get("a"));
        assertTrue("check created doc content", content.get("a").asInt() == 1);

        // *** filter - case 1 - with string id should not find it
        URI collectionTmpUriSearch = buildURI("/" + dbTmpName + "/" + collectionTmpName,
                new NameValuePair[] { new BasicNameValuePair("filter", "{'_id':'54c965cbc2e64568e235b711'}") });

        resp = adminExecutor.execute(Request.Get(collectionTmpUriSearch).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

        content = JsonObject.readFrom(resp.returnContent().asString());
        assertTrue("check created doc content", content.get("_returned").asInt() == 0);

        // *** filter - case 1 - with oid id should find it
        collectionTmpUriSearch = buildURI("/" + dbTmpName + "/" + collectionTmpName, new NameValuePair[] {
                new BasicNameValuePair("filter", "{'_id':{'$oid':'54c965cbc2e64568e235b711'}}") });

        resp = adminExecutor.execute(Request.Get(collectionTmpUriSearch).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

        content = JsonObject.readFrom(resp.returnContent().asString());
        assertTrue("check created doc content", content.get("_returned").asInt() == 1);

    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

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

@Test
public void testPutDataDotNotation() throws Exception {
    Response resp;//from  w w w.  j a v  a  2  s .  com

    // *** test post valid data with dot notation
    final String VALID_USER_DN = getResourceFile("data/jsonpath-testuser-dotnot.json");

    resp = adminExecutor.execute(Request.Put(userURI).bodyString(VALID_USER_DN, halCT)
            .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));

    check("check post valid data with dot notation", resp, HttpStatus.SC_CREATED);
}

From source file:com.qwazr.database.TableSingleClient.java

@Override
public Map<String, Object> upsertRow(String table_name, String row_id, Map<String, Object> row) {
    UBuilder uriBuilder = new UBuilder("/table/", table_name, "/row/", row_id);
    Request request = Request.Put(uriBuilder.build());
    return commonServiceRequest(request, row, null, MapStringObjectTypeRef, 200);
}

From source file:org.exist.security.RestApiSecurityTest.java

@Override
protected void createXmlResource(final String resourceUri, final String content, final String uid,
        final String pwd) throws ApiException {
    final Executor exec = getExecutor(uid, pwd);
    try {//from w w w. jav a  2  s .c  o m
        final HttpResponse resp = exec.execute(Request.Put(REST_URI + resourceUri)
                .addHeader("Content-Type", "application/xml").bodyByteArray(content.getBytes()))
                .returnResponse();

        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
            throw new ApiException("Could not store XML resource to uri: " + resourceUri + ". "
                    + getResponseBody(resp.getEntity()));
        }
    } catch (final IOException ioe) {
        throw new ApiException(ioe);
    }
}

From source file:org.vas.test.rest.RestImpl.java

protected Request httpPut(String uri) {
    Request request = Request.Put(uri);
    configureRequest(request);

    return request;
}

From source file:com.helger.peppol.smpclient.SMPClient.java

/**
 * Saves a service group. The meta data references should not be set and are
 * not used.//  www  . ja  v  a 2  s.c  o m
 *
 * @param aServiceGroup
 *        The service group to save.
 * @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
 *         A HTTP Not Found was received. This can happen if the service was
 *         not found.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 */
public void saveServiceGroup(@Nonnull final ServiceGroupType aServiceGroup,
        @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroup, "ServiceGroup");
    ValueEnforcer.notNull(aCredentials, "Credentials");

    try {
        final String sBody = new SMPMarshallerServiceGroupType().getAsXMLString(aServiceGroup);
        final Request aRequest = Request
                .Put(getSMPHostURI() + IdentifierHelper
                        .getIdentifierURIPercentEncoded(aServiceGroup.getParticipantIdentifier()))
                .addHeader(CHTTPHeader.AUTHORIZATION, aCredentials.getRequestValue())
                .bodyString(sBody, CONTENT_TYPE_TEXT_XML);
        executeRequest(aRequest).handleResponse(new SMPHttpResponseHandlerWriteOperations());
    } catch (final Exception ex) {
        throw getConvertedException(ex);
    }
}

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

/**
 * Saves a service group. The meta data references should not be set and are
 * not used.//w  w  w.  ja v  a2s .co  m
 *
 * @param aServiceGroup
 *        The service group to save.
 * @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
 *         A HTTP Not Found was received. This can happen if the service was
 *         not found.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 */
public void saveServiceGroup(@Nonnull final ServiceGroupType aServiceGroup,
        @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroup, "ServiceGroup");
    ValueEnforcer.notNull(aCredentials, "Credentials");

    try {
        final String sBody = new BDXRMarshallerServiceGroupType().getAsXMLString(aServiceGroup);
        final Request aRequest = Request
                .Put(getSMPHostURI() + IdentifierHelper
                        .getIdentifierURIPercentEncoded(aServiceGroup.getParticipantIdentifier()))
                .addHeader(CHTTPHeader.AUTHORIZATION, aCredentials.getRequestValue())
                .bodyString(sBody, CONTENT_TYPE_TEXT_XML);
        executeRequest(aRequest).handleResponse(new SMPHttpResponseHandlerWriteOperations());
    } catch (final Exception ex) {
        throw getConvertedException(ex);
    }
}

From source file:org.exist.security.RestApiSecurityTest.java

@Override
protected void createBinResource(final String resourceUri, final byte[] content, final String uid,
        final String pwd) throws ApiException {
    final Executor exec = getExecutor(uid, pwd);
    try {/*w w  w . j  a v  a2 s. c om*/
        final HttpResponse resp = exec
                .execute(Request.Put(REST_URI + resourceUri)
                        .addHeader("Content-Type", "application/octet-stream").bodyByteArray(content))
                .returnResponse();

        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
            throw new ApiException("Could not store Binary resource to uri: " + resourceUri + ". "
                    + getResponseBody(resp.getEntity()));
        }
    } catch (final IOException ioe) {
        throw new ApiException(ioe);
    }
}

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

@Override
protected void storeBinaryFile(final XmldbURI filePath, final byte[] content) throws Exception {
    final HttpResponse response = executor
            .execute(Request.Put(getRestUrl() + filePath.toString())
                    .setHeader("Content-Type", "application/octet-stream").bodyByteArray(content))
            .returnResponse();// w ww  .  java2 s . co  m

    if (response.getStatusLine().getStatusCode() != SC_CREATED) {
        throw new Exception("Unable to store binary file: " + filePath);
    }
}

From source file:com.adobe.acs.commons.http.impl.HttpClientFactoryImpl.java

@Override
public Request put(String partialUrl) {
    String url = baseUrl + partialUrl;
    return Request.Put(url);
}