Example usage for org.apache.http.entity ContentType toString

List of usage examples for org.apache.http.entity ContentType toString

Introduction

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

Prototype

public String toString() 

Source Link

Usage

From source file:pl.allegro.tech.hermes.consumers.consumer.sender.http.ByteBufferEntity.java

public ByteBufferEntity(final ByteBuffer buffer, final ContentType contentType) {
    super();/*  ww  w  .  j  av a  2 s .  c  o  m*/
    Args.notNull(buffer, "Source byte buffer");
    this.buffer = buffer;
    if (contentType != null) {
        setContentType(contentType.toString());
    }
}

From source file:org.imsglobal.caliper.request.ApacheHttpRequestor.java

/**
 * Generate an HTTP StringEntity from the provided JSON string.  Set the ContentType to 'application/json'.
 * @param value//from ww w .j  av a 2 s.c o  m
 * @param contentType
 * @return
 * @throws UnsupportedEncodingException
 */
public StringEntity generatePayload(String value, ContentType contentType) throws UnsupportedEncodingException {
    StringEntity payload = new StringEntity(value);
    payload.setContentType(contentType.toString());

    return payload;
}

From source file:com.hp.mqm.client.internal.InputStreamSourceEntity.java

public InputStreamSourceEntity(InputStreamSource inputStreamSource, long length, ContentType contentType) {
    if (inputStreamSource == null) {
        throw new IllegalArgumentException("InputStreamSource cannot be null.");
    }/*ww w.  j a va2  s.c  o m*/
    this.length = length;
    if (contentType != null) {
        setContentType(contentType.toString());
    }
    this.inputStreamSource = inputStreamSource;
}

From source file:org.apache.hadoop.gateway.dispatch.InputStreamEntity.java

/**
 * @param instream    input stream/*from   ww w  .  java2  s . c o  m*/
 * @param length      of the input stream, {@code -1} if unknown
 * @param contentType for specifying the {@code Content-Type} header, may be {@code null}
 * @throws IllegalArgumentException if {@code instream} is {@code null}
 */
public InputStreamEntity(final InputStream instream, final long length, final ContentType contentType) {
    super();
    this.content = Args.notNull(instream, "Source input stream");
    this.length = length;
    if (contentType != null) {
        setContentType(contentType.toString());
    }
}

From source file:com.joyent.manta.http.entity.ExposedByteArrayEntity.java

/**
 * Creates a new instance based on the passed byte array at the specified
 * offset and length./*from   w ww. j  av a2  s . c o  m*/
 *
 * @param buffer byte array to back this entity.
 * @param offset offset to start reading the byte array from
 * @param length total number of bytes to read
 * @param contentType content type to be used
 */
public ExposedByteArrayEntity(final byte[] buffer, final int offset, final int length,
        final ContentType contentType) {
    Validate.notNull(buffer, "Byte array must not be null");

    this.buffer = buffer;
    this.offset = offset;
    this.length = length;

    if (contentType != null) {
        setContentType(contentType.toString());
    }
}

From source file:au.csiro.casda.sodalint.Validator.java

/**
 * Retrieve the content from an address using a GET request.
 *  //  ww  w.j a  v  a 2 s.  c om
 * @param address The address to be queried.
 * @return The content, or null if no content could be read.
 * @throws HttpResponseException If a non 200 response code is returned.
 * @throws UnsupportedEncodingException If the content does not have an XML format. 
 * @throws IOException If the content could not be read.
 */
protected String getXmlContentFromUrl(String address)
        throws HttpResponseException, UnsupportedEncodingException, IOException {
    Response response = Request.Get(address).execute();
    HttpResponse httpResponse = response.returnResponse();
    StatusLine statusLine = httpResponse.getStatusLine();
    final int statusCodeOk = 200;
    if (statusLine.getStatusCode() != statusCodeOk) {
        throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
    }
    HttpEntity entity = httpResponse.getEntity();
    if (entity == null) {
        return null;
    }
    ContentType contentType = ContentType.getOrDefault(entity);
    if (!ContentType.APPLICATION_XML.getMimeType().equals(contentType.getMimeType())
            && !ContentType.TEXT_XML.getMimeType().equals(contentType.getMimeType())) {
        throw new UnsupportedEncodingException(contentType.toString());
    }
    String content = readTextContent(entity);
    if (StringUtils.isBlank(content)) {
        return null;
    }

    return content;
}

From source file:com.joyent.manta.client.MantaObjectOutputStream.java

/**
 * Creates a new instance of an {@link OutputStream} that wraps PUT
 * requests to Manta.//  w  ww .  j  a  va  2 s . c om
 *
 * @param path The fully qualified path of the object. i.e. /user/stor/foo/bar/baz
 * @param httpHelper reference to HTTP operations helper class
 * @param mantaHttpHeaders optional HTTP headers to include when copying the object
 * @param metadata optional user-supplied metadata for object
 * @param contentType HTTP Content-Type header value
 */
MantaObjectOutputStream(final String path, final HttpHelper httpHelper, final MantaHttpHeaders mantaHttpHeaders,
        final MantaMetadata metadata, final ContentType contentType) {
    this.httpContent = new EmbeddedHttpContent(contentType.toString(), closed);
    this.path = path;

    final MantaHttpHeaders headers;

    if (mantaHttpHeaders == null) {
        headers = new MantaHttpHeaders();
    } else {
        headers = mantaHttpHeaders;
    }

    if (contentType != null) {
        headers.setContentType(contentType.toString());
    }

    /*
     * Thread execution definition that runs the HTTP PUT operation.
     */
    this.completed = EXECUTOR.submit(() -> httpHelper.httpPut(path, headers, httpContent, metadata));

    /*
     * We have to wait here until the upload to Manta starts and a Writer
     * becomes available.
     */
    while (httpContent.getWriter() == null) {
        try {
            Thread.sleep(CLOSED_CHECK_INTERVAL);
        } catch (InterruptedException e) {
            return;
        }
    }
}

From source file:net.ychron.unirestinst.request.HttpRequestWithBody.java

public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) {
    InputStreamBody inputStreamBody = new InputStreamBody(stream, contentType, fileName);
    MultipartBody body = new MultipartBody(httpClientHelper, this).field(name, inputStreamBody, true,
            contentType.toString());
    this.body = body;
    return body;/*from  w  w  w.j  a v  a  2 s .c  o m*/
}

From source file:org.ambraproject.wombat.service.remote.AbstractRestfulJsonApi.java

private <R extends HttpUriRequest & HttpEntityEnclosingRequest> HttpResponse uploadObject(ApiAddress address,
        Object object, Function<URI, R> requestConstructor) throws IOException {
    R request = buildRequest(address, requestConstructor);

    ContentType contentType = ContentType.APPLICATION_JSON;
    if (object != null) {
        String json = jsonService.serialize(object);
        request.setEntity(new StringEntity(json, contentType));
    }/*from   w  ww . j  ava 2s .  com*/

    request.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());

    try (CloseableHttpResponse response = cachedRemoteReader.getResponse(request)) {
        //return closed response
        return response;
    }
}