Search in sources :

Example 91 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project sling by apache.

the class PostStatusTest method simplePost.

private void simplePost(String url, String statusParam, int expectStatus, String expectLocation) throws IOException {
    final PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);
    if (statusParam != null) {
        post.addParameter(SlingPostConstants.RP_STATUS, statusParam);
    }
    final int status = httpClient.executeMethod(post);
    assertEquals("Unexpected status response", expectStatus, status);
    if (expectLocation != null) {
        String location = post.getResponseHeader("Location").getValue();
        assertNotNull("Expected location header", location);
        assertTrue(location.endsWith(expectLocation));
    }
    post.releaseConnection();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 92 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project sling by apache.

the class RequestUriOptingServletTest method testPostMethodExistingResource.

public void testPostMethodExistingResource() throws Exception {
    final PostMethod post = new PostMethod(testNodeNORT.nodeUrl + TEST_URL_SUFFIX);
    final int status = httpClient.executeMethod(post);
    assertEquals("PUT should return 200", 200, status);
    final String content = post.getResponseBodyAsString();
    assertServlet(content, REQUEST_URI_OPTING_SERVLET_SUFFIX);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 93 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project sling by apache.

the class RequestUriOptingServletTest method testPuttMethodNonExistingResource.

public void testPuttMethodNonExistingResource() throws Exception {
    final PostMethod post = new PostMethod(NONEXISTING_RESOURCE_URL + TEST_URL_SUFFIX);
    final int status = httpClient.executeMethod(post);
    assertEquals("PUT should return 200", 200, status);
    final String content = post.getResponseBodyAsString();
    assertServlet(content, REQUEST_URI_OPTING_SERVLET_SUFFIX);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 94 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project sling by apache.

the class SLING2082Test method testPOST.

public void testPOST() throws Exception {
    final String path = "/" + getClass().getSimpleName() + "/" + Math.random() + ".html/%22%3e%3cscript%3ealert(29679)%3c/script%3e";
    final PostMethod post = new PostMethod(HTTP_BASE_URL + path);
    runTest(post, HttpServletResponse.SC_CREATED);
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 95 with PostMethod

use of org.apache.commons.httpclient.methods.PostMethod in project sling by apache.

the class RedirectOnLoginErrorTest method assertPostStatus.

/** Execute a POST request and check status
     * @return the HttpMethod executed
     * @throws IOException */
private HttpMethod assertPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage, String referer) throws IOException {
    final PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);
    post.setDoAuthentication(false);
    //set the referer to indicate where we came from
    post.setRequestHeader("Referer", referer);
    //set Accept header to trick sling into treating the request as from a browser
    post.setRequestHeader("User-Agent", "Mozilla/5.0 Sling Integration Test");
    if (postParams != null) {
        final NameValuePair[] nvp = {};
        post.setRequestBody(postParams.toArray(nvp));
    }
    if (postParams != null) {
        final NameValuePair[] nvp = {};
        post.setRequestBody(postParams.toArray(nvp));
    }
    final int status = httpClient.executeMethod(post);
    if (assertMessage == null) {
        assertEquals(expectedStatusCode, status);
    } else {
        assertEquals(assertMessage, expectedStatusCode, status);
    }
    return post;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Aggregations

PostMethod (org.apache.commons.httpclient.methods.PostMethod)203 HttpClient (org.apache.commons.httpclient.HttpClient)114 Test (org.junit.Test)55 IOException (java.io.IOException)32 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)28 Part (org.apache.commons.httpclient.methods.multipart.Part)25 NameValuePair (org.apache.commons.httpclient.NameValuePair)24 FilePart (org.apache.commons.httpclient.methods.multipart.FilePart)23 Map (java.util.Map)21 GetMethod (org.apache.commons.httpclient.methods.GetMethod)21 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)21 StringPart (org.apache.commons.httpclient.methods.multipart.StringPart)21 HttpMethod (org.apache.commons.httpclient.HttpMethod)17 Header (org.apache.commons.httpclient.Header)16 Note (org.apache.zeppelin.notebook.Note)13 HttpException (org.apache.commons.httpclient.HttpException)12 File (java.io.File)11 InputStream (java.io.InputStream)11 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)11 JSONParser (org.json.simple.parser.JSONParser)11