}
private void respondWithError(HttpServletResponse resp, OAuthProblemException error)
throws IOException, ServletException {
OAuthResponse oauthResponse = null;
try {
if (OAuthUtils.isEmpty(error.getError())) {
oauthResponse = OAuthRSResponse.errorResponse(HttpServletResponse.SC_UNAUTHORIZED)
.setRealm(realm)
.buildHeaderMessage();
} else {
int responseCode = 401;
if (error.getError().equals(OAuthError.CodeResponse.INVALID_REQUEST)) {
responseCode = 400;
} else if (error.getError().equals(OAuthError.ResourceResponse.INSUFFICIENT_SCOPE)) {
responseCode = 403;
}
oauthResponse = OAuthRSResponse
.errorResponse(responseCode)
.setRealm(realm)
.setError(error.getError())
.setErrorDescription(error.getDescription())
.setErrorUri(error.getUri())
.buildHeaderMessage();
}
resp.addHeader(OAuth.HeaderType.WWW_AUTHENTICATE,
oauthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE));
resp.sendError(oauthResponse.getResponseStatus());
} catch (OAuthSystemException e) {
throw new ServletException(e);
}
}