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


Java OAuthRequest.addBodyParameter方法代码示例

本文整理汇总了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());
}
 
开发者ID:elimu-ai,项目名称:webapp,代码行数:23,代码来源:Google2Api.java

示例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);
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:27,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:29,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:30,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:29,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:36,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:30,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:44,代码来源:Fit2CloudClient.java

示例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;
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:24,代码来源:Fit2CloudClient.java

示例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()));
}
 
开发者ID:davido,项目名称:gerrit-oauth-provider,代码行数:19,代码来源:BitbucketApi.java

示例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());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:17,代码来源:WeiXinOAuth20ServiceImpl.java

示例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;
}
 
开发者ID:Tradeshift,项目名称:tradeshift-app-samples,代码行数:40,代码来源:TokenServiceImpl.java

示例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);
    }

}
 
开发者ID:Tradeshift,项目名称:tradeshift-app-samples,代码行数:32,代码来源:TokenServiceImpl.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:54,代码来源:Fit2CloudClient.java

示例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());
	}
}
 
开发者ID:fit2cloud,项目名称:fit2cloud-general-java-sdk,代码行数:52,代码来源:Fit2CloudClient.java


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