org.scribe.model.Response.getCode()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(82)

本文整理了Java中org.scribe.model.Response.getCode方法的一些代码示例,展示了Response.getCode的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getCode方法的具体详情如下:
包路径:org.scribe.model.Response
类名称:Response
方法名:getCode

Response.getCode介绍

[英]Obtains the HTTP status code
[中]获取HTTP状态代码

代码示例

代码示例来源:origin: google/data-transfer-project

private <T> SmugMugResponse<T> makeRequest(
  String url, TypeReference<SmugMugResponse<T>> typeReference) throws IOException {
 // Note: there are no request params that need to go here, because smugmug fully specifies
 // which resource to get in the URL of a request, without using query params.
 String fullUrl;
 if (!url.contains("https://")) {
  fullUrl = BASE_URL + url;
 } else {
  fullUrl = url;
 }
 OAuthRequest request =
   new OAuthRequest(Verb.GET, fullUrl + "?_accept=application%2Fjson");
 oAuthService.signRequest(accessToken, request);
 final Response response = request.send();
 if (response.getCode() < 200 || response.getCode() >= 300) {
  throw new IOException(
    String.format("Error occurred in request for %s : %s", url, response.getMessage()));
 }
 String result = response.getBody();
 return mapper.readValue(result, typeReference);
}

代码示例来源:origin: google/data-transfer-project

if (response.getCode() < 200 || response.getCode() >= 300) {
 throw new IOException(
   String.format("Error occurred in request for %s : %s", fullUrl, response.getMessage()));

代码示例来源:origin: de.esoco/esoco-oauth

/***************************************
 * {@inheritDoc}
 */
@Override
public int getCode()
{
  return rResponse.getCode();
}

代码示例来源:origin: org.scribe/scribe

public boolean isSuccessful()
{
 return getCode() >= 200 && getCode() < 400;
}

代码示例来源:origin: tumblr/jumblr

/* package-visible for testing */ Token clearXAuth(Response response) {
  if (response.getCode() == 200 || response.getCode() == 201) {
    return parseXAuthResponse(response);
  } else {
    throw new JumblrException(response);
  }
}

代码示例来源:origin: org.jboss.seam.social/seam-social

@Override
public int getCode() {
  return getDelegate().getCode();
}

代码示例来源:origin: tumblr/jumblr

/* package-visible for testing */ 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);
  }
}

代码示例来源:origin: org.apache.camel/camel-yammer

private String send(Verb verb, String params) throws Exception {
  String url = apiUrl + ((params != null) ? params : "");
  
  OAuthRequest request = new OAuthRequest(verb, url);
  request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
  
  // For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23
  StringBuilder sb = new StringBuilder();
  sb.append("Bearer ");
  sb.append(apiAccessToken);
  request.addHeader("Authorization",  sb.toString());
  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()));
  }
}

代码示例来源:origin: hoverruan/weiboclient4j

public static <T> List<T> parseJsonObject(Response response, TypeReference<List<T>> type)
    throws WeiboClientException {
  if (response.isSuccessful()) {
    return parseJsonObject(response.getCode(), response.getBody(), type);
  } else {
    throw createException(response);
  }
}

代码示例来源:origin: hoverruan/weiboclient4j

public static <T> T parseJsonObject(Response response, Class<T> clazz) throws WeiboClientException {
  if (response.isSuccessful()) {
    return parseJsonObject(response.getCode(), response.getBody(), clazz);
  } else {
    throw createException(response);
  }
}

代码示例来源:origin: tumblr/jumblr

public String getRedirectUrl(String path) {
  OAuthRequest request = this.constructGet(path, null);
  sign(request);
  boolean presetVal = HttpURLConnection.getFollowRedirects();
  HttpURLConnection.setFollowRedirects(false);
  Response response = request.send();
  HttpURLConnection.setFollowRedirects(presetVal);
  if (response.getCode() == 301 || response.getCode() == 302) {
    return response.getHeader("Location");
  } else {
    throw new JumblrException(response);
  }
}

代码示例来源:origin: hburgmeier/jerseyoauth2

protected void throwClientException(Response response) throws ClientException
{
  int code = response.getCode();
  String body = response.getBody();
  throw new ClientException(Integer.toString(code)+" "+body);
}

代码示例来源:origin: hoverruan/weiboclient4j

private static WeiboClientException createException(Response response) {
  String body = response.getBody();
  int code = response.getCode();
  if (isNotBlank(body)) {
    try {
      WeiboError error = readValue(body, WeiboError.class);
      return new WeiboClientException(code, body, error);
    } catch (IOException e) {
      return new WeiboClientException(code, body, e);
    }
  } else {
    return new WeiboClientException(code);
  }
}

代码示例来源:origin: hburgmeier/jerseyoauth2

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());
  }
}

代码示例来源:origin: hburgmeier/jerseyoauth2

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();
}

代码示例来源:origin: hburgmeier/jerseyoauth2

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();
}

代码示例来源:origin: org.scribe/scribe

public Token getRequestToken(RequestTuner tuner)
{
 config.log("obtaining request token from " + api.getRequestTokenEndpoint());
 OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint());
 config.log("setting oauth_callback to " + config.getCallback());
 request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
 addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
 appendSignature(request);
 config.log("sending request...");
 Response response = request.send(tuner);
 String body = response.getBody();
 config.log("response status code: " + response.getCode());
 config.log("response body: " + body);
 return api.getRequestTokenExtractor().extract(body);
}

代码示例来源:origin: org.scribe/scribe-up

@Override
public Token getRequestToken() {
  this.config.log("obtaining request token from " + this.api.getRequestTokenEndpoint());
  final OAuthRequest request = new ProxyOAuthRequest(this.api.getRequestTokenVerb(),
                            this.api.getRequestTokenEndpoint(), this.proxyHost,
                            this.proxyPort);
  
  this.config.log("setting oauth_callback to " + this.config.getCallback());
  request.addOAuthParameter(OAuthConstants.CALLBACK, this.config.getCallback());
  addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
  appendSignature(request);
  
  this.config.log("sending request...");
  final Response response = request.send();
  final String body = response.getBody();
  
  this.config.log("response status code: " + response.getCode());
  this.config.log("response body: " + body);
  return this.api.getRequestTokenExtractor().extract(body);
}

代码示例来源:origin: org.scribe/scribe

public Token getAccessToken(Token requestToken, Verifier verifier, RequestTuner tuner)
{
 config.log("obtaining access token from " + api.getAccessTokenEndpoint());
 OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
 request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken());
 request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue());
 config.log("setting token to: " + requestToken + " and verifier to: " + verifier);
 addOAuthParams(request, requestToken);
 appendSignature(request);
 
 config.log("sending request...");
 Response response = request.send(tuner);
 String body = response.getBody();
 
 config.log("response status code: " + response.getCode());
 config.log("response body: " + body);
 return api.getAccessTokenExtractor().extract(body);
}

代码示例来源:origin: com.atlassian.jira.plugins/bitbucket-client

/**
 * {@inheritDoc}
 */
@Override
public Token getRequestToken() {
  config.log("obtaining request token from " + api.getRequestTokenEndpoint());
  OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint());
  config.log("setting oauth_callback to " + config.getCallback());
  request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
  addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
  appendSignature(request);
  config.log("sending request...");
  Response response = request.send();
  String body = response.getBody();
  config.log("response status code: " + response.getCode());
  config.log("response body: " + body);
  return api.getRequestTokenExtractor().extract(body);
}

相关文章

微信公众号

最新文章

更多