本文整理汇总了Java中org.scribe.model.OAuthRequest.setCharset方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthRequest.setCharset方法的具体用法?Java OAuthRequest.setCharset怎么用?Java OAuthRequest.setCharset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scribe.model.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.setCharset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeScript
import org.scribe.model.OAuthRequest; //导入方法依赖的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);
}
}
示例2: setClusterParam
import org.scribe.model.OAuthRequest; //导入方法依赖的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());
}
}
示例3: changeClusterAndRole
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
public boolean changeClusterAndRole(Long cmdbServerId, String clusterName, String clusterRoleName, String sshIp,
Long sshPort, String sshUser, String sshPwd, String osType) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cmdbserver/changeClusterAndRole");
request.addBodyParameter("cmdbServerId", String.valueOf(cmdbServerId));
request.addBodyParameter("clusterName", clusterName);
request.addBodyParameter("clusterRoleName", clusterRoleName);
request.addBodyParameter("sshIp", sshIp);
request.addBodyParameter("sshPort", String.valueOf(sshPort));
request.addBodyParameter("sshUser", sshUser);
request.addBodyParameter("sshPwd", sshPwd);
request.addBodyParameter("osType", osType);
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
System.out.println(code);
if (code == 200) {
return true;
} else {
return false;
}
}
示例4: editScript
import org.scribe.model.OAuthRequest; //导入方法依赖的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());
}
}
示例5: saveTag
import org.scribe.model.OAuthRequest; //导入方法依赖的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());
}
}
示例6: addApplicationRevision
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 添加应用版本
*
* @param name
* 应用版本名称
* @param description
* 应用版本描述
* @param applicationName
* 所属应用名称
* @param repositoryName
* 所属仓库名称
* @param location
* 应用版本文件的下载路径
* @param md5
* 应用版本文件的md5值
* @return
* @throws Fit2CloudException
*/
public ApplicationRevision addApplicationRevision(String name, String description, String applicationName,
String repositoryName, String location, String md5) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/deploy/app/revision/add.json");
request.addBodyParameter("revName", name);
request.addBodyParameter("revDescription", description);
request.addBodyParameter("appName", applicationName);
if (repositoryName != null) {
request.addBodyParameter("repoName", repositoryName);
}
request.addBodyParameter("location", location);
if (md5 != null && md5.trim().length() > 0) {
request.addBodyParameter("md5", md5);
}
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, ApplicationRevision.class);
} else {
throw new Fit2CloudException(response.getBody());
}
}
示例7: getDeployment
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取部署任务信息
*
* @param deploymentId
* @return
* @throws Fit2CloudException
*/
public ApplicationDeployment getDeployment(Long deploymentId) throws Fit2CloudException {
if (deploymentId == null || deploymentId == 0) {
throw new Fit2CloudException("invalid parameter!");
}
String url = String.format("%s/deploy/app/revision/deployment/get.json?deploymentId=%s", restApiEndpoint,
deploymentId);
OAuthRequest request = new OAuthRequest(Verb.GET, url);
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, ApplicationDeployment.class);
} else {
throw new Fit2CloudException(response.getBody());
}
}
示例8: getPortMonitor
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取指定监控项的端口监控信息(端口监控间隔时间为5分钟)
*
* @param pageSize
* 分页大小,(可选,默认9999)
* @param pageNum
* 分页编号,(可选,默认1)
* @return
* @throws Fit2CloudException
*/
public PortMonitor getPortMonitor(long portMonitorId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET,
restApiEndpoint + "/monitor/port?portMonitorId=" + portMonitorId);
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, PortMonitor.class);
} else {
throw new Fit2CloudException(responseString);
}
}
示例9: getAccessTokenByAuthCode
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* Receive oauth2 token from authentication server and store it in the session context
*
* @param authorizationCode from authentication server
* @return oauth2 token
* @throws IOException
*/
@Override
public OAuth2AccessToken getAccessTokenByAuthCode(String authorizationCode) throws ParseException {
LOGGER.info("get oauth2 access token", TokenServiceImpl.class);
OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, ACCESS_TOKEN_URI);
oAuthRequest.addHeader("Content-Type", HEADER_CONTENT_TYPE);
oAuthRequest.addHeader("Authorization", HEADER_AUTHORIZATION_TYPE + Base64.encodeBase64String(new String(CLIENT_ID + ":" + CLIENT_SECRET).getBytes()));
oAuthRequest.setCharset(HEADER_CHAR_SET_TYPE);
oAuthRequest.addBodyParameter("grant_type", AUTHORIZATION_CODE_GRANT_TYPE);
oAuthRequest.addBodyParameter("code", authorizationCode);
LOGGER.info("send request for access token", TokenServiceImpl.class);
String accessTokenResponse = oAuthRequest.send().getBody();
if (accessTokenResponse != null) {
LOGGER.info("successfully received authorization token");
// store accessToken in session context
this.accessToken = new DefaultOAuth2AccessToken(new JSONObject(accessTokenResponse).get("access_token").toString());
((DefaultOAuth2AccessToken) this.accessToken).setRefreshToken(new DefaultOAuth2RefreshToken(new JSONObject(accessTokenResponse).get("refresh_token").toString()));
((DefaultOAuth2AccessToken) this.accessToken).setExpiration((new Date(System.currentTimeMillis() + (Long
.valueOf(new JSONObject(accessTokenResponse).get("expires_in").toString()) * 60000))));
String idToken = new JSONObject(accessTokenResponse).get("id_token").toString();
this.jwtDTO = parseJWTToken(idToken);
this.userId = this.jwtDTO.getUserId();
} else {
LOGGER.warn("failed to get authorization token", TokenServiceImpl.class);
}
return accessToken;
}
示例10: refreshToken
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* Obtain a new token by refresh token
*/
@Override
public void refreshToken() {
if (this.accessToken.getRefreshToken() != null) {
OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, ACCESS_TOKEN_URI);
oAuthRequest.addHeader("Content-Type", HEADER_CONTENT_TYPE);
oAuthRequest.addHeader("Authorization", HEADER_AUTHORIZATION_TYPE + Base64.encodeBase64String(new String(CLIENT_ID + ":" + CLIENT_SECRET).getBytes()));
oAuthRequest.setCharset(HEADER_CHAR_SET_TYPE);
oAuthRequest.addBodyParameter("grant_type", REFRESH_TOKEN_GRANT_TYPE);
oAuthRequest.addBodyParameter("refresh_token", getAccessTokenFromContext().getRefreshToken().getValue().toString());
oAuthRequest.addBodyParameter("scope", CLIENT_ID + "." + propertySources.getTradeshiftAppVersion());
LOGGER.info("send request for access token by refresh token", TokenServiceImpl.class);
String accessTokenResponse = oAuthRequest.send().getBody();
if (accessTokenResponse != null) {
LOGGER.info("successfully received authorization token by refresh token");
// store accessToken in session context
this.accessToken = new DefaultOAuth2AccessToken(new JSONObject(accessTokenResponse).get("access_token").toString());
((DefaultOAuth2AccessToken) this.accessToken).setExpiration((new Date(System.currentTimeMillis() + Long.valueOf(new JSONObject(accessTokenResponse).get("expires_in").toString()))));
} else {
LOGGER.warn("failed to get authorization token by refresh token", TokenServiceImpl.class);
}
} else {
LOGGER.error("Refresh token doesn't exist", TokenServiceImpl.class);
}
}
示例11: registerCmdbServer
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
public CmdbVm registerCmdbServer(Long cmdbServerId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cmdbserver/register");
request.addBodyParameter("cmdbServerId", String.valueOf(cmdbServerId));
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, CmdbVm.class);
} else {
throw new Fit2CloudException(response.getBody());
}
}
示例12: updateClusterRole
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
public boolean updateClusterRole(Long clusterRoleId, String clusterRoleName) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cmdbserver/updateClusterRole");
request.addBodyParameter("clusterRoleId", String.valueOf(clusterRoleId));
request.addBodyParameter("clusterRoleName", clusterRoleName);
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
if (code == 200) {
return true;
} else {
return false;
}
}
示例13: getApplicationList
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取代码部署应用列表
*
* @param pageSize
* 分页大小,(可选,默认9999)
* @param pageNum
* 分页编号,(可选,默认1)
* @return
* @throws Fit2CloudException
*/
public List<Application> getApplicationList(Integer pageSize, Integer pageNum) throws Fit2CloudException {
StringBuffer requestParamSb = new StringBuffer();
if (pageSize != null && pageSize.intValue() > 0) {
requestParamSb.append("pageSize=");
requestParamSb.append(pageSize);
requestParamSb.append("&");
}
if (pageNum != null && pageNum.intValue() > 0) {
requestParamSb.append("pageNum=");
requestParamSb.append(pageNum);
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 + "/deploy/apps?" + requestParam);
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) {
Type listType = new TypeToken<List<Application>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
示例14: getApplicationRepoList
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取代码部署仓库列表
*
* @param pageSize
* 分页大小,(可选,默认9999)
* @param pageNum
* 分页编号,(可选,默认1)
* @return
* @throws Fit2CloudException
*/
public List<ApplicationRepo> getApplicationRepoList(Integer pageSize, Integer pageNum) throws Fit2CloudException {
StringBuffer requestParamSb = new StringBuffer();
if (pageSize != null && pageSize.intValue() > 0) {
requestParamSb.append("pageSize=");
requestParamSb.append(pageSize);
requestParamSb.append("&");
}
if (pageNum != null && pageNum.intValue() > 0) {
requestParamSb.append("pageNum=");
requestParamSb.append(pageNum);
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 + "/deploy/repos?" + requestParam);
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) {
Type listType = new TypeToken<List<ApplicationRepo>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
示例15: getContactGroupList
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取通知组列表
*
* @param pageSize
* 分页大小,(可选,默认9999)
* @param pageNum
* 分页编号,(可选,默认1)
* @return
* @throws Fit2CloudException
*/
public List<ContactGroup> getContactGroupList(Integer pageSize, Integer pageNum) throws Fit2CloudException {
StringBuffer requestParamSb = new StringBuffer();
if (pageSize != null && pageSize.intValue() > 0) {
requestParamSb.append("pageSize=");
requestParamSb.append(pageSize);
requestParamSb.append("&");
}
if (pageNum != null && pageNum.intValue() > 0) {
requestParamSb.append("pageNum=");
requestParamSb.append(pageNum);
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 + "/contactgroups?" + requestParam);
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) {
Type listType = new TypeToken<List<ContactGroup>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}