本文整理匯總了Java中org.scribe.model.OAuthRequest.addBodyParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java OAuthRequest.addBodyParameter方法的具體用法?Java OAuthRequest.addBodyParameter怎麽用?Java OAuthRequest.addBodyParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.scribe.model.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.addBodyParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAccessToken
import org.scribe.model.OAuthRequest; //導入方法依賴的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());
}
示例2: 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);
}
}
示例3: 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());
}
}
示例4: addScript
import org.scribe.model.OAuthRequest; //導入方法依賴的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());
}
}
示例5: 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());
}
}
示例6: 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());
}
}
示例7: deleteTag
import org.scribe.model.OAuthRequest; //導入方法依賴的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());
}
}
示例8: 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());
}
}
示例9: 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;
}
}
示例10: getAccessToken
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public Token getAccessToken(Token token, Verifier verifier) {
OAuthRequest request =
new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addHeader("Authorization", prepareAuthorizationHeaderValue());
request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_VALUE);
request.addBodyParameter(CODE, verifier.getValue());
Response response = request.send();
if (response.getCode() == SC_OK) {
Token t = api.getAccessTokenExtractor().extract(response.getBody());
return new Token(t.getToken(), config.getApiSecret());
}
throw new OAuthException(
String.format(
"Error response received: %s, HTTP status: %s",
response.getBody(), response.getCode()));
}
示例11: getAccessToken
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
/**
* 獲取account_token的http請求參數添加
*/
@Override
public Token getAccessToken(final Token requestToken, final Verifier verifier) {
final OAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
this.api.getAccessTokenEndpoint(), this.connectTimeout,
this.readTimeout, this.proxyHost, this.proxyPort);
request.addBodyParameter("appid", this.config.getApiKey());
request.addBodyParameter("secret", this.config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
request.addBodyParameter("grant_type", "authorization_code");
final Response response = request.send();
return this.api.getAccessTokenExtractor().extract(response.getBody());
}
示例12: 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;
}
示例13: 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);
}
}
示例14: addDeployment
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
/**
* 添加代碼部署任務
*
* @param applicationName
* 應用名稱
* @param applicationRevisionName
* 應用版本名稱
* @param clusterName
* 集群名稱
* @param clusterRoleName
* 虛機組名稱
* @param serverId
* 虛機ID
* @param deployPolicy
* 部署策略 (allAtOnce | halfAtATime | oneAtATime)
* @param description
* 部署任務描述
* @param contactGroupId
* 通知組ID,null表示不需要接收部署通知郵件
* @return
* @throws Fit2CloudException
*/
public ApplicationDeployment addDeployment(String applicationName, String applicationRevisionName,
String clusterName, String clusterRoleName, Long serverId, String deployPolicy, String description,
Long contactGroupId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST,
restApiEndpoint + "/deploy/app/revision/deployment/add.json");
request.addBodyParameter("appName", applicationName);
request.addBodyParameter("revName", applicationRevisionName);
request.addBodyParameter("clusterName", clusterName);
if (clusterRoleName != null && clusterRoleName.trim().length() > 0) {
request.addBodyParameter("clusterRoleName", clusterRoleName);
}
if (serverId != null && serverId.longValue() > 0) {
request.addBodyParameter("serverId", String.valueOf(serverId));
}
request.addBodyParameter("deployPolicy", deployPolicy);
request.addBodyParameter("description", description);
if (contactGroupId != null && contactGroupId.longValue() > 0) {
request.addBodyParameter("contactGroupId", String.valueOf(contactGroupId));
}
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());
}
}
示例15: registerServer
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
/**
* 將自服務平台的虛機注冊到devops平台
*
* @param sfServerId
* 自服務屁股疼虛機ID
* @param cloudServerId
* 自服務屁股疼虛機對應的cloudServer ID
* @param installAgent
* 是否自動安裝agent
* @param user
* 係統的登錄用戶名
* @param password
* 係統的登錄密碼
* @param key
* 係統的登錄秘鑰
* @param port
* 係統的登錄端口
* @return
* @throws Fit2CloudException
*/
public Server registerServer(String sfServerId, Long cloudServerId, boolean installAgent, String user,
String password, String key, Long port) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/sfserver/register");
request.addBodyParameter("sfServerId", sfServerId);
request.addBodyParameter("cloudServerId", String.valueOf(cloudServerId));
request.addBodyParameter("installAgent", String.valueOf(installAgent));
if (user != null && user.trim().length() > 0) {
request.addBodyParameter("user", user);
}
if (password != null && password.trim().length() > 0) {
request.addBodyParameter("password", password);
}
if (key != null && key.trim().length() > 0) {
request.addBodyParameter("key", key);
}
if (port == null || port <= 0) {
port = 22l;
}
request.addBodyParameter("port", String.valueOf(port));
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, Server.class);
} else {
throw new Fit2CloudException(response.getBody());
}
}