Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.StringRequestEntity


       
        this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
        this.client.setHttpConnectionManager(connman);
       
        PostMethod httppost = new PostMethod("/test/");
        httppost.setRequestEntity(new StringRequestEntity("stuff"));
        try {
            this.client.executeMethod(httppost);
        } finally {
            httppost.releaseConnection();
        }
        assertFalse(connman.getConection().isOpen());

        httppost = new PostMethod("/test/");
        httppost.setRequestHeader("Connection", "keep-alive");
        httppost.setRequestEntity(new StringRequestEntity("more stuff"));
        try {
            this.client.executeMethod(httppost);
        } finally {
            httppost.releaseConnection();
        }
View Full Code Here


        this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
        this.client.setHttpConnectionManager(connman);
       
        PostMethod httppost = new PostMethod("/test/");
        httppost.setRequestHeader("Connection", "close");
        httppost.setRequestEntity(new StringRequestEntity("stuff"));
        try {
            this.client.executeMethod(httppost);
        } finally {
            httppost.releaseConnection();
        }
View Full Code Here

            final PostMethod post = new PostMethod(url.toString());
            post.setDoAuthentication(true);
            post.setRequestHeader("Accept", "application/json;stream=true");
            final Gson gson = new Gson();
            final String postData = gson.toJson(data);
            post.setRequestEntity(new StringRequestEntity(postData, "application/json", "UTF-8"));
            final int status = client.executeMethod(post);
            if (status != 200) throw new RuntimeException("Return Status Code "+post.getStatusCode()+" "+post.getStatusLine());
            return gson.fromJson(post.getResponseBodyAsString(), resultType);
        } catch (Exception e) {
            throw new RuntimeException("Error executing request to "+url+" with "+data+":" + e.getMessage());
View Full Code Here

        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(buildBase + "/api/build");
        theLogger.finest("/api/build: " + content);
        try {
          method.setRequestEntity(new StringRequestEntity(content, "application/json", "utf-8"));
            int statusCode = client.executeMethod(method);
            String json = method.getResponseBodyAsString();
            theLogger.finest("/api/build response: " + json);
          if (statusCode != HttpStatus.SC_ACCEPTED && statusCode != HttpStatus.SC_OK) {
            throw new IOException(buildBase + "/api/build failed with status: " + statusCode + "\n" + json);
View Full Code Here

            try {
                switch (type) {
                    case PropertyType.NAME:
                    case PropertyType.PATH:
                        String str = ValueFormat.getJCRString(value, resolver);
                        ent = new StringRequestEntity(str, contentType, "UTF-8");
                        break;
                    case PropertyType.BINARY:
                        in = value.getStream();
                        ent = new InputStreamRequestEntity(in, contentType);
                        break;
                    default:
                        str = value.getString();
                        ent = new StringRequestEntity(str, contentType, "UTF-8");
                        break;
                }
            } catch (UnsupportedEncodingException e) {
                // should never get here
                throw new RepositoryException(e.getMessage());
View Full Code Here

    public void testLatinAccentInRequestBody() throws IOException {
        PostMethod httppost = new PostMethod("/");
        String s = constructString(SWISS_GERMAN_STUFF_UNICODE);
        // Test default encoding ISO-8859-1
        httppost.setRequestEntity(
            new StringRequestEntity(s, "text/plain", CHARSET_DEFAULT));
        verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_ISO8859_1);
        // Test UTF-8 encoding
        httppost.setRequestEntity(
            new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
        verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_UTF8);

    }
View Full Code Here

    public void testRussianInRequestBody() throws IOException {
        PostMethod httppost = new PostMethod("/");
        String s = constructString(RUSSIAN_STUFF_UNICODE);
        // Test UTF-8 encoding
        httppost.setRequestEntity(
            new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
        verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_UTF8);
        // Test KOI8-R
        httppost.setRequestEntity(
            new StringRequestEntity(s, "text/plain", CHARSET_KOI8_R));
        verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_KOI8R);
        // Test WIN1251
        httppost.setRequestEntity(
            new StringRequestEntity(s, "text/plain", CHARSET_WIN1251));
        verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_WIN1251);
    }
View Full Code Here

    }
   
    public void testRequestEntityLength() throws IOException {
        String s = constructString(SWISS_GERMAN_STUFF_UNICODE);
        RequestEntity requestentity =
            new StringRequestEntity(s, "text/plain", CHARSET_UTF8);
        assertEquals(
                s.getBytes(CHARSET_UTF8).length,
                requestentity.getContentLength());
    }
View Full Code Here

    }

    public void testPostSetRequestBody() throws Exception {
        PostMethod post = new PostMethod("/foo");
        String body = "this+is+the+body";
        post.setRequestEntity(new StringRequestEntity(body));
        assertEquals(body, getRequestAsString(post.getRequestEntity()));
    }
View Full Code Here

    public void testPutRedirect() throws Exception {
        HttpClient client = createHttpClient();
        PutMethod method = new PutMethod(redirectUrl);
        method.setQueryString("to=" + URIUtil.encodeWithinQuery(bodyUrl + "?foo=bar&bar=foo"));
        method.setRequestEntity(new StringRequestEntity("This is data to be sent in the body of an HTTP PUT."));
        client.executeMethod(method);
        assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.StringRequestEntity

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.