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


Java Response.getBody方法代码示例

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


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

示例1: send

import org.scribe.model.Response; //导入方法依赖的package包/类
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()));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:ScribeApiRequestor.java

示例2: getRequestToken

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * {@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);
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:23,代码来源:TwoLoOAuth10aServiceImpl.java

示例3: postMedia

import org.scribe.model.Response; //导入方法依赖的package包/类
@Override
public String postMedia(String url, Lecture lecture, java.io.File file, Map.Entry<String, String>... params) throws IOException {
	Entity entity = new Entity();
	Log.i("FileNAME", file.getName());
	Log.i("FileNAME", file.getAbsolutePath());
	Log.i("FileNAME", file.getCanonicalPath());
	Log.i("FileNAME", file.getParent());
	Log.i("TOKEN", this.accesToken.getToken());

	entity.addPart("lecture[media]", file, URLConnection.guessContentTypeFromName(file.getName()));
	entity.addPart("lecture[name]", lecture.name);
	entity.addPart("lecture[type]", lecture.type);
	MultipartRequest request = new MultipartRequest(url, this.accesToken.getToken());
	request.setEntity(entity);
	Response r = request.send();
	if (r.getCode() != 201){
		throw new IOException();
	}
	Log.i("RESPONSE", Integer.toString(r.getCode()));
	return r.getBody();
}
 
开发者ID:Openredu,项目名称:mobile,代码行数:22,代码来源:ScribeHttpClient.java

示例4: executeScript

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * 在指定虚机上执行指定脚本
 * 
 * @param serverId
 *            虚机ID
 * @param scriptContent
 *            脚本内容
 * @return 返回执行脚本事件ID, 可根据此ID获取返回的所有执行日志
 * @throws Fit2CloudException
 */
public long executeScript(long serverId, String scriptContent) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, executeScriptInServerUrl);
	request.addBodyParameter("serverId", String.valueOf(serverId));
	request.addBodyParameter("scriptContent", scriptContent);
	request.setCharset("UTF-8");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		return Long.parseLong(responseString);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:27,代码来源:Fit2CloudClient.java

示例5: setClusterParam

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * 设置集群参数, 若之前无此参数,则添加; 若有则替换
 * 
 * @param clusterId
 *            集群ID
 * @param name
 *            集群参数名称
 * @param value
 *            集群参数值
 * @return
 * @throws Fit2CloudException
 */
public boolean setClusterParam(long clusterId, String name, String value) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cluster/" + clusterId + "/param");
	request.addBodyParameter("name", name);
	request.addBodyParameter("value", value);
	request.setCharset("UTF-8");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		return "true".equals(responseString);
	} else {
		throw new Fit2CloudException(response.getBody());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:29,代码来源:Fit2CloudClient.java

示例6: getLaunchconfigurations

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * 获取虚机创建模板列表
 * 
 * @param cloudCredentialId
 *            可选,云帐号ID
 * @return
 * @throws Fit2CloudException
 */
public List<LaunchConfiguration> getLaunchconfigurations(Long cloudCredentialId) throws Fit2CloudException {
	StringBuffer requestParamSb = new StringBuffer();
	if (cloudCredentialId != null && cloudCredentialId.intValue() > 0) {
		requestParamSb.append("cloudCredentialId=");
		requestParamSb.append(cloudCredentialId);
		requestParamSb.append("&");
	}
	String requestParam = requestParamSb.toString();
	if (requestParam != null && requestParam.endsWith("&")) {
		requestParam = requestParam.substring(0, requestParam.length() - 1);
	}
	OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/launchconfigurations?" + requestParam);
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		Type listType = new TypeToken<ArrayList<LaunchConfiguration>>() {
		}.getType();
		return new GsonBuilder().create().fromJson(responseString, listType);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:34,代码来源:Fit2CloudClient.java

示例7: saveTag

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * 给指定虚机设置标签. 若无则新增标签; 若有则替换
 * 
 * @param serverId
 *            虚机ID
 * @param tagName
 *            标签名称
 * @param tagValue
 *            标签值
 * @return
 * @throws Fit2CloudException
 */
public Tag saveTag(Long serverId, String tagName, String tagValue) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/tags/save");
	if (serverId != null && serverId.intValue() > 0) {
		request.addBodyParameter("serverId", String.valueOf(serverId));
	}
	if (tagName != null && tagName.trim().length() > 0) {
		request.addBodyParameter("tagName", tagName.trim());
	}
	if (tagValue != null && tagValue.trim().length() > 0) {
		request.addBodyParameter("tagValue", tagValue.trim());
	}
	request.setCharset("UTF-8");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		return new GsonBuilder().create().fromJson(responseString, Tag.class);
	} else {
		throw new Fit2CloudException(response.getBody());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:36,代码来源:Fit2CloudClient.java

示例8: getClusterParams

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * 获取指定集群的集群参数
 * 
 * @param clusterId
 *            集群ID
 * @return
 * @throws Fit2CloudException
 */
public List<ClusterParam> getClusterParams(long clusterId) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/cluster/" + clusterId + "/params");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		Type listType = new TypeToken<ArrayList<ClusterParam>>() {
		}.getType();
		return new GsonBuilder().create().fromJson(responseString, listType);

	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:25,代码来源:Fit2CloudClient.java

示例9: executeScript

import org.scribe.model.Response; //导入方法依赖的package包/类
public long executeScript(long serverId, String scriptContent)
		throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, executeScriptInServerUrl);
	request.addBodyParameter("serverId", String.valueOf(serverId));
	request.addBodyParameter("scriptContent", scriptContent);
	request.setCharset("UTF-8");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code==200){
		return Long.parseLong(responseString);
	}else{
		throw new Fit2CloudException(responseString);
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-java-sdk,代码行数:18,代码来源:Fit2CloudClient.java

示例10: getDevice

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * @param uid
 *            the cube id to query for
 * @return the description of a device
 * @throws CubeSensorsException
 *             when a request fails
 */
public Device getDevice(final String uid) {
	final String queryUrl = RESOURCES_ROOT + DEVICES_PATH + uid;
	LOGGER.trace("Querying: {}", queryUrl);

	final OAuthRequest request = new OAuthRequest(Verb.GET, queryUrl);
	request.getHeaders().put(HTTP_HEADER_ACCEPT, MEDIA_TYPE_APPLICATION_JSON);
	service.signRequest(accessToken, request);
	final Response response = request.send();
	LOGGER.trace("Response: {}", response.getBody());

	if (!response.isSuccessful()) {
		throw new CubeSensorsException(response.getBody());
	}

	final JsonDeviceResponse queryResponse = parseQuery(response.getBody(), JsonDeviceResponse.class);
	if (queryResponse == null) {
		return null;
	}

	LOGGER.debug("Retrieved device {}.", queryResponse.device.uid);

	return extractDevice(queryResponse.device);
}
 
开发者ID:1337joe,项目名称:cubesensors-for-java,代码行数:31,代码来源:CubeSensorsApiV1.java

示例11: getSocialUser

import org.scribe.model.Response; //导入方法依赖的package包/类
private SocialUser getSocialUser(Token accessToken,int authProvider) throws OurException
{
    logger.info("Token: " + accessToken + " Provider: " + authProvider);
    OAuthService service = getOAuthService(authProvider);
    
    
    String url = getProtectedResourceUrlFromSession();
    logger.info("protected url: " + url);
    OAuthRequest request = new OAuthRequest(Verb.GET,url);
    // sign the request
    service.signRequest(accessToken,request);
    Response response = request.send();
    String json = response.getBody();
    SocialUser socialUser = getSocialUserFromJson(json,authProvider);
    return socialUser;
}
 
开发者ID:muquit,项目名称:gwtoauthlogindemo,代码行数:17,代码来源:OAuthLoginServiceImpl.java

示例12: TKResponse

import org.scribe.model.Response; //导入方法依赖的package包/类
public TKResponse(Request req) {
	Response response = req.send();
	String limitUsed = response.getHeader("X-RateLimit-Used");
	String limitExpire = response.getHeader("X-RateLimit-Expire");
	String limitTotal = response.getHeader("X-RateLimit-Limit");
	String limitRemain = response.getHeader("X-RateLimit-Remaining");
	if (limitUsed != null) {
		rateLimitUsed = Integer.parseInt(limitUsed);
	}
	if (limitExpire != null) {
		rateLimitExpire = Long.parseLong(limitExpire);
	}
	if (limitTotal != null) {
		rateLimitTotal = Integer.parseInt(limitTotal);
	}
	if (limitRemain != null) {
		rateLimitRemaining = Integer.parseInt(limitRemain);
	}
	this.response = response.getBody();
}
 
开发者ID:Ccook,项目名称:conniption,代码行数:21,代码来源:TKResponse.java

示例13: clear

import org.scribe.model.Response; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:tumblr,项目名称:jumblr,代码行数:21,代码来源:RequestBuilder.java

示例14: parseXAuthResponse

import org.scribe.model.Response; //导入方法依赖的package包/类
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);
}
 
开发者ID:tumblr,项目名称:jumblr,代码行数:24,代码来源:RequestBuilder.java

示例15: JumblrException

import org.scribe.model.Response; //导入方法依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:tumblr,项目名称:jumblr,代码行数:23,代码来源:JumblrException.java


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