Example usage for org.apache.commons.httpclient.auth AuthenticationException getMessage

List of usage examples for org.apache.commons.httpclient.auth AuthenticationException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.auth AuthenticationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.esri.gpt.control.search.ServletSavedSearch.java

/**
 * Execute./*  ww w  .  j a  va2  s. c  o  m*/
 * 
 * @param request the request
 * @param response the response
 * @param context the context
 * @throws Exception the exception
 */
@Override
protected void execute(HttpServletRequest request, HttpServletResponse response, RequestContext context)
        throws Exception {

    try {
        if (context.getUser().getName().equals("")) {
            throw new AuthenticationException("Login needed");
        }
        if (request.getMethod().toLowerCase().equals("get")) {
            writeSavedSearches(request, response, context);
        } else if (request.getMethod().toLowerCase().equals("put")
                || request.getMethod().toLowerCase().equals("post")) {
            putSavedSearches(request, response, context);
        } else if (request.getMethod().toLowerCase().equals("delete")) {
            deleteSavedSearch(request, response, context);
        }

    } catch (AuthenticationException e) {
        response.sendError(404, "User principle not found.  Try authenticating.");
        LOG.log(Level.INFO, "Tried to get saved search but principle not found for " + request.getRemoteAddr(),
                e);
    } catch (Throwable e) {
        response.sendError(500, e.getMessage());
        LOG.log(Level.WARNING, "Error while interacting with saved searches", e);
    }

}

From source file:org.review_board.ereviewboard.core.client.ReviewboardHttpClient.java

public String login(String username, String password, IProgressMonitor monitor) throws ReviewboardException {

    GetMethod loginRequest = new GetMethod(location.getUrl() + "/api/info/");
    Credentials credentials = new UsernamePasswordCredentials(username, password);

    monitor = Policy.monitorFor(monitor);

    String foundSessionCookie = null;

    try {//from ww  w.ja v  a 2  s  . c  om
        monitor.beginTask("Logging in", IProgressMonitor.UNKNOWN);

        // TODO: this will probably affect existing requests, might have ill side-effects
        httpClient.getState().clearCookies();

        // perform authentication
        String authHeader = new BasicScheme().authenticate(credentials, loginRequest);
        loginRequest.addRequestHeader("Authorization", authHeader);

        // execute and validate call
        int requestStatus = executeRequest(loginRequest, monitor);

        switch (requestStatus) {

        case HttpStatus.SC_OK:
            break;
        case HttpStatus.SC_UNAUTHORIZED:
            throw new ReviewboardException("Authentication failed, please check your username and password");
        default:
            throw new ReviewboardException("Request returned unacceptable status code " + requestStatus);
        }

        // look for session cookie
        for (Cookie cookie : httpClient.getState().getCookies())
            if (cookie.getName().equals("rbsessionid"))
                foundSessionCookie = cookie.getValue();

        if (foundSessionCookie == null)
            throw new ReviewboardException("Did not find session cookie in response");

        return foundSessionCookie;

    } catch (AuthenticationException e) {
        throw new ReviewboardException(e.getMessage(), e);
    } finally {
        loginRequest.releaseConnection();
        monitor.done();
    }
}