public static void saveAccessToken(HttpServletRequest request, OAuthService service, Token accessToken) throws Exception {
OAuthRequest _request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, _request);
Response _response = _request.send();
if (_response.getCode() != 200)
throw new OAuthException("Can query account information.");
String contentType = _response.getHeader("Content-Type");
if (contentType == null) contentType = "";
//String charset = "";
int semicolonPos = contentType.indexOf(';');
if (semicolonPos > 0) {
String _charset = contentType.substring(semicolonPos + 1).trim();
if (_charset.startsWith("charset")) {
//charset =
_charset.substring(_charset.indexOf('=') + 1);
}
contentType = contentType.substring(0, semicolonPos);
}
Map<String, String> responseAttributes = null;
String response = _response.getBody();
if ("application/json".equals(contentType) || (response.startsWith("{") && response.endsWith("}"))) {
JSONObject jsonResponse = new JSONObject(response);
if (jsonResponse != null) {
if (jsonResponse.has("error")) {
throw new OAuthException("Error getting access token: " + System.getProperty("line.separator") + jsonResponse.toString());