Example usage for org.apache.http.entity ByteArrayEntity ByteArrayEntity

List of usage examples for org.apache.http.entity ByteArrayEntity ByteArrayEntity

Introduction

In this page you can find the example usage for org.apache.http.entity ByteArrayEntity ByteArrayEntity.

Prototype

public ByteArrayEntity(byte[] bArr) 

Source Link

Usage

From source file:io.restassured.internal.http.GZIPDecompressingEntityTest.java

@Test
public void returns_gzipped_decompressed_content_when_content_length_is_minus_one() throws IOException {
    // Given//w w w . j  a  va  2s . com
    String json = "{\"userId\":\"e047379\",\"ldapId\":\"0dfdf5a0-483c-45d7-8b24-8dd1299586c8\",\"firstName\":\"Ninju\",\"lastName\":\"BohraB\",\"cookieNotice\":true}";
    byte[] compressed = gzipCompress(json);

    // When
    GZIPDecompressingEntity gzipDecompressingEntity = new GZIPDecompressingEntity(
            new ByteArrayEntity(compressed) {
                @Override
                public long getContentLength() {
                    return -1;
                }
            });

    // Then
    String string = IOUtils.toString(gzipDecompressingEntity.getContent());
    assertThat(string).isEqualTo(json);
}

From source file:de.micromata.genome.tpsb.httpmockup.HttpClientRequestAcceptor.java

private HttpPost buildMethod(MockHttpServletRequest request) {
    HttpPost ret;//from  w  w w  . j  av  a2  s .co  m
    if (StringUtils.equals(request.getMethod(), "POST") == true) {
        HttpPost pm = new HttpPost(baseUrl + request.getPathInfo());
        pm.setEntity(new ByteArrayEntity(request.getRequestData()));
        ret = pm;
    } else {
        throw new UnsupportedOperationException("Currently only POST methods are supported");
    }
    return ret;
}

From source file:com.jaeksoft.searchlib.remote.UriWriteObject.java

public UriWriteObject(URI uri, Externalizable object) throws IOException {
    HttpPut httpPut = new HttpPut(uri.toASCIIString());
    httpPut.setConfig(requestConfig);//  ww  w.j a  v  a 2  s.com
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    swo = new StreamWriteObject(baos);
    swo.write(object);
    swo.close(true);
    swo = null;
    sro = null;
    httpPut.setEntity(new ByteArrayEntity(baos.toByteArray()));
    execute(httpPut);
}

From source file:org.osmsurround.ae.osmrequest.OsmDeleteRequest.java

@Override
protected HttpRequestBase createRequest(OsmBasicType amenity, int changesetId) throws Exception {
    ByteArrayOutputStream baos = marshallIntoBaos(amenity, changesetId);

    HttpEntityEnclosingRequestBase request = new HttpDeleteWithBody(
            osmApiBaseUrl + "/api/0.6/" + OsmBasicTypeMap.get(amenity.getClass()) + "/" + amenity.getId());
    request.setEntity(new ByteArrayEntity(baos.toByteArray()));

    return request;
}

From source file:org.osmsurround.ae.osmrequest.OsmInsertRequest.java

@Override
protected HttpRequestBase createRequest(OsmBasicType amenity, int changesetId) throws Exception {
    ByteArrayOutputStream baos = marshallIntoBaos(amenity, changesetId);

    HttpEntityEnclosingRequestBase request = new HttpPut(
            osmApiBaseUrl + "/api/0.6/" + OsmBasicTypeMap.get(amenity.getClass()) + "/create");

    request.setEntity(new ByteArrayEntity(baos.toByteArray()));
    return request;
}

From source file:org.osmsurround.ae.osmrequest.OsmUpdateRequest.java

@Override
protected HttpRequestBase createRequest(OsmBasicType amenity, int changesetId) throws Exception {
    ByteArrayOutputStream baos = marshallIntoBaos(amenity, changesetId);
    HttpEntityEnclosingRequestBase request = new HttpPut(
            osmApiBaseUrl + "/api/0.6/" + OsmBasicTypeMap.get(amenity.getClass()) + "/" + amenity.getId());
    request.setEntity(new ByteArrayEntity(baos.toByteArray()));
    return request;
}

From source file:CB_Core.GCVote.GCVote.java

public static ArrayList<RatingData> GetRating(String User, String password, ArrayList<String> Waypoints) {
    ArrayList<RatingData> result = new ArrayList<RatingData>();

    String data = "userName=" + User + "&password=" + password + "&waypoints=";
    for (int i = 0; i < Waypoints.size(); i++) {
        data += Waypoints.get(i);//from   w  w  w .j a v a 2 s .c o m
        if (i < (Waypoints.size() - 1))
            data += ",";
    }

    try {
        HttpPost httppost = new HttpPost("http://gcvote.de/getVotes.php");

        httppost.setEntity(new ByteArrayEntity(data.getBytes("UTF8")));

        // Log.info(log, "GCVOTE-Post" + data);

        // Execute HTTP Post Request
        String responseString = Execute(httppost);

        // Log.info(log, "GCVOTE-Response" + responseString);

        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(responseString));

        Document doc = db.parse(is);

        NodeList nodelist = doc.getElementsByTagName("vote");

        for (Integer i = 0; i < nodelist.getLength(); i++) {
            Node node = nodelist.item(i);

            RatingData ratingData = new RatingData();
            ratingData.Rating = Float.valueOf(node.getAttributes().getNamedItem("voteAvg").getNodeValue());
            String userVote = node.getAttributes().getNamedItem("voteUser").getNodeValue();
            ratingData.Vote = (userVote == "") ? 0 : Float.valueOf(userVote);
            ratingData.Waypoint = node.getAttributes().getNamedItem("waypoint").getNodeValue();
            result.add(ratingData);

        }

    } catch (Exception e) {
        String Ex = "";
        if (e != null) {
            if (e != null && e.getMessage() != null)
                Ex = "Ex = [" + e.getMessage() + "]";
            else if (e != null && e.getLocalizedMessage() != null)
                Ex = "Ex = [" + e.getLocalizedMessage() + "]";
            else
                Ex = "Ex = [" + e.toString() + "]";
        }
        Log.err(log, "GcVote-Error" + Ex);
        return null;
    }
    return result;

}

From source file:com.mashape.unirest.android.request.body.RawBody.java

public HttpEntity getEntity() {
    return new ByteArrayEntity(body);
}

From source file:org.n52.shetland.util.HTTP.java

public static byte[] post(URI uri, byte[] bytes) throws IOException {
    HttpPost request = new HttpPost(uri);
    request.setEntity(new ByteArrayEntity(bytes));
    return execute(request);
}

From source file:com.github.restdriver.serverdriver.http.ByteArrayRequestBody.java

@Override
public void applyTo(ServerDriverHttpUriRequest request) {

    HttpUriRequest internalRequest = request.getHttpUriRequest();

    if (!(internalRequest instanceof HttpEntityEnclosingRequest)) {
        return;/*from  w w  w.  j  a v  a2  s  .  co m*/
    }

    HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) internalRequest;

    entityRequest.setHeader("Content-type", contentType);

    ByteArrayEntity entity = new ByteArrayEntity(content);
    entity.setContentType(contentType);
    entityRequest.setEntity(entity);

}