本文整理了Java中org.scribe.model.Response.getBody
方法的一些代码示例,展示了Response.getBody
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getBody
方法的具体详情如下:
包路径:org.scribe.model.Response
类名称:Response
方法名:getBody
[英]Obtains the HTTP Response body
[中]获取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
return mapper.readValue(response.getBody(), typeReference);
代码示例来源:origin: multidots/android-app-common-tasks
@Override
protected Void doInBackground(String... params) {
System.out.println("001 OauthEnd doInBackground-->" + params[0]);
String url = params[0];
if (url.contains("user_refused")) {
setResult(RESULT_CANCELED);
finish();
} else {
final Uri uri = Uri.parse(url);
final String verifier = uri.getQueryParameter("oauth_verifier");
final Verifier v = new Verifier(verifier);
System.out.println("hp Verifier>>>> " + v.getValue());
final Token accessToken = oas_linkedin.getAccessToken(requestToken,
v);
final OAuthRequest request = new OAuthRequest(Verb.GET,
PROTECTED_RESOURCE_URL);
oas_linkedin.signRequest(accessToken, request);
Response response = request.send();
// TODO JSON response in intent RESPONSE
Intent intent = new Intent();
intent.putExtra("RESPONSE", response.getBody());
setResult(RESULT_OK, intent);
finish();
}
return null;
}
}
代码示例来源:origin: multidots/android-app-common-tasks
@Override
protected Void doInBackground(String... params) {
System.out.println("001 OauthEnd doInBackground-->" + params[0]);
String url = params[0];
if (url.contains("user_refused")) {
setResult(RESULT_CANCELED);
finish();
} else {
final Uri uri = Uri.parse(url);
final String verifier = uri.getQueryParameter("oauth_verifier");
final Verifier v = new Verifier(verifier);
System.out.println("hp Verifier>>>> " + v.getValue());
final Token accessToken = oas_linkedin.getAccessToken(requestToken,
v);
final OAuthRequest request = new OAuthRequest(Verb.GET,
PROTECTED_RESOURCE_URL);
oas_linkedin.signRequest(accessToken, request);
Response response = request.send();
// TODO JSON response in intent RESPONSE
Intent intent = new Intent();
intent.putExtra("RESPONSE", response.getBody());
setResult(RESULT_OK, intent);
finish();
}
return null;
}
}
代码示例来源:origin: bill1012/AdminEAP
@Override
public OAuthUser getOAuthUser(Token accessToken) {
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
this.signRequest(accessToken, request);
Response response = request.send();
OAuthUser oAuthUser = new OAuthUser();
oAuthUser.setoAuthType(getoAuthType());
Object result = JSON.parse(response.getBody());
oAuthUser.setoAuthId(JSONPath.eval(result, "$.id").toString());
oAuthUser.setUserName(JSONPath.eval(result, "$.login").toString());
return oAuthUser;
}
代码示例来源:origin: de.esoco/esoco-oauth
/***************************************
* {@inheritDoc}
*/
@Override
public String getData()
{
return rResponse.getBody();
}
代码示例来源:origin: org.jboss.seam.social/seam-social
@Override
public String getBody() {
return getDelegate().getBody();
}
代码示例来源: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: 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: 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: jenkinsci/bitbucket-build-status-notifier-plugin
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addHeader(OAuthConstants.HEADER, this.getHttpBasicAuthHeaderValue());
request.addBodyParameter(GRANT_TYPE_KEY, GRANT_TYPE_CLIENT_CREDENTIALS);
Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody());
}
代码示例来源:origin: alrocar/POIProxy
@Override
public byte[] download(String URL, String fileName, String downloadPath,
Auth authElem) throws Exception {
AuthTypeEnum authType = AuthTypeEnum.valueOf(authElem.getType());
OAuthService service = new ServiceBuilder().provider(authType._class)
.apiKey(authElem.getApiKey())
.apiSecret(authElem.getApiSecret()).build();
OAuthRequest request = new OAuthRequest(Verb.GET, URL);
Token myToken = new Token(authElem.getAccessToken(),
authElem.getAccessTokenSecret());
service.signRequest(myToken, request);
Response response = request.send();
return response.getBody().getBytes();
}
}
代码示例来源: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: 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: org.scribe/scribe-up
@Override
public Token getAccessToken(final Token requestToken, final Verifier verifier) {
this.config.log("obtaining access token from " + this.api.getAccessTokenEndpoint());
final ProxyOAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
this.api.getAccessTokenEndpoint(), this.proxyHost,
this.proxyPort);
request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken());
request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue());
this.config.log("setting token to: " + requestToken + " and verifier to: " + verifier);
addOAuthParams(request, requestToken);
appendSignature(request);
final Response response = request.send();
return this.api.getAccessTokenExtractor().extract(response.getBody());
}
代码示例来源:origin: com.atlassian.jira.plugins/bitbucket-client
/**
* {@inheritDoc}
*/
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
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);
Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody());
}
代码示例来源:origin: hburgmeier/jerseyoauth2
@Override
public Token refreshToken(OAuth2Token token) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addQuerystringParameter("refresh_token", token.getRefreshToken());
if(config.hasScope())
request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody());
}
代码示例来源:origin: org.scribe/scribe
/**
* {@inheritDoc}
*/
public Token getAccessToken(Token requestToken, Verifier verifier)
{
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
return api.getAccessTokenExtractor().extract(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);
}
内容来源于网络,如有侵权,请联系作者删除!