Search in sources :

Example 31 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project cloudstack by apache.

the class BigSwitchBcfApi method executeDeleteObject.

protected String executeDeleteObject(final String uri) throws BigSwitchBcfApiException {
    checkInvariants();
    DeleteMethod dm = (DeleteMethod) createMethod("delete", uri, _port);
    setHttpHeader(dm);
    executeMethod(dm);
    String hash = checkResponse(dm, "BigSwitch HTTP delete failed: ");
    dm.releaseConnection();
    return hash;
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod)

Example 32 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project android by nextcloud.

the class NotificationExecuteActionTask method doInBackground.

@Override
protected Boolean doInBackground(Action... actions) {
    HttpMethod method;
    Action action = actions[0];
    switch(action.type) {
        case "GET":
            method = new GetMethod(action.link);
            break;
        case "POST":
            method = new Utf8PostMethod(action.link);
            break;
        case "DELETE":
            method = new DeleteMethod(action.link);
            break;
        case "PUT":
            method = new PutMethod(action.link);
            break;
        default:
            // do nothing
            return Boolean.FALSE;
    }
    method.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE);
    int status;
    try {
        status = client.executeMethod(method);
    } catch (IOException e) {
        Log_OC.e(this, "Execution of notification action failed: " + e);
        return Boolean.FALSE;
    } finally {
        method.releaseConnection();
    }
    return status == HttpStatus.SC_OK || status == HttpStatus.SC_ACCEPTED;
}
Also used : Action(com.owncloud.android.lib.resources.notifications.models.Action) DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) Utf8PostMethod(org.apache.commons.httpclient.methods.Utf8PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 33 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project alfresco-repository by Alfresco.

the class BaseWebScriptTest method sendRemoteRequest.

/**
 * Send Remote Request to stand-alone Web Script Server
 *
 * @param req Request
 * @param expectedStatus int
 * @return response
 * @throws IOException
 */
protected Response sendRemoteRequest(Request req, int expectedStatus) throws IOException {
    String uri = req.getFullUri();
    if (!uri.startsWith("http")) {
        uri = remoteServer.baseAddress + uri;
    }
    // construct method
    HttpMethod httpMethod = null;
    String method = req.getMethod();
    if (method.equalsIgnoreCase("GET")) {
        GetMethod get = new GetMethod(req.getFullUri());
        httpMethod = get;
    } else if (method.equalsIgnoreCase("POST")) {
        PostMethod post = new PostMethod(req.getFullUri());
        post.setRequestEntity(new ByteArrayRequestEntity(req.getBody(), req.getType()));
        httpMethod = post;
    } else if (method.equalsIgnoreCase("PATCH")) {
        PatchMethod post = new PatchMethod(req.getFullUri());
        post.setRequestEntity(new ByteArrayRequestEntity(req.getBody(), req.getType()));
        httpMethod = post;
    } else if (method.equalsIgnoreCase("PUT")) {
        PutMethod put = new PutMethod(req.getFullUri());
        put.setRequestEntity(new ByteArrayRequestEntity(req.getBody(), req.getType()));
        httpMethod = put;
    } else if (method.equalsIgnoreCase("DELETE")) {
        DeleteMethod del = new DeleteMethod(req.getFullUri());
        httpMethod = del;
    } else {
        throw new AlfrescoRuntimeException("Http Method " + method + " not supported");
    }
    if (req.getHeaders() != null) {
        for (Map.Entry<String, String> header : req.getHeaders().entrySet()) {
            httpMethod.setRequestHeader(header.getKey(), header.getValue());
        }
    }
    // execute method
    httpClient.executeMethod(httpMethod);
    return new HttpMethodResponse(httpMethod);
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Map(java.util.Map) HttpMethod(org.apache.commons.httpclient.HttpMethod) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity)

Example 34 with DeleteMethod

use of org.apache.commons.httpclient.methods.DeleteMethod in project jaxrs-api by eclipse-ee4j.

the class MethodFactory method getInstance.

/*
   * public methods
   * ========================================================================
   */
/**
 * Returns the approriate request method based on the provided request string.
 * The request must be in the format of METHOD URI_PATH HTTP_VERSION, i.e. GET
 * /index.jsp HTTP/1.1.
 *
 * @return HttpMethod based in request.
 */
public static HttpMethod getInstance(String request) {
    StringTokenizer st = new StringTokenizer(request);
    String method;
    String query = null;
    String uri;
    String version;
    try {
        method = st.nextToken();
        uri = TS_URL.getRequest(st.nextToken());
        version = st.nextToken();
    } catch (NoSuchElementException nsee) {
        throw new IllegalArgumentException("Request provided: " + request + " is malformed.");
    }
    // check to see if there is a query string appended
    // to the URI
    int queryStart = uri.indexOf('?');
    if (queryStart != -1) {
        query = uri.substring(queryStart + 1);
        uri = uri.substring(0, queryStart);
    }
    HttpMethodBase req;
    if (method.equals(GET_METHOD)) {
        req = new GetMethod(uri);
    } else if (method.equals(POST_METHOD)) {
        req = new PostMethod(uri);
    } else if (method.equals(PUT_METHOD)) {
        req = new PutMethod(uri);
    } else if (method.equals(DELETE_METHOD)) {
        req = new DeleteMethod(uri);
    } else if (method.equals(HEAD_METHOD)) {
        req = new HeadMethod(uri);
    } else if (method.equals(OPTIONS_METHOD)) {
        req = new OptionsMethod(uri);
    } else {
        throw new IllegalArgumentException("Invalid method: " + method);
    }
    setHttpVersion(version, req);
    if (query != null) {
        req.setQueryString(query);
    }
    return req;
}
Also used : StringTokenizer(java.util.StringTokenizer) DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) OptionsMethod(org.apache.commons.httpclient.methods.OptionsMethod) HttpMethodBase(org.apache.commons.httpclient.HttpMethodBase) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)34 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 PutMethod (org.apache.commons.httpclient.methods.PutMethod)12 Test (org.junit.Test)8 PostMethod (org.apache.commons.httpclient.methods.PostMethod)7 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)7 IOException (java.io.IOException)6 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 HttpClient (org.apache.commons.httpclient.HttpClient)5 HttpMethodBase (org.apache.commons.httpclient.HttpMethodBase)4 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)4 HeadMethod (org.apache.commons.httpclient.methods.HeadMethod)3 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 Header (org.apache.commons.httpclient.Header)2 URIException (org.apache.commons.httpclient.URIException)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)2