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.users.client.UserServiceClientHTTP.java

@Override
public void setUserStatus(Long userId, UserStatus status) {
    String resource = String.format(baseUrl + SET_STATUS, userId);
    PutMethod method = new PutMethod(resource);
    try {/*from ww  w  .  j  a v a2  s . c o m*/
        ChangeUserStatusRequest request = new ChangeUserStatusRequest();
        request.setUserStatus(status);
        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 AccountQueryResult listAccounts(ListAccountsRequest request) {
    String uri = baseUrl + ACCOUNTS;
    PutMethod method = new PutMethod(uri);
    try {/*  ww w. ja va 2s  .  co  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, AccountQueryResult.class);

        } else {
            throw new RuntimeException(
                    "Failed to list accounts, RESPONSE CODE: " + statusCode + " url: " + uri);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed listing accounts via url " + uri, e);
    } finally {
        method.releaseConnection();
    }
}

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

@Override
public void updateUser(User user) {
    String resource = String.format(baseUrl + USER, user.getUserId());
    PutMethod method = new PutMethod(resource);
    try {//from   ww  w .  j av  a  2  s  .  c  om
        String data = serialize(user);
        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:it.geosolutions.figis.requester.HTTPUtils.java

/**
* Used to query for REST resources./*from   ww w  . jav a 2  s .co m*/
*
* @param url The URL of the REST resource to query about.
* @param username
* @param pw
* @return true on 200, false on 404.
* @throws RuntimeException on unhandled status or exceptions.
*/
public static boolean exists(String url, String username, String pw) {

    GetMethod httpMethod = null;

    try {
        HttpClient client = new HttpClient();
        setAuth(client, url, username, pw);
        httpMethod = new GetMethod(url);
        client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);

        int status = client.executeMethod(httpMethod);
        switch (status) {
        case HttpStatus.SC_OK:
            return true;
        case HttpStatus.SC_NOT_FOUND:
            return false;
        default:
            throw new RuntimeException("Unhandled response status at '" + url + "': (" + status + ") "
                    + httpMethod.getStatusText());
        }
    } catch (ConnectException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (httpMethod != null) {
            httpMethod.releaseConnection();
        }
    }
}

From source file:co.cask.cdap.data2.datafabric.dataset.service.DatasetServiceTestBase.java

protected void assertNamespaceNotFound(HttpResponse response, Id.Namespace namespaceId) {
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
    Assert.assertTrue(response.getResponseBodyAsString().contains(namespaceId.toString()));
}

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

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

    try {//from   w ww . j a v  a  2s .  co m
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return null;
        }
        assertResponseCodeOK(method, statusCode);
        return new String(method.getResponseBody());

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

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

@Override
public EntriesQueryResult listEntries(ListEntriesRequest request) {
    String uri = baseUrl + ENTRIES;
    PutMethod method = new PutMethod(uri);
    try {/*ww  w. j  a  va  2s.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, EntriesQueryResult.class);

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

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

From source file:it.geosolutions.geoserver.rest.HTTPUtils.java

/**
 * Used to query for REST resources.//from  w w  w  .j  av a 2s  .  co  m
 * 
 * @param url The URL of the REST resource to query about.
 * @param username
 * @param pw
 * @return true on 200, false on 404.
 * @throws RuntimeException on unhandled status or exceptions.
 */
public static boolean exists(String url, String username, String pw) {

    GetMethod httpMethod = null;
    HttpClient client = new HttpClient();
    HttpConnectionManager connectionManager = client.getHttpConnectionManager();
    try {
        setAuth(client, url, username, pw);
        httpMethod = new GetMethod(url);
        connectionManager.getParams().setConnectionTimeout(2000);
        int status = client.executeMethod(httpMethod);
        switch (status) {
        case HttpStatus.SC_OK:
            return true;
        case HttpStatus.SC_NOT_FOUND:
            return false;
        default:
            throw new RuntimeException("Unhandled response status at '" + url + "': (" + status + ") "
                    + httpMethod.getStatusText());
        }
    } catch (ConnectException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (httpMethod != null)
            httpMethod.releaseConnection();
        connectionManager.closeIdleConnections(0);
    }
}

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

@Override
public void setUserAvatarId(Long userId, String avatarId) {
    String resource = String.format(baseUrl + USER_AVATARID, userId);
    PutMethod method = new PutMethod(resource);
    try {//from w ww  . j  a va  2 s . c  o m
        ChangeUserAvatarIdRequest request = new ChangeUserAvatarIdRequest();
        request.setUserAvatarId(avatarId);
        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:it.geosolutions.geonetwork.util.HTTPUtils.java

/**
 * Used to query for REST resources./*from   w ww . ja  v a 2  s .  co  m*/
 *
 * @param url The URL of the REST resource to query about.
 * @param username
 * @param pw
 * @return true on 200, false on 404.
 * @throws RuntimeException on unhandled status or exceptions.
 */
public boolean exists(String url) {

    GetMethod httpMethod = null;

    try {
        //         HttpClient client = new HttpClient();
        setAuth(client, url, username, pw);
        httpMethod = new GetMethod(url);
        client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
        lastHttpStatus = client.executeMethod(httpMethod);
        switch (lastHttpStatus) {
        case HttpStatus.SC_OK:
            return true;
        case HttpStatus.SC_NOT_FOUND:
            return false;
        default:
            throw new RuntimeException("Unhandled response status at '" + url + "': (" + lastHttpStatus + ") "
                    + httpMethod.getStatusText());
        }
    } catch (ConnectException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (httpMethod != null)
            httpMethod.releaseConnection();
    }
}