Package org.apache.http.entity

Examples of org.apache.http.entity.StringEntity


  {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost method = new HttpPost(apiURL);
    try
    {
      method.setEntity(new StringEntity(input,ContentType.create("text/plain","UTF-8")));
      HttpResponse response = client.execute(method);
      int responseCode = response.getStatusLine().getStatusCode();
      String responseString = convertToString(response);
      if (responseCode != expectedResponse)
        throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+", saw "+Integer.toString(responseCode)+": "+responseString);
View Full Code Here


        HttpContext context = new BasicHttpContext(null);
        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
        context.setAttribute(ExecutionContext.HTTP_REQUEST, request);

        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        StringEntity entity = new StringEntity("whatever");
        response.setEntity(entity);
        ResponseConnControl interceptor = new ResponseConnControl();
        interceptor.process(response, context);
        Header header = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
        assertNull(header);
View Full Code Here

   
    public void testRequestContentEntityContentLengthDelimitedHTTP11() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        String s = "whatever";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        request.setEntity(entity);

        RequestContent interceptor = new RequestContent();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.CONTENT_LEN);
View Full Code Here

   
    public void testRequestContentEntityChunkedHTTP11() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        String s = "whatever";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        entity.setChunked(true);
        request.setEntity(entity);

        RequestContent interceptor = new RequestContent();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.TRANSFER_ENCODING);
View Full Code Here

    public void testRequestContentEntityChunkedHTTP10() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
                "POST", "/", HttpVersion.HTTP_1_0);
        String s = "whatever";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        entity.setChunked(true);
        request.setEntity(entity);

        RequestContent interceptor = new RequestContent();
        try {
            interceptor.process(request, context);
View Full Code Here

   public void testRequestExpectContinueGenerated() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        String s = "whatever";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        request.setEntity(entity);
        request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
        RequestExpectContinue interceptor = new RequestExpectContinue();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
View Full Code Here

    public void testRequestExpectContinueNotGenerated() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        String s = "whatever";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        request.setEntity(entity);
        request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
        RequestExpectContinue interceptor = new RequestExpectContinue();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
View Full Code Here

    public void testRequestExpectContinueHTTP10() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
                "POST", "/", HttpVersion.HTTP_1_0);
        String s = "whatever";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        request.setEntity(entity);
        request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
        RequestExpectContinue interceptor = new RequestExpectContinue();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
View Full Code Here

    public void testRequestExpectContinueZeroContent() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        String s = "";
        StringEntity entity = new StringEntity(s, "US-ASCII");
        request.setEntity(entity);
        request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
        RequestExpectContinue interceptor = new RequestExpectContinue();
        interceptor.process(request, context);
        Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
View Full Code Here

    }
   
    public void testResponseConnControlEntityContentLength() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        StringEntity entity = new StringEntity("whatever");
        response.setEntity(entity);
        ResponseConnControl interceptor = new ResponseConnControl();
        interceptor.process(response, context);
        Header header = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
        assertNull(header);
View Full Code Here

TOP

Related Classes of org.apache.http.entity.StringEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.