use of org.apache.commons.httpclient.methods.DeleteMethod in project xwiki-platform by xwiki.
the class AttachmentsResourceTest method testDELETEAttachment.
@Test
public void testDELETEAttachment() throws Exception {
String attachmentName = String.format("%d.txt", System.currentTimeMillis());
String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
String content = "ATTACHMENT CONTENT";
PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
GetMethod getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
DeleteMethod deleteMethod = executeDelete(attachmentURI, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode());
getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project xwiki-platform by xwiki.
the class AttachmentsResourceTest method testDELETEAttachmentNoRights.
@Test
public void testDELETEAttachmentNoRights() throws Exception {
String attachmentName = String.format("%d.txt", System.currentTimeMillis());
String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
String content = "ATTACHMENT CONTENT";
PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
DeleteMethod deleteMethod = executeDelete(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode());
GetMethod getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project fabric8 by jboss-fuse.
the class ProxyServlet method doDelete.
/**
* Performs an HTTP DELETE request
*
* @param httpServletRequest The {@link javax.servlet.http.HttpServletRequest} object passed
* in by the servlet engine representing the
* client request to be proxied
* @param httpServletResponse The {@link javax.servlet.http.HttpServletResponse} object by which
* we can send a proxied response to the client
*/
@Override
public void doDelete(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
ProxyDetails proxyDetails = createProxyDetails(httpServletRequest, httpServletResponse);
if (!proxyDetails.isValid()) {
noMappingFound(httpServletRequest, httpServletResponse);
} else {
DeleteMethod deleteMethodProxyRequest = new DeleteMethod(proxyDetails.getStringProxyURL());
// Forward the request headers
setProxyRequestHeaders(proxyDetails, httpServletRequest, deleteMethodProxyRequest);
// Execute the proxy request
executeProxyRequest(proxyDetails, deleteMethodProxyRequest, httpServletRequest, httpServletResponse);
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project jaggery by wso2.
the class XMLHttpRequestHostObject method send.
private void send(Context cx, Object obj) throws ScriptException {
final HttpMethodBase method;
if ("GET".equalsIgnoreCase(methodName)) {
method = new GetMethod(this.url);
} else if ("HEAD".equalsIgnoreCase(methodName)) {
method = new HeadMethod(this.url);
} else if ("POST".equalsIgnoreCase(methodName)) {
PostMethod post = new PostMethod(this.url);
if (obj instanceof FormDataHostObject) {
FormDataHostObject fd = ((FormDataHostObject) obj);
List<Part> parts = new ArrayList<Part>();
for (Map.Entry<String, String> entry : fd) {
parts.add(new StringPart(entry.getKey(), entry.getValue()));
}
post.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post.getParams()));
} else {
String content = getRequestContent(obj);
if (content != null) {
post.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
}
}
method = post;
} else if ("PUT".equalsIgnoreCase(methodName)) {
PutMethod put = new PutMethod(this.url);
String content = getRequestContent(obj);
if (content != null) {
put.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
}
method = put;
} else if ("DELETE".equalsIgnoreCase(methodName)) {
method = new DeleteMethod(this.url);
} else if ("TRACE".equalsIgnoreCase(methodName)) {
method = new TraceMethod(this.url);
} else if ("OPTIONS".equalsIgnoreCase(methodName)) {
method = new OptionsMethod(this.url);
} else {
throw new ScriptException("Unknown HTTP method : " + methodName);
}
for (Header header : requestHeaders) {
method.addRequestHeader(header);
}
if (username != null) {
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
}
this.method = method;
final XMLHttpRequestHostObject xhr = this;
if (async) {
updateReadyState(cx, xhr, LOADING);
final ContextFactory factory = cx.getFactory();
final ExecutorService es = Executors.newSingleThreadExecutor();
es.submit(new Callable() {
public Object call() throws Exception {
Context ctx = RhinoEngine.enterContext(factory);
try {
executeRequest(ctx, xhr);
} catch (ScriptException e) {
log.error(e.getMessage(), e);
} finally {
es.shutdown();
RhinoEngine.exitContext();
}
return null;
}
});
} else {
executeRequest(cx, xhr);
}
}
use of org.apache.commons.httpclient.methods.DeleteMethod in project application by collectionspace.
the class ServicesConnection method createMethod.
private HttpMethod createMethod(RequestMethod method, String uri, InputStream data) throws ConnectionException {
uri = prepend_base(uri);
if (uri == null)
throw new ConnectionException("URI must not be null");
// Extract QP's
int qp_start = uri.indexOf('?');
String qps = null;
if (qp_start != -1) {
qps = uri.substring(qp_start + 1);
uri = uri.substring(0, qp_start);
}
HttpMethod out = null;
switch(method) {
case POST:
{
out = new PostMethod(uri);
if (data != null)
((PostMethod) out).setRequestEntity(new InputStreamRequestEntity(data));
break;
}
case PUT:
{
out = new PutMethod(uri);
if (data != null)
((PutMethod) out).setRequestEntity(new InputStreamRequestEntity(data));
break;
}
case GET:
out = new GetMethod(uri);
break;
case DELETE:
out = new DeleteMethod(uri);
break;
default:
throw new ConnectionException("Unsupported method " + method, 0, uri);
}
if (qps != null)
out.setQueryString(qps);
out.setDoAuthentication(true);
return out;
}
Aggregations