当前位置: 首页>>代码示例>>Java>>正文


Java Response.getBody方法代码示例

本文整理汇总了Java中com.github.scribejava.core.model.Response.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getBody方法的具体用法?Java Response.getBody怎么用?Java Response.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.scribejava.core.model.Response的用法示例。


在下文中一共展示了Response.getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
    if (credential instanceof TokenResponseCredential) {
        TokenResponseCredential tokenCredential = (TokenResponseCredential) credential;

        OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v3/userinfo");

        OAuth20Service service = tokenCredential.getService();
        OAuth2AccessToken token = tokenCredential.getTokenResponse();
        service.signRequest(token, request);

        try {
            Response oResp = service.execute(request);
            String body = oResp.getBody();

            OAuth2User oAuth2User = jsonProcessor.extractUserInfo(body);

            return new CredentialValidationResult(oAuth2User);

        } catch (InterruptedException | ExecutionException | IOException e) {
            e.printStackTrace(); // FIXME
        }

    }
    return CredentialValidationResult.NOT_VALIDATED_RESULT;
}
 
开发者ID:atbashEE,项目名称:jsr375-extensions,代码行数:27,代码来源:DemoIdentityStore.java

示例2: sendRequestForData

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
/**
 * Make a request to get the data of the authenticated user for the provider.
 *
 * @param accessToken the access token
 * @param dataUrl     url of the data
 * @return the user data response
 */
protected String sendRequestForData(final T accessToken, final String dataUrl) {
    logger.debug("accessToken: {} / dataUrl: {}", accessToken, dataUrl);
    final long t0 = System.currentTimeMillis();
    final OAuthRequest request = createOAuthRequest(dataUrl);
    signRequest(accessToken, request);
    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) {
        throw new HttpCommunicationException(code, body);
    }
    return body;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:24,代码来源:BaseOAuthClient.java

示例3: loadOAuthProviderAccount

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {
	OAuthService service = this.getService();

	// getting user profile
	OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, config.getProfileUrl(), service);
	service.signRequest(accessToken, oauthRequest); // the access token from step 4

	Response oauthResponse = oauthRequest.send();

	String jsonString = oauthResponse.getBody();
	JSONObject root = new JSONObject(jsonString);

	String accountId = String.valueOf(root.getInt(TWITTER_ACCTID_PROPERTY)); 
	String displayName = root.getString(TWITTER_DISPLAYNAME_PROPERTY);
	String publicId = root.getString(TWITTER_SCREENNAME_PROPERTY); 
	String profilePath = provider.getIdProviderUrl() + "/" + publicId; 
	
	OAuthProviderAccount profile = 
			new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);

	return profile;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:23,代码来源:TwitterOAuthProvider.java

示例4: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
private AccountData parseJSON(Response response) throws JSONException{
    AccountData accountData = new AccountData();
    JSONObject json = new JSONObject();
    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonAccountBal = new JSONObject();
    JSONObject jsonMoney = new JSONObject();
    JSONObject jsonSecurities = new JSONObject();
    JSONObject jsonBuyPower = new JSONObject();

    json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonAccountBal = jsonResponse.getJSONObject(GET_ACCOUNT_BAL);
    jsonMoney = jsonAccountBal.getJSONObject(GET_MONEY);
    jsonSecurities = jsonAccountBal.getJSONObject(GET_SECURITIES);
    jsonBuyPower = jsonAccountBal.getJSONObject(GET_BUYING_POWER);

    accountData.setCashAvailable(jsonMoney.getDouble("cashavailable"));
    accountData.setAccountValue(jsonAccountBal.getDouble("accountvalue"));
    accountData.setUnsettledFunds(jsonMoney.getDouble("unsettledfunds"));
    accountData.setOptionValue(jsonSecurities.getDouble("options"));
    accountData.setStockValue(jsonSecurities.getDouble("stocks"));
    accountData.setUnclearedDeposits(jsonMoney.getDouble("uncleareddeposits"));
    //accountData.setBuyingPower(jsonBuyPower.getDouble("options"));

    return accountData;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseAccountData.java

示例5: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public StockQuote parseJSON(Response response) throws JSONException{
    StockQuote quote = new StockQuote(symbol);
    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonQuotes = new JSONObject();
    JSONObject jsonQuote = new JSONObject();

    JSONObject json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonQuotes = jsonResponse.getJSONObject(GET_QUOTES);
    jsonQuote = jsonQuotes.getJSONObject(GET_QUOTE);

    quote.setStockQuoteData(
            jsonQuote.getDouble("last"),
            jsonQuote.getDouble("ask"),
            jsonQuote.getDouble("asksz"),
            jsonQuote.getDouble("bid"),
            jsonQuote.getDouble("bidsz"),
            jsonQuote.getDouble("hi"),
            jsonQuote.getDouble("lo"),
            jsonQuote.getLong("vl"),
            jsonQuote.getLong("incr_vl"),
            jsonQuote.getLong("timestamp"));

    return quote;

}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseStockQuote.java

示例6: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
private MarketDay parseJSON(Response response) throws JSONException {
    MarketDay marketDay = new MarketDay();
    JSONObject json = new JSONObject();
    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonQuotes = new JSONObject();
    JSONArray jsonQuote = new JSONArray();

    //Make sure to respect the object(array(object)) hierarchy of the response.
    json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonQuotes = jsonResponse.getJSONObject(GET_QUOTES);
    jsonQuote = jsonQuotes.getJSONArray(GET_QUOTE);

    //Loop through the quote array and do something with the data..
    for (int i = 0; i < jsonQuote.length(); i++){
        JSONObject curQuote = jsonQuote.getJSONObject(i);
        marketDay.addCandle(1,
                            curQuote.getDouble("opn"),
                            curQuote.getDouble("lo"),
                            curQuote.getDouble("hi"),
                            curQuote.getDouble("last"),
                            curQuote.getLong("incr_vl"));
    }

    return marketDay;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseData.java

示例7: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public ArrayList<String> parseJSON(Response response) throws JSONException{
    ArrayList<String> ret = new ArrayList<String>();

    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonExpirationDates = new JSONObject();
    JSONArray jsonDate = new JSONArray();

    JSONObject json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonExpirationDates = jsonResponse.getJSONObject(GET_EXPIRATION_DATES);
    jsonDate = jsonExpirationDates.getJSONArray(GET_DATE);

    for(int i = 0; i < jsonDate.length(); i++){
        String curDate = jsonDate.getString(i);
        ret.add(curDate);
    }

    try {
        ArrayList<Calendar> calList = parseCalendarDates(ret);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return ret;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:26,代码来源:ParseOptionExpirations.java

示例8: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public double parseJSON(Response response) throws JSONException{
    ArrayList<Double> ret = new ArrayList<Double>();
    double retDouble = 0.0;

    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonPrices = new JSONObject();
    JSONArray jsonPrice = new JSONArray();

    JSONObject json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonPrices = jsonResponse.getJSONObject(GET_PRICES);
    jsonPrice = jsonPrices.getJSONArray(GET_PRICE);

    for(int i = 0; i < jsonPrice.length(); i++){
        String curPrice = jsonPrice.getString(i);
        ret.add(Double.parseDouble(curPrice));
    }

    //pass the list we just parsed from TK to narrow down to one strike.
    retDouble = getCurrentStrikePrice(ret);

    return retDouble;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:24,代码来源:ParseOptionStrikePrice.java

示例9: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
protected OptionOrder parseJSON(Response response) throws JSONException{
    OptionOrder order = new OptionOrder();

    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonWarning = new JSONObject();
    JSONObject json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonWarning = jsonResponse.getJSONObject(GET_WARNING);

    if(jsonResponse.has("warning")){
        order.setException("warningtext");
        order.setIsException(true);
    }else {
        order.setClientOrderID(jsonResponse.getString("clientorderid"));
        order.setOrderStatus(jsonResponse.getInt("orderstatus"));
        order.setIsException(false);
    }

    return order;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:21,代码来源:ParseOptionOrder.java

示例10: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
protected OptionOrderPreview parseJSON(Response response) throws JSONException {
    OptionOrderPreview order = new OptionOrderPreview();

    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonQuotes = new JSONObject();
    JSONObject jsonInstrument = new JSONObject();
    JSONObject jsonDisplayData = new JSONObject();

    JSONObject json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonQuotes = jsonResponse.getJSONObject(GET_QUOTES);
    jsonInstrument = jsonQuotes.getJSONObject(GET_INSTRUMENT_QUOTE);
    jsonDisplayData = jsonInstrument.getJSONObject(GET_DISPLAY_DATA);

    order.setCommission(jsonResponse.getDouble("estcommission"));
    order.setOrderCost(jsonResponse.getDouble("principal"));
    order.setTotalCost();
    order.setDelta(jsonDisplayData.getDouble("delta"));
    order.setAskPrice(jsonDisplayData.getDouble("askprice"));
    order.setFixml(fixml);

    return order;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:24,代码来源:ParseOptionOrderPreview.java

示例11: extract

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public GatewayResponse extract(Response response) {
    String jsonBody;
    try {
        jsonBody = response.getBody();
    } catch (IOException e) {
        throw new UserInfoJsonRetrievingException(e);
    }
    if (isSuccessful(response)) {
        //here not need to check if userId is valid as the check will be postponed to do in service later
        String userId = getUserId(jsonBody) != null ? getUserId(jsonBody) : JsonUtil.getString(jsonBody, getUserIdFieldName());
        String nickName = JsonUtil.getString(jsonBody, getNickNameFieldName());
        String headImageUrl = getHeadImageUrlFieldName() != null ? JsonUtil.getString(jsonBody, getHeadImageUrlFieldName()) : "";

        return new GatewayResponse(userId, nickName, headImageUrl, getServiceType(), jsonBody);
    } else {
        String errorCode = JsonUtil.getString(jsonBody, getErrorCodeFieldName());
        String errorDesc = JsonUtil.getString(jsonBody, getErrorDescFieldName());
        throw new BadOAuthUserInfoException(errorCode, errorDesc);
    }
}
 
开发者ID:perrywang,项目名称:OAuthGateway,代码行数:21,代码来源:BaseResponseExtractor.java

示例12: getSingleUseToken

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public String getSingleUseToken() {
    OAuth10aService service = JamAuthConfig.instance().getOAuth10aService();
    final OAuthRequest request = new OAuthRequest(Verb.POST,
            JamAuthConfig.instance().getServerUrl() + "/v1/single_use_tokens",
            service);
    service.signRequest(JamAuthConfig.instance().getOAuth10aAccessToken(), request);

    final Response response = request.send();
    String body = response.getBody();

    Matcher matcher = SINGLE_USE_TOKEN_PATTERN.matcher(body);
    if (matcher.find()) {
        return matcher.group(0);
    }
    return null;
}
 
开发者ID:SAP,项目名称:SAPJamSampleCode,代码行数:17,代码来源:JamAuthConfig.java

示例13: retrieveUserProfileFromToken

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
@Override
protected FacebookProfile retrieveUserProfileFromToken(final OAuth2AccessToken accessToken) throws HttpAction {
    String body = sendRequestForData(accessToken, getProfileUrl(accessToken));
    if (body == null) {
        throw new HttpCommunicationException("Not data found for accessToken: " + accessToken);
    }
    final FacebookProfile profile = extractUserProfile(body);
    addAccessTokenToProfile(profile, accessToken);
    if (profile != null && this.requiresExtendedToken) {
        String url = CommonHelper.addParameter(EXCHANGE_TOKEN_URL, OAuthConstants.CLIENT_ID, getKey());
        url = CommonHelper.addParameter(url, OAuthConstants.CLIENT_SECRET, getSecret());
        url = addExchangeToken(url, accessToken);
        final OAuthRequest request = createOAuthRequest(url);
        final long t0 = System.currentTimeMillis();
        final Response response = request.send();
        final int code = response.getCode();
        body = response.getBody();
        final long t1 = System.currentTimeMillis();
        logger.debug("Request took: " + (t1 - t0) + " ms for: " + url);
        logger.debug("response code: {} / response body: {}", code, body);
        if (code == 200) {
            logger.debug("Retrieve extended token from  {}", body);
            final OAuth2AccessToken extendedAccessToken = ((DefaultApi20) getApi()).getAccessTokenExtractor().extract(body);
            logger.debug("Extended token: {}", extendedAccessToken);
            addAccessTokenToProfile(profile, extendedAccessToken);
        } else {
            logger.error("Cannot get extended token: {} / {}", code, body);
        }
    }
    return profile;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:32,代码来源:FacebookClient.java

示例14: loadOAuthProviderAccount

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {

	OAuthService service = this.getService();

	// getting user profile
	OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, config.getProfileUrl(), service);

	service.signRequest(accessToken, oauthRequest);
	Response oauthResponse = oauthRequest.send();
	String jsonString = oauthResponse.getBody();
	JSONObject root = new JSONObject(jsonString);
	JSONArray emailArray = root.getJSONArray(GOOGLE_JSON_EMAILLIST_PROPERTY);
	JSONObject firstEmail = emailArray.getJSONObject(0);

	String accountId = root.getString(GOOGLE_JSON_ACCOUNTID_PROPERTY); 
	String displayName = root.getString(GOOGLE_JSON_DISPLAYNAME_PROPERTY);
	String publicId = firstEmail.getString(GOOGLE_JSON_EMAIL_PROPERTY); 
	String profilePath="";
	if (root.has(GOOGLE_JSON_PROFILEPATH_PROPERTY)){
		profilePath = root.getString(GOOGLE_JSON_PROFILEPATH_PROPERTY); 
	}
	
	OAuthProviderAccount profile = 
			new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
		
	return profile;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:28,代码来源:GoogleOAuthProvider.java

示例15: parseJSON

import com.github.scribejava.core.model.Response; //导入方法依赖的package包/类
public OpenOptionPosition parseJSON(Response response) throws JSONException{
    OpenOptionPosition position = new OpenOptionPosition();

    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonAccountHoldings = new JSONObject();
    JSONObject jsonAccountHolding = new JSONObject();
    JSONObject jsonInstrument = new JSONObject();
    JSONObject jsonQuote = new JSONObject();

    JSONObject json = new JSONObject(response.getBody());
    jsonResponse = json.getJSONObject(GET_RESPONSE);
    jsonAccountHoldings = jsonResponse.getJSONObject(GET_HOLDINGS);
    jsonAccountHolding = jsonAccountHoldings.getJSONObject(GET_HOLDING);
    jsonInstrument = jsonAccountHolding.getJSONObject(GET_INSTRUMENT);
    jsonQuote = jsonAccountHolding.getJSONObject(GET_QUOTE);

    position.setCFI(jsonInstrument.getString("cfi"));
    position.setCostBasis(jsonAccountHolding.getDouble("costbasis"));
    position.setLastPrice(jsonQuote.getDouble("lastprice"));
    position.setExpiryDate(jsonInstrument.getString("matdt"));
    position.setPutOrCall(jsonInstrument.getString("putcall"));
    position.setQuantity(jsonAccountHolding.getInt("qty"));
    position.setSecType(jsonInstrument.getString("sectyp"));
    position.setStrikePrice(jsonInstrument.getDouble("strkpx"));
    position.setSymbol(jsonInstrument.getString("sym"));
    position.setGainLoss(jsonAccountHolding.getDouble("gainloss"));


    return position;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:31,代码来源:ParseOpenPosition.java


注:本文中的com.github.scribejava.core.model.Response.getBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。