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());
}
Aggregations