Package org.apache.http.entity

Examples of org.apache.http.entity.StringEntity


            if (uri.equals("/oldlocation/")) {
                response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
                response.addHeader(new BasicHeader("Location", url));
            } else if (uri.equals("/relativelocation/")) {
                response.setStatusLine(ver, HttpStatus.SC_OK);
                StringEntity entity = new StringEntity("Successful redirect");
                response.setEntity(entity);
            } else {
                response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
            }
        }
View Full Code Here


        final String  charset = "UTF-8";
        final HttpHost target = getServerHttp();

        HttpPost request = new HttpPost("/echo/");
        request.setHeader("Host", target.getHostName());
        request.setEntity(new StringEntity(message, charset));

        HttpClientConnection conn = connectTo(target);

        httpContext.setAttribute(
                ExecutionContext.HTTP_CONNECTION, conn);
View Full Code Here

        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            StringEntity entity = new StringEntity("Whatever");
            response.setEntity(entity);
        }
View Full Code Here

                response.addHeader(new BasicHeader("Location",
                        "http://" + this.host + ":" + this.port + "/newlocation/"));
                response.addHeader(new BasicHeader("Connection", "close"));
            } else if (uri.equals("/newlocation/")) {
                response.setStatusLine(ver, HttpStatus.SC_OK);
                StringEntity entity = new StringEntity("Successful redirect");
                response.setEntity(entity);
            } else {
                response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
            }
        }
View Full Code Here

        assertEquals(1, result.size());
        assertNameValuePair(result.get(0), "Name8", "xx,  yy  ,zz");
    }

    public void testParseEntity () throws Exception {
        final StringEntity entity = new StringEntity("Name1=Value1", null);

        entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
        final List <NameValuePair> result = URLEncodedUtils.parse(entity);
        assertEquals(1, result.size());
        assertNameValuePair(result.get(0), "Name1", "Value1");

        entity.setContentType("text/test");
        assertTrue(URLEncodedUtils.parse(entity).isEmpty());
    }
View Full Code Here

        entity.setContentType("text/test");
        assertTrue(URLEncodedUtils.parse(entity).isEmpty());
    }

    public void testIsEncoded () throws Exception {
        final StringEntity entity = new StringEntity("...", null);

        entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
        assertTrue(URLEncodedUtils.isEncoded(entity));

        entity.setContentType("text/test");
        assertFalse(URLEncodedUtils.isEncoded(entity));
    }
View Full Code Here

        assertEquals("whatever", clone.getParams().getParameter("p2"));
        assertEquals(null, clone.getParams().getParameter("p3"));
       
        assertNull(clone.getEntity());
       
        StringEntity e1 = new StringEntity("stuff");
        httppost.setEntity(e1);
        clone = (HttpPost) httppost.clone();
        assertTrue(clone.getEntity() instanceof StringEntity);
        assertFalse(clone.getEntity().equals(e1));
       
View Full Code Here

                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
            this.requestedUri = request.getRequestLine().getUri();
            response.setStatusLine(ver, HttpStatus.SC_OK);
            StringEntity entity = new StringEntity("Response Body");
            response.setEntity(entity);
        }
View Full Code Here

    private static class BasicService implements HttpRequestHandler {
        public void handle(final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            response.setStatusCode(200);
            response.setEntity(new StringEntity("Hello World"));
        }
View Full Code Here

        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            StringEntity entity = new StringEntity("Whatever");
            response.setEntity(entity);
        }
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.