本文整理匯總了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);
}
}