Example usage for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.

Prototype

int SC_NOT_FOUND

To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.

Click Source Link

Document

<tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public TransactionQueryResult listTransactions(ListTransactionsRequest request) {
    String uri = baseUrl + TRANSACTIONS;
    PutMethod method = new PutMethod(uri);
    try {//from w w w . j  av  a 2  s  .  c o  m
        String data = serialize(request);
        method.setRequestEntity(new StringRequestEntity(data, MIME_TYPE_JSON, DEFAULT_CHAR_ENCODING));

        // Execute the HTTP Call
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        if (statusCode == HttpStatus.SC_OK) {
            InputStream body = method.getResponseBodyAsStream();
            return parseJson(body, TransactionQueryResult.class);

        } else {
            throw new RuntimeException(
                    "Failed to list transactions, RESPONSE CODE: " + statusCode + " url: " + uri);
        }

    } catch (Exception e) {
        throw new RuntimeException("Failed listing transactions via url " + uri, e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java

@Override
public void updatePassword(Long userId, String newPassword) {
    String resource = String.format(baseUrl + SET_PASSWORD, userId);
    PutMethod method = new PutMethod(resource);
    try {/*w w w. ja  v  a2  s .co m*/
        ChangeUserPasswordRequest request = new ChangeUserPasswordRequest();
        request.setPassword(newPassword);
        String data = serialize(request);
        method.setRequestEntity(new StringRequestEntity(data, "application/json", "UTF-8"));

        // Execute the HTTP Call
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public CurrencyListResult getSupportedCurrencies() {
    String uri = baseUrl + CURRENCIES;
    String resource = String.format(uri);
    GetMethod method = createGetMethod(resource);

    try {//  www  .  ja v  a2s.  c o  m
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        // Read the response body.
        InputStream body = method.getResponseBodyAsStream();
        return parseJson(body, CurrencyListResult.class);
    } catch (Exception e) {
        throw new RuntimeException("Failed getting supported currencies via url " + uri, e);
    } finally {
        method.releaseConnection();
    }
}

From source file:davmail.http.DavGatewayHttpClientFacade.java

/**
 * Execute a delete method on the given path with httpClient.
 *
 * @param httpClient Http client instance
 * @param path       Path to be deleted/*from w w w .  j  a v  a  2  s. com*/
 * @return http status
 * @throws IOException on error
 */
public static int executeDeleteMethod(HttpClient httpClient, String path) throws IOException {
    DeleteMethod deleteMethod = new DeleteMethod(path);
    deleteMethod.setFollowRedirects(false);

    int status = executeHttpMethod(httpClient, deleteMethod);
    // do not throw error if already deleted
    if (status != HttpStatus.SC_OK && status != HttpStatus.SC_NOT_FOUND) {
        throw DavGatewayHttpClientFacade.buildHttpException(deleteMethod);
    }
    return status;
}

From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java

@Override
public CreateUserResponse createUser(CreateUserRequest request) {
    PostMethod method = new PostMethod(baseUrl + CREATE_USER);
    try {//from   ww w . j  a  va  2s  .  c  om
        String data = serialize(request);
        method.setRequestEntity(new StringRequestEntity(data, "application/json", "UTF-8"));

        // Execute the HTTP Call
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        if (statusCode == HttpStatus.SC_OK) {
            InputStream body = method.getResponseBodyAsStream();
            return parseJson(body, CreateUserResponse.class);

        } else {
            throw new RuntimeException("Failed to create user, RESPONSE CODE: " + statusCode);
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public void addCurrency(Currency currency) {
    String uri = baseUrl + CURRENCIES;
    PostMethod method = createPostMethod(uri);

    try {//from w w w. java  2  s.  com
        String data = serialize(currency);
        method.setRequestEntity(new StringRequestEntity(data, MIME_TYPE_JSON, DEFAULT_CHAR_ENCODING));

        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);
    } catch (Exception e) {
        throw new RuntimeException("Failed adding currency via url " + uri, e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java

@Override
public void setUserAttribute(Long userId, String key, String value) {
    String resource = String.format(baseUrl + USER_ATTRIBUTES + "/" + key, userId);
    PutMethod method = new PutMethod(resource);
    try {/*from w  w w .j  a  v a 2 s.  c o m*/
        method.setRequestEntity(new StringRequestEntity(value, "text/plain", "UTF-8"));

        // Execute the HTTP Call
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public Currency getCurrency(String currencyCode) {
    String resource = String.format(baseUrl + CURRENCY, currencyCode);
    GetMethod method = createGetMethod(resource);

    try {/*from   ww  w  .  ja  v  a  2  s  .c  om*/
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        // Read the response body.
        InputStream body = method.getResponseBodyAsStream();
        return parseJson(body, Currency.class);
    } catch (Exception e) {
        throw new RuntimeException("Failed getting currency via resource " + resource, e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java

@Override
public String getUserAttribute(Long userId, String key) {
    // Create a method instance.
    String resource = String.format(baseUrl + USER_ATTRIBUTES + "/" + key, userId);
    GetMethod method = createGetMethod(resource);

    try {/*from   ww  w  . j  a va  2s. c o m*/
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        // Read the response body.
        InputStream body = method.getResponseBodyAsStream();

        return new java.util.Scanner(body).useDelimiter("\\A").next();

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.wallet.client.WalletServiceClientHTTP.java

@Override
public void updateCurrency(Currency currency) {
    String resource = String.format(baseUrl + CURRENCIES, currency.getCode());
    PutMethod method = new PutMethod(resource);
    try {//w w  w  .j  a  va2 s.c o  m
        String data = serialize(currency);
        method.setRequestEntity(new StringRequestEntity(data, MIME_TYPE_JSON, DEFAULT_CHAR_ENCODING));

        // Execute the HTTP Call
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return;
        }
        assertResponseCodeOK(method, statusCode);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}