本文整理汇总了Java中org.scribe.model.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.scribe.model包,在下文中一共展示了Response类的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()));
}
}
示例2: getAccessToken
import org.scribe.model.Response; //导入依赖的package包/类
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
switch (api.getAccessTokenVerb()) {
case POST:
request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
break;
case GET:
default:
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());
}
示例3: 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);
}
示例4: getClusters
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 获取当前用户所有集群信息
*
* @return
* @throws Fit2CloudException
*/
public List<Cluster> getClusters() throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/clusters");
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<Cluster>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
示例5: getClusterRoles
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 获取指定集群下所有虚机组信息
*
* @param clusterId
* 集群ID
* @return
* @throws Fit2CloudException
*/
public List<ClusterRole> getClusterRoles(long clusterId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/cluster/" + clusterId + "/roles");
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<ClusterRole>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
示例6: 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);
}
}
示例7: getLoggingsByEventId
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 获取事件返回的所有日志信息(如执行脚本事件)
*
* @param eventId
* 事件ID
* @return
* @throws Fit2CloudException
*/
public List<Logging> getLoggingsByEventId(long eventId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, getLoggingUrl + eventId);
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<Logging>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
示例8: launchServer
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 创建虚机
*
* @param clusterId
* 虚机所在的集群
* @param clusterRoleId
* 虚机所在的虚机组
* @param launchConfigurationId
* 创建虚机所使用的模板
* @return 创建后的虚机信息
* @throws Fit2CloudException
*/
public Server launchServer(long clusterId, long clusterRoleId, long launchConfigurationId)
throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/launchserver/cluster/" + clusterId
+ "/clusterrole/" + clusterRoleId + "?launchConfigurationId=" + launchConfigurationId);
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, Server.class);
} else {
throw new Fit2CloudException(responseString);
}
}
示例9: launchServerAsync
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 创建虚机. 此接口将立刻返回虚机ID,而后台将异步创建虚机. 之后通过返回的虚机信息中的ID来查询完整的虚机信息
*
* @param clusterId
* 虚机所在的集群
* @param clusterRoleId
* 虚机所在的虚机组
* @param launchConfigurationId
* 创建虚机所使用的模板
* @return
* @throws Fit2CloudException
*/
public Server launchServerAsync(long clusterId, long clusterRoleId, long launchConfigurationId)
throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/launchserver/async/cluster/" + clusterId
+ "/clusterrole/" + clusterRoleId + "?launchConfigurationId=" + launchConfigurationId);
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, Server.class);
} else {
throw new Fit2CloudException(responseString);
}
}
示例10: 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);
}
}
示例11: 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());
}
}
示例12: addScript
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 添加脚本
*
* @param name
* 脚本名称
* @param description
* 脚本描述
* @param scriptText
* 脚本内容
* @return 脚本ID
* @throws Fit2CloudException
*/
public Long addScript(String name, String description, String scriptText) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/script/add");
request.addBodyParameter("name", name);
request.addBodyParameter("description", description);
request.addBodyParameter("scriptText", scriptText);
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(response.getBody());
}
}
示例13: editScript
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 编辑指定脚本
*
* @param scriptId
* 脚本ID
* @param description
* 脚本描述
* @param scriptText
* 脚本内容
* @return
* @throws Fit2CloudException
*/
public boolean editScript(long scriptId, String description, String scriptText) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/script/" + scriptId + "/update");
request.addBodyParameter("description", description);
request.addBodyParameter("scriptText", scriptText);
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());
}
}
示例14: 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());
}
}
示例15: deleteTag
import org.scribe.model.Response; //导入依赖的package包/类
/**
* 删除指定虚机的标签
*
* @param serverId
* 虚机ID
* @param tagName
* 标签名称
* @return
* @throws Fit2CloudException
*/
public boolean deleteTag(Long serverId, String tagName) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/tags/delete");
if (serverId != null && serverId.intValue() > 0) {
request.addBodyParameter("serverId", String.valueOf(serverId));
}
if (tagName != null && tagName.trim().length() > 0) {
request.addBodyParameter("tagName", tagName.trim());
}
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());
}
}