Package org.scribe.model

Examples of org.scribe.model.Response


        this.service.signRequest(accessToken, request);
        // Let the client to decide if the token should be in header
        if (this.isTokenAsHeader()) {
            request.addHeader("Authorization", "Bearer " + accessToken.getToken());
        }
        final Response response = request.send();
        final int code = response.getCode();
        final String body = response.getBody();
        final long t1 = System.currentTimeMillis();
        logger.debug("Request took : " + (t1 - t0) + " ms for : " + dataUrl);
        logger.debug("response code : {} / response body : {}", code, body);
        if (code != 200) {
            logger.error("Failed to get data, code : " + code + " / body : " + body);
View Full Code Here


        if (LOG.isDebugEnabled()) {
            LOG.debug("Yammer request url: {}", request.getCompleteUrl());
        }
       
        Response response = request.send();
        if (response.isSuccessful()) {                   
            return response.getBody();
        } else {
            throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
        }
    }
View Full Code Here

  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());
View Full Code Here

  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());
View Full Code Here

            request.addHeader("If-Modified-Since", sinceFormatted);
            request.addQuerystringParameter("noEarlierThan", noEarlierFormatted);
        }
        service.signRequest(token, request);
        long then = System.currentTimeMillis();
        Response response = request.send();
        final int httpResponseCode = response.getCode();
        String body = response.getBody();
        if (httpResponseCode ==200) {
            JSONObject jsonObject = JSONObject.fromObject(body);
            final JSONArray items = jsonObject.getJSONArray("items");
            for(int i=0; i<items.size(); i++) {
                JSONObject item = items.getJSONObject(i);
View Full Code Here

        final String userEndpoint = url + accessToken;
        OAuthRequest request = new OAuthRequest(Verb.GET, userEndpoint);
        request.addHeader("Accept", "application/vnd.com.runkeeper.User+json");
        final OAuthService service = runKeeperController.getOAuthService();
        service.signRequest(token, request);
        Response response = request.send();
        final int httpResponseCode = response.getCode();
        long then = System.currentTimeMillis();
        String body = response.getBody();

        if (httpResponseCode==200) {
            JSONObject jsonObject = JSONObject.fromObject(body);
            String fitnessActivities = jsonObject.getString("fitness_activities");
            List<String> activities = new ArrayList<String>();
View Full Code Here

            OAuthRequest request = new OAuthRequest(Verb.GET, activityURL);
            request.addQuerystringParameter("oauth_token", token.getToken());
            request.addHeader("Accept", "application/vnd.com.runkeeper.FitnessActivity+json");
            service.signRequest(token, request);
            long then = System.currentTimeMillis();
            Response response = request.send();
            final int httpResponseCode = response.getCode();
            String body = response.getBody();
            if (httpResponseCode ==200) {
                countSuccessfulApiCall(updateInfo.apiKey,
                                       updateInfo.objectTypes, then, activityURL);
                JSONObject jsonObject = JSONObject.fromObject(body);
                createOrUpdateActivity(jsonObject, updateInfo);
View Full Code Here

            }
            OAuthService service = getOAuthService(updateInfo.apiKey);
            final String accessToken = guestService.getApiKeyAttribute(updateInfo.apiKey, "accessToken");
            final Token token = new Token(accessToken, guestService.getApiKeyAttribute(updateInfo.apiKey, "tokenSecret"));
            service.signRequest(token, request);
            Response response = request.send();
            httpResponseCode = response.getCode();
            if (httpResponseCode!=200)
                throw new UpdateFailedException("Unexpected response code: " + httpResponseCode);
            String json = response.getBody();
            JSONObject jsonObject = JSONObject.fromObject(json);
            final int withingsStatusCode = jsonObject.getInt("status");
            String message = null;
            if (withingsStatusCode !=0) {
                switch (withingsStatusCode) {
View Full Code Here

      service.signRequest(accessToken, request);
      request.setConnectionKeepAlive(true);
      request.setConnectTimeout(10, TimeUnit.SECONDS);
      request.setReadTimeout(30, TimeUnit.SECONDS);
      request.setCharset("UTF-8");
      Response response = null;

      try {
        response = request.send();
      } catch (OAuthConnectionException e) {
        throw e;
      }

      String responseBody = response.getBody();
      if (response.isSuccessful()) {
        return responseBody + "\n";
      } else {
        if (response.getCode() == 401) {
          _log.warn("Response error: " + response.getCode());
          System.err.println(responseBody);
          if (i == 0) {
            refreshAccessToken();
          } else {
            throw new OAuthAuthenticationException("Unauthorized");
          }
        } else {
          _log.error(method + " " + request.getCompleteUrl());
          _log.error(postBody);
          _log.error("HTTP response code: " + response.getCode());
          _log.error("Response: " + responseBody);
          if (responseBody.contains("Deadlock found when trying to get lock; try restarting transaction")
              || responseBody.contains("nested exception is org.hibernate.exception.LockAcquisitionException: could not execute statement")) {
            throw new PleaseRetryException(responseBody);
          } else
View Full Code Here

    OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), this.refreshTokenEndpoint);
    request.addQuerystringParameter(OAuthConstants.CLIENT_ID, apiKey);
    request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, apiSecret);
    request.addQuerystringParameter("grant_type", "refresh_token");
    request.addQuerystringParameter("refresh_token", refreshToken.getToken());
    Response response = request.send();
    return getAccessTokenExtractor().extract(response.getBody());
  }
View Full Code Here

TOP

Related Classes of org.scribe.model.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.