Java Code Examples for org.scribe.model.Response#getBody()
The following examples show how to use
org.scribe.model.Response#getBody() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 7 votes |
public SampleEntity retrieveEntitySample1(Token accessToken) throws ClientException { OAuthService service = getOAuthService(scopes, null); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:9998/testsuite/rest/sample/1"); service.signRequest(accessToken, request); Response response = request.send(); if (response.getCode()!=200) throwClientException(response); ObjectMapper mapper = new ObjectMapper(); try { SampleEntity entity = mapper.readValue(response.getBody(), SampleEntity.class); return entity; } catch (IOException e) { throw new ClientException(response.getBody()); } }
Example 2
Source File: RequestBuilder.java From jumblr with Apache License 2.0 | 6 votes |
ResponseWrapper clear(Response response) { if (response.getCode() == 200 || response.getCode() == 201) { String json = response.getBody(); try { Gson gson = new GsonBuilder(). registerTypeAdapter(JsonElement.class, new JsonElementDeserializer()). create(); ResponseWrapper wrapper = gson.fromJson(json, ResponseWrapper.class); if (wrapper == null) { throw new JumblrException(response); } wrapper.setClient(client); return wrapper; } catch (JsonSyntaxException ex) { throw new JumblrException(response); } } else { throw new JumblrException(response); } }
Example 3
Source File: RequestBuilder.java From jumblr with Apache License 2.0 | 6 votes |
private Token parseXAuthResponse(final Response response) { String responseStr = response.getBody(); if (responseStr != null) { // Response is received in the format "oauth_token=value&oauth_token_secret=value". String extractedToken = null, extractedSecret = null; final String[] values = responseStr.split("&"); for (String value : values) { final String[] kvp = value.split("="); if (kvp != null && kvp.length == 2) { if (kvp[0].equals("oauth_token")) { extractedToken = kvp[1]; } else if (kvp[0].equals("oauth_token_secret")) { extractedSecret = kvp[1]; } } } if (extractedToken != null && extractedSecret != null) { return new Token(extractedToken, extractedSecret); } } // No good throw new JumblrException(response); }
Example 4
Source File: JumblrException.java From jumblr with Apache License 2.0 | 6 votes |
/** * Instantiate a new JumblrException given a bad response to wrap * @param response the response to wrap */ public JumblrException(Response response) { this.responseCode = response.getCode(); String body = response.getBody(); JsonParser parser = new JsonParser(); try { final JsonElement element = parser.parse(body); if (element.isJsonObject()) { JsonObject object = element.getAsJsonObject(); this.extractMessage(object); this.extractErrors(object); } else { this.message = body; } } catch (JsonParseException ex) { this.message = body; } }
Example 5
Source File: FacebookAPI.java From mamute with Apache License 2.0 | 5 votes |
public String getUserId() { String url = "https://graph.facebook.com/me?fields=id"; Response response = makeRequest(url); String body = response.getBody(); JsonObject jsonObj = new JsonParser().parse(body).getAsJsonObject(); JsonElement jsonElement = jsonObj.get("id"); if (jsonElement == null) { throw new IllegalArgumentException("facebook did not sent data requested! response body: " + body); } return jsonElement.getAsString(); }
Example 6
Source File: FacebookAPI.java From mamute with Apache License 2.0 | 5 votes |
private Response makeRequest(String url) { OAuthRequest request = new OAuthRequest(Verb.GET, url); service.signRequest(accessToken, request); Response response = request.send(); String body = response.getBody(); if (response.getCode() / 100 != 2) { throw new IllegalArgumentException("http error: " + response.getCode() + ", facebook response body: " + body); } return response; }
Example 7
Source File: DataUploadService.java From open with GNU General Public License v3.0 | 5 votes |
public String getPermissionResponse() { try { OAuthRequest request = requestFactory.getPermissionsRequest(); app.getOsmOauthService().signRequest(app.getAccessToken(), request); Response response = request.send(); return response.getBody(); } catch (Exception e) { Logger.d("Unable to get permissions"); } return null; }
Example 8
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 5 votes |
public String sendTestRequestSample1(Token accessToken) throws ClientException { OAuthService service = getOAuthService(scopes, null); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:9998/testsuite/rest/sample/1"); service.signRequest(accessToken, request); Response response = request.send(); if (response.getCode()!=200) throwClientException(response); return response.getBody(); }
Example 9
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 5 votes |
public String sendTestRequestSample2(Token accessToken) throws ClientException { OAuthService service = getOAuthService(null, null); OAuthRequest request = new OAuthRequest(Verb.GET, "http://localhost:9998/testsuite/rest/sample2/1"); service.signRequest(accessToken, request); Response response = request.send(); if (response.getCode()!=200) throwClientException(response); return response.getBody(); }
Example 10
Source File: ResourceClient.java From jerseyoauth2 with MIT License | 4 votes |
protected void throwClientException(Response response) throws ClientException { int code = response.getCode(); String body = response.getBody(); throw new ClientException(Integer.toString(code)+" "+body); }