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

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

Introduction

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

Prototype

public StringEntity(String str, Charset charset) 

Source Link

Usage

From source file:gobblin.writer.http.HttpWriter.java

@Override
public Optional<HttpUriRequest> onNewRecord(D record) {
    try {/*from ww w .  j  a v  a 2s  .c  o m*/
        HttpUriRequest uriRequest = RequestBuilder.post()
                .addHeader(HttpHeaders.CONTENT_TYPE, ContentType.TEXT_PLAIN.getMimeType())
                .setUri(getCurServerHost())
                .setEntity(new StringEntity(record.toString(), ContentType.TEXT_PLAIN.toString())).build();
        return Optional.of(uriRequest);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:io.logspace.agent.hq.HqClient.java

private static StringEntity toJSonEntity(AgentControllerCapabilities capabilities) throws IOException {
    return new StringEntity(AgentControllerCapabilitiesJsonSerializer.toJson(capabilities), APPLICATION_JSON);
}

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

public HttpEntity getEntity() {
    try {//from w ww .j av a2  s  .co m
        return new StringEntity(body.toString(), UTF_8);
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:org.wisdom.test.http.RequestBodyEntity.java

/**
 * @return the HTTP Entity wrapping the body.
 */
public HttpEntity getEntity() {
    return new StringEntity(body.toString(), UTF_8);
}

From source file:org.nuxeo.elasticsearch.http.readonly.HttpClient.java

public static String get(String url, String payload) throws IOException {
    if (payload == null) {
        return get(url);
    }/*  ww  w .jav a2s.  c om*/
    CloseableHttpClient client = HttpClients.createDefault();
    HttpGetWithEntity e = new HttpGetWithEntity(url);
    StringEntity myEntity = new StringEntity(payload,
            ContentType.create(MediaType.APPLICATION_FORM_URLENCODED, UTF8_CHARSET));
    e.setEntity(myEntity);
    try (CloseableHttpResponse response = client.execute(e)) {
        HttpEntity entity = response.getEntity();
        return entity != null ? EntityUtils.toString(entity) : null;
    }
}

From source file:pl.bcichecki.rms.client.android.services.clients.restful.impl.DevicesRestClient.java

public void createDevice(Device device, AsyncHttpResponseHandler handler) {
    String deviceAsJson = GsonHolder.getGson().toJson(device);
    HttpEntity deviceAsHttpEntity;// w ww .  j  a  va  2  s.  co  m

    try {
        deviceAsHttpEntity = new StringEntity(deviceAsJson, HttpConstants.CHARSET_UTF8);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "This system does not support required encoding.", e);
        throw new IllegalStateException("This system does not support required encoding.", e);
    }
    List<Header> headers = new ArrayList<Header>();
    RestUtils.decorareHeaderWithMD5(headers, deviceAsJson);

    put(getContext(), getAbsoluteAddress(RestConstants.RESOURCE_PATH_DEVICES), getHeadersAsArray(headers),
            deviceAsHttpEntity, HttpConstants.CONTENT_TYPE_APPLICATION_JSON_CHARSET_UTF8, handler);
}

From source file:net.ychron.unirestinst.request.body.RequestBodyEntity.java

public HttpEntity getEntity() {
    return new StringEntity(body.toString(), UTF_8);
}

From source file:org.wise.vle.domain.webservice.crater.CRaterHttpClient.java

/**
 * Handles POSTing a CRater Request to the CRater Servlet and returns the 
 * CRater response string.//from   w ww .ja  v  a  2  s  .  c om
 * 
 * @param cRaterUrl the CRater url
 * @param bodyData the xml body data to be sent to the CRater server
 * @return the response from the CRater server
 */
public static String post(String cRaterUrl, String bodyData) {
    String responseString = null;

    if (cRaterUrl != null) {
        HttpClient client = HttpClientBuilder.create().build();

        // Create a method instance.
        HttpPost post = new HttpPost(cRaterUrl);

        try {
            //System.out.println("CRater request bodyData:" + bodyData);
            post.setEntity(new StringEntity(bodyData, ContentType.TEXT_XML));

            // Execute the method.
            HttpResponse response = client.execute(post);

            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                System.err.println("Method failed: " + response.getStatusLine());
            }

            // Read the response body.
            responseString = IOUtils.toString(response.getEntity().getContent());
            //System.out.println("responseString: " + responseString);
        } catch (IOException e) {
            System.err.println("Fatal transport error: " + e.getMessage());
            e.printStackTrace();
        } finally {
            // Release the connection.
            post.releaseConnection();
        }
    }

    return responseString;
}

From source file:org.llorllale.youtrack.api.mock.http.response.MockNotFoundResponse.java

/**
 * Ctor.//from www.j  a v a2  s  .  c  o  m
 *
 * @param xml the xml payload that YouTrack returns in 404 responses
 * @since 0.4.0
 */
@SuppressWarnings("checkstyle:MagicNumber")
public MockNotFoundResponse(String xml) {
    this.statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 404, "Not Found");
    this.payload = new StringEntity(xml, ContentType.APPLICATION_XML);
}