protected void handleUnexpectedResponse(int statusCode, HttpResponse response) throws Exception { if (response == null) { return; } BufferedReader reader = new BufferedReader(new InputStreamReader(response.getContent())); StringBuilder responseBody = new StringBuilder(); String line = reader.readLine(); while (line != null) { responseBody.append(line); line = reader.readLine(); } switch (statusCode) { case 401: throw new OAuthNotAuthorizedException(responseBody.toString()); default: throw new OAuthCommunicationException("Service provider responded in error: " + statusCode + " (" + response.getReasonPhrase() + ")", responseBody.toString()); } }
/** * Return {@link OAuthConsumer} of the client for the current authorization. * * @return {@link OAuthConsumer} instance of the client * @throws OAuthNotAuthorizedException if the client is not authorized */ public final OAuthConsumer getAuthConsumer() throws OAuthNotAuthorizedException { if (oAuthConsumer == null) throw new OAuthNotAuthorizedException(); return oAuthConsumer; }
/** * Return {@link OAuthProvider} of the client for the current authorization. * * @return {@link OAuthProvider} instance of the client * @throws OAuthNotAuthorizedException if the client is not authorized */ public final OAuthProvider getAuthProvider() throws OAuthNotAuthorizedException { if (oAuthProvider == null) throw new OAuthNotAuthorizedException(); return oAuthProvider; }
protected void handleUnexpectedResponse(int statusCode, HttpResponse response) throws Exception { if (response == null) { return; } BufferedReader reader = new BufferedReader(new InputStreamReader(response.getContent())); StringBuilder responseBody = new StringBuilder(); String line = reader.readLine(); while (line != null) { responseBody.append(line); line = reader.readLine(); } switch (statusCode) { case 401: throw new OAuthNotAuthorizedException(responseBody.toString()); default: throw new OAuthCommunicationException("Service provider responded in error: " + statusCode + " (" + response.getReasonPhrase() + ")", responseBody.toString()); } }