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

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

Introduction

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

Prototype

public void setContentType(Header header) 

Source Link

Usage

From source file:org.fcrepo.camel.FcrepoClientAuthTest.java

@Test
public void testAuthNoPassword() throws IOException, FcrepoOperationFailedException {
    final int status = 200;
    final URI uri = create(baseUrl);
    final ByteArrayEntity entity = new ByteArrayEntity(rdfXml.getBytes());

    testClient = new FcrepoClient("user", null, null, true);
    setField(testClient, "httpclient", mockHttpclient);
    entity.setContentType(RDF_XML);
    doSetupMockRequest(RDF_XML, entity, status);

    final FcrepoResponse response = testClient.get(uri, RDF_XML, null);

    assertEquals(response.getUrl(), uri);
    assertEquals(response.getStatusCode(), status);
    assertEquals(response.getContentType(), RDF_XML);
    assertEquals(response.getLocation(), null);
    assertEquals(IOUtils.toString(response.getBody()), rdfXml);
}

From source file:org.fcrepo.camel.FcrepoClientAuthTest.java

@Test
public void testAuthNoHost() throws IOException, FcrepoOperationFailedException {
    final int status = 200;
    final URI uri = create(baseUrl);
    final ByteArrayEntity entity = new ByteArrayEntity(rdfXml.getBytes());

    testClient = new FcrepoClient("user", "pass", null, true);
    setField(testClient, "httpclient", mockHttpclient);
    entity.setContentType(RDF_XML);
    doSetupMockRequest(RDF_XML, entity, status);

    final FcrepoResponse response = testClient.get(uri, RDF_XML, null);

    assertEquals(response.getUrl(), uri);
    assertEquals(response.getStatusCode(), status);
    assertEquals(response.getContentType(), RDF_XML);
    assertEquals(response.getLocation(), null);
    assertEquals(IOUtils.toString(response.getBody()), rdfXml);
}

From source file:org.fcrepo.camel.FcrepoClientAuthTest.java

@Test
public void testAuthWithHost() throws IOException, FcrepoOperationFailedException {
    final int status = 200;
    final URI uri = create(baseUrl);
    final ByteArrayEntity entity = new ByteArrayEntity(rdfXml.getBytes());

    testClient = new FcrepoClient("user", "pass", "localhost", true);
    setField(testClient, "httpclient", mockHttpclient);
    entity.setContentType(RDF_XML);
    doSetupMockRequest(RDF_XML, entity, status);

    final FcrepoResponse response = testClient.get(uri, RDF_XML, null);

    assertEquals(response.getUrl(), uri);
    assertEquals(response.getStatusCode(), status);
    assertEquals(response.getContentType(), RDF_XML);
    assertEquals(response.getLocation(), null);
    assertEquals(IOUtils.toString(response.getBody()), rdfXml);
}

From source file:com.favalike.http.GAEClientConnection.java

@Override
public void receiveResponseEntity(HttpResponse response) throws HttpException, IOException {
    if (this.response == null) {
        throw new IOException("receiveResponseEntity() called on closed connection");
    }/*  w ww. ja v a2  s.c  om*/

    ByteArrayEntity bae = new ByteArrayEntity(this.response.getContent());
    bae.setContentType(response.getFirstHeader("Content-Type"));
    response.setEntity(bae);

    response = null;
}

From source file:com.subgraph.vega.internal.http.proxy.ProxyRequestHandler.java

private HttpEntity copyEntity(HttpEntity entity) {
    try {//w w w  . ja  v  a2  s  .  c  om
        if (entity == null) {
            return null;
        }
        final ByteArrayEntity newEntity = new ByteArrayEntity(EntityUtils.toByteArray(entity));
        newEntity.setContentEncoding(entity.getContentEncoding());
        newEntity.setContentType(entity.getContentType());
        return newEntity;
    } catch (IOException e) {
        return null;
    }
}

From source file:org.fcrepo.camel.FcrepoClientErrorTest.java

@Test
public void testGet() throws IOException, FcrepoOperationFailedException {
    final int status = 100;
    final URI uri = create(baseUrl);
    final ByteArrayEntity entity = new ByteArrayEntity(rdfXml.getBytes());

    entity.setContentType(RDF_XML);
    doSetupMockRequest(RDF_XML, entity, status);

    final FcrepoResponse response = testClient.get(uri, RDF_XML, null);

    assertEquals(response.getUrl(), uri);
    assertEquals(response.getStatusCode(), status);
    assertEquals(response.getContentType(), RDF_XML);
    assertEquals(response.getLocation(), null);
    assertEquals(IOUtils.toString(response.getBody()), rdfXml);
}

From source file:org.fcrepo.camel.FcrepoClientErrorTest.java

@Test
public void testGetError() throws Exception {
    final int status = 400;
    final URI uri = create(baseUrl);
    final ByteArrayEntity entity = new ByteArrayEntity(rdfXml.getBytes());

    entity.setContentType(RDF_XML);
    doSetupMockRequest(RDF_XML, entity, status);

    final FcrepoResponse response = testClient.get(uri, RDF_XML, "return=representation;");

    assertEquals(response.getUrl(), uri);
    assertEquals(response.getStatusCode(), status);
    assertEquals(response.getContentType(), RDF_XML);
    assertEquals(response.getLocation(), null);
    assertEquals(IOUtils.toString(response.getBody()), rdfXml);
}

From source file:com.intel.cosbench.client.swift.SwiftClient.java

public void storeObject(String container, String object, byte[] data) throws IOException, SwiftException {
    SwiftResponse response = null;//from   ww w. j  a  v  a  2  s.c  o  m
    try {
        method = HttpClientUtil.makeHttpPut(getObjectPath(container, object));
        method.setHeader(X_AUTH_TOKEN, authToken);
        ByteArrayEntity entity = new ByteArrayEntity(data);
        entity.setChunked(false);
        entity.setContentType("application/octet-stream");
        ((HttpPut) method).setEntity(entity);
        response = new SwiftResponse(client.execute(method));
        if (response.getStatusCode() == SC_CREATED)
            return;
        if (response.getStatusCode() == SC_ACCEPTED)
            return;
        if (response.getStatusCode() == SC_NOT_FOUND)
            throw new SwiftFileNotFoundException("container not found: " + container,
                    response.getResponseHeaders(), response.getStatusLine());
        throw new SwiftException("unexpected return from server", response.getResponseHeaders(),
                response.getStatusLine());
    } finally {
        if (response != null)
            response.consumeResposeBody();
    }
}

From source file:org.callimachusproject.server.chain.TransactionHandler.java

private ByteArrayEntity copyEntity(HttpEntity entity, int length) throws IOException {
    InputStream in = entity.getContent();
    try {//from   w  w  w. j ava2 s. c  o  m
        if (length < 0) {
            length = ONE_PACKET;
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream(length);
        ChannelUtil.transfer(in, baos);
        ByteArrayEntity bae = new ByteArrayEntity(baos.toByteArray());
        bae.setContentEncoding(entity.getContentEncoding());
        bae.setContentType(entity.getContentType());
        return bae;
    } finally {
        in.close();
    }
}

From source file:org.mobicents.applications.ussd.examples.http.push.HTTPPush.java

/**
 * @param serialized//from ww  w  .  j av a  2 s  . com
 * @return
 */
protected HttpResponse send(byte[] serialized) throws Exception {
    HttpUriRequest post = new HttpPost(this.targetURI);
    if (!(post instanceof HttpEntityEnclosingRequestBase)) {
        throw new IOException();
    }
    addStatusEntry("Sending:\n" + new String(serialized));
    ByteArrayEntity entity = new ByteArrayEntity(serialized);
    entity.setContentType("text/xml");
    entity.setContentEncoding(Charset.defaultCharset().toString());
    ((HttpEntityEnclosingRequestBase) post).setEntity(entity);

    return this.httpClient.execute(post, this.context);
}