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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations