Search in sources :

Example 1 with ServiceClientHTTPException

use of edu.uiuc.ncsa.security.servlet.ServiceClientHTTPException in project OA4MP by ncsa.

the class OA2ClientExceptionHandler method handleException.

@Override
public void handleException(Throwable t, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    if (t instanceof OA2RedirectableError) {
        getLogger().info("get a standard error with a redirect");
        OA2RedirectableError oa2RedirectableError = (OA2RedirectableError) t;
        request.setAttribute(OA2Constants.ERROR, oa2RedirectableError.getError());
        request.setAttribute(OA2Constants.ERROR_DESCRIPTION, oa2RedirectableError.getDescription());
        request.setAttribute(OA2Constants.STATE, oa2RedirectableError.getState());
    } else if (t instanceof ServiceClientHTTPException) {
        // This can be thrown by the service client when a bad response comes back from the server.
        // If there really is server problem, this tries to get a human readable error page.
        // parse the body. It should be of the form
        // error=....
        // error_description=...
        // separated by a line feed.
        ServiceClientHTTPException tt = (ServiceClientHTTPException) t;
        getLogger().info("got standard error with http status code = " + tt.getStatus());
        if (!tt.hasContent()) {
            // can't do anything
            defaultSCXresponse(tt, request);
        } else {
            try {
                parseContent(tt.getContent(), request);
            } catch (GeneralException xx) {
                defaultSCXresponse(tt, request);
            }
        }
    } else {
        // fall through. We got some exception from someplace and have to manage it.
        // This is really last ditch.
        getLogger().info("Got exception of type " + t.getClass().getSimpleName());
        // again, something is wrong, possibly with the configuration so more info is better.
        t.printStackTrace();
        request.setAttribute(OA2Constants.ERROR, t.getClass().getSimpleName());
        request.setAttribute(OA2Constants.ERROR_DESCRIPTION, t.getMessage());
    }
    // sets return action on error page to this web app.
    request.setAttribute("action", request.getContextPath());
    JSPUtil.fwd(request, response, clientServlet.getCE().getErrorPagePath());
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ServiceClientHTTPException(edu.uiuc.ncsa.security.servlet.ServiceClientHTTPException) OA2RedirectableError(edu.uiuc.ncsa.security.oauth_2_0.OA2RedirectableError)

Aggregations

GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 OA2RedirectableError (edu.uiuc.ncsa.security.oauth_2_0.OA2RedirectableError)1 ServiceClientHTTPException (edu.uiuc.ncsa.security.servlet.ServiceClientHTTPException)1