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) throws UnsupportedEncodingException 

Source Link

Usage

From source file:com.klarna.checkout.HandlerTest.java

/**
 * Test of handleResponse.//  w ww  .j a va  2s .  c  o  m
 *
 * @throws Exception if things go bad.
 */
@Test
public void testHandleResponse() throws Exception {
    HttpResponse res = mock(HttpResponse.class);
    Handler handler = new Handler(mock(IResource.class));
    StatusLine sline = mock(StatusLine.class);
    when(sline.getStatusCode()).thenReturn(200);
    when(res.getStatusLine()).thenReturn(sline);
    when(res.getEntity()).thenReturn(new StringEntity("{}"));
    handler.handleResponse(res);
}

From source file:com.nominanuda.web.http.FormEncodingUtf8Test.java

private String g(String v, String ct) throws IOException {
    StringEntity se = new StringEntity("f=" + v);
    if (ct != null) {
        se.setContentType(ct);//  w  w w  . j  a v a  2 s.c o m
    }
    List<NameValuePair> pairs = h.parseEntityWithDefaultUtf8(se);
    String vv = pairs.get(0).getValue();
    return vv;
}

From source file:com.continuuity.loom.TestHelper.java

public static void finishTask(String loomUrl, FinishTaskRequest finishRequest) throws Exception {
    HttpPost httpPost = new HttpPost(String.format("%s/v1/loom/tasks/finish", loomUrl));
    httpPost.setEntity(new StringEntity(GSON.toJson(finishRequest)));

    CloseableHttpClient httpClient = HttpClients.createDefault();
    CloseableHttpResponse response = httpClient.execute(httpPost);
    try {/* w ww. j  av  a2 s . c  o m*/
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    } finally {
        response.close();
    }
}

From source file:com.clarionmedia.infinitum.http.rest.impl.RestfulStringModelMap.java

@Override
public HttpEntity toHttpEntity() {
    try {//ww  w .j a v a  2s .c o m
        return new StringEntity(mMessage);
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:forplay.android.AndroidNet.java

private void doHttp(boolean isPost, String url, String data, Callback callback) {
    // TODO: use AsyncTask
    HttpClient httpclient = new DefaultHttpClient();
    HttpRequestBase req = null;/*from   w w w.  ja va  2  s.co  m*/
    if (isPost) {
        HttpPost httppost = new HttpPost(url);
        if (data != null) {
            try {
                httppost.setEntity(new StringEntity(data));
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                callback.failure(e);
            }
        }
        req = httppost;
    } else {
        req = new HttpGet(url);
    }
    try {
        HttpResponse response = httpclient.execute(req);
        callback.success(EntityUtils.toString(response.getEntity()));
    } catch (Exception e) {
        callback.failure(e);
    }
}

From source file:brooklyn.test.TestHttpRequestHandler.java

public TestHttpRequestHandler response(String response) {
    try {// w ww.jav a 2 s . co  m
        this.entity = new StringEntity(response);
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.propagate(e);
    }
    return this;
}

From source file:org.esigate.servlet.impl.ResponseSenderTest.java

public void testSendResponseAlreadySent() throws Exception {
    MockHttpServletResponse httpServletResponse = new MockHttpServletResponse();
    PrintWriter writer = httpServletResponse.getWriter();
    writer.write("Test");
    writer.close();/*  w  w w. jav  a  2s .c  om*/
    CloseableHttpResponse httpClientResponse = BasicCloseableHttpResponse
            .adapt(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK")));
    httpClientResponse.setEntity(new StringEntity("Abcdefg"));
    renderer.sendResponse(httpClientResponse, null, httpServletResponse);
}

From source file:ecplugins.s3.TestUtils.java

/**
 * callRunProcedure// w ww  .j ava2s .  co  m
 *
 * @param jo
 * @return the jobId of the job launched by runProcedure
 */
public static String callRunProcedure(JSONObject jo) throws Exception {

    HttpClient httpClient = new DefaultHttpClient();
    JSONObject result = null;

    try {
        HttpPost httpPostRequest = new HttpPost("http://" + props.getProperty(StringConstants.COMMANDER_USER)
                + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@"
                + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/jobs?request=runProcedure");
        StringEntity input = new StringEntity(jo.toString());

        input.setContentType("application/json");
        httpPostRequest.setEntity(input);
        HttpResponse httpResponse = httpClient.execute(httpPostRequest);

        result = new JSONObject(EntityUtils.toString(httpResponse.getEntity()));
        return result.getString("jobId");

    } finally {
        httpClient.getConnectionManager().shutdown();
    }

}

From source file:requestToApi.java

public String addRoom(String roomName, String serverId) {
    String output2 = "";
    try {/*from  w ww .  j a  v a2s  .c  o  m*/

        StringEntity input = new StringEntity(
                "{\"roomName\":\"" + roomName + "\",\"serverId\":\"" + serverId + "\"}");
        String URL = "http://smarthomeinterface.azurewebsites.net/addRoom";
        output2 = send(input, URL);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return output2;
}

From source file:org.opentravel.otm.forum2016.am.UpdateAPIOperation.java

/**
 * @see org.opentravel.otm.forum2016.am.RESTClientOperation#execute()
 *///from  w w w .j  a  v a 2 s .c om
@Override
public APIDetails execute() throws IOException {
    HttpPut request = new HttpPut(APIPublisherConfig.getWSO2PublisherApiBaseUrl() + "/" + api.getId());

    request.setHeader("Content-Type", "application/json");
    request.setEntity(new StringEntity(new Gson().toJson(api.toJson())));
    return execute(request);
}