Java Code Examples for org.scribe.model.OAuthRequest
The following are top voted examples for showing how to use
org.scribe.model.OAuthRequest. These examples are extracted from open source projects.
You can vote up the examples you like and your votes will be used in our system to generate
more good examples.
Example 1
| Project: Camel File: ScribeApiRequestor.java View source code | 7 votes |
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()));
}
}
Example 2
| Project: webapp File: Google2Api.java View source code | 6 votes |
@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());
}
Example 3
| Project: duckdns File: Google2Api.java View source code | 6 votes |
@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());
}
Example 4
| Project: jira-dvcs-connector File: TwoLegged10aOauthRemoteRequestor.java View source code | 6 votes |
@Override
protected String afterFinalUriConstructed(HttpRequestBase forMethod, String finalUri, Map<String, ? extends Object> parameters)
{
long start = System.currentTimeMillis();
//
// generate oauth 1.0 params for 2LO - use scribe so far for that ...
//
OAuthService service = createOauthService();
OAuthRequest request = new OAuthRequest(Verb.valueOf(forMethod.getMethod()), finalUri);
addParametersForSigning(request, parameters);
service.signRequest(new EmptyToken(), request);
Map<String, String> oauthParams = request.getOauthParameters();
//
//
log.debug("2LO signing took [{}] ms ", System.currentTimeMillis() - start);
return finalUri + paramsToString(oauthParams, finalUri.indexOf("?") != -1);
}
Example 5
| Project: jira-dvcs-connector File: ScribeOauthRemoteRequestor.java View source code | 6 votes |
protected void addParametersForSigning(final OAuthRequest request, final Map<String, ? extends Object> parameters)
{
if (parameters == null)
{
return;
}
Verb method = request.getVerb();
if (method == Verb.POST || method == Verb.PUT)
{
processParams(parameters, new ParameterProcessor()
{
@Override
public void process(String key, String value)
{
request.addBodyParameter(key, value);
}
});
}
}
Example 6
| Project: jira-dvcs-connector File: HttpClientThrreeLoOAuth10aServiceImpl.java View source code | 6 votes |
private void appendSignature(OAuthRequest request)
{
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
Example 7
| Project: jira-dvcs-connector File: TwoLoOAuth10aServiceImpl.java View source code | 6 votes |
/**
* {@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);
}
Example 8
| Project: jira-dvcs-connector File: TwoLoOAuth10aServiceImpl.java View source code | 6 votes |
private void appendSignature(OAuthRequest request)
{
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
Example 9
| Project: jira-dvcs-connector File: ThreeLegged10aOauthRemoteRequestor.java View source code | 6 votes |
@Override
protected void onConnectionCreated(HttpClient client, HttpRequestBase method, Map<String, ? extends Object> parameters)
throws IOException
{
long start = System.currentTimeMillis();
//
// generate oauth 1.0 params for 3LO - use scribe so far for that ...
//
OAuthService service = createOauthService();
OAuthRequest request = new OAuthRequest(Verb.valueOf(method.getMethod()), method.getURI().toString());
addParametersForSigning(request, parameters);
service.signRequest(generateAccessTokenObject(accessTokenWithSecret), request);
String header = authHeaderCreator.extract(request);
method.addHeader(OAuthConstants.HEADER, header);
log.debug("3LO signing took [{}] ms ", System.currentTimeMillis() - start);
}
Example 10
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取当前用户所有集群信息
*
* @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);
}
}
Example 11
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取指定集群下所有虚机组信息
*
* @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);
}
}
Example 12
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 在指定虚机上执行指定脚本
*
* @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);
}
}
Example 13
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取事件返回的所有日志信息(如执行脚本事件)
*
* @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);
}
}
Example 14
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 创建虚机
*
* @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);
}
}
Example 15
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 创建虚机. 此接口将立刻返回虚机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);
}
}
Example 16
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取指定集群的集群参数
*
* @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);
}
}
Example 17
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 设置集群参数, 若之前无此参数,则添加; 若有则替换
*
* @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());
}
}
Example 18
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 编辑指定脚本
*
* @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());
}
}
Example 19
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 删除指定虚机的标签
*
* @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());
}
}
Example 20
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 添加应用版本
*
* @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());
}
}
Example 21
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取部署任务信息
*
* @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());
}
}
Example 22
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取指定代码部署任务中,每台主机部署的情况
*
* @param deploymentId
* 代码部署任务ID
* @return
* @throws Fit2CloudException
*/
public List<ApplicationDeploymentLog> getDeploymentLogs(Long deploymentId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/deploymentlog/" + deploymentId + "/list");
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<ApplicationDeploymentLog>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 23
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取指定代码部署任务中,每台主机部署的情况
*
* @param deploymentId
* 代码部署任务ID
* @return
* @throws Fit2CloudException
*/
public List<ApplicationDeploymentEventLog> getDeploymentEventLogs(Long deploymentId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET,
restApiEndpoint + "/deploymentEventlog/" + deploymentId + "/list");
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<ApplicationDeploymentEventLog>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 24
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取监控数据排行锁支持的监控项列表
*
* @return
* @throws Fit2CloudException
*/
public List<Metric> getTopMetrics() throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/top/metrics");
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<Metric>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 25
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取云帐号列表
*
* @return
* @throws Fit2CloudException
*/
public List<CloudCredential> getCloudCredentials() throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/cloudcredentials");
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<CloudCredential>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 26
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取虚机创建模板列表
*
* @param cloudCredentialId
* 可选,云帐号ID
* @return
* @throws Fit2CloudException
*/
public List<LaunchConfiguration> getLaunchconfigurations(Long cloudCredentialId) throws Fit2CloudException {
StringBuffer requestParamSb = new StringBuffer();
if (cloudCredentialId != null && cloudCredentialId.intValue() > 0) {
requestParamSb.append("cloudCredentialId=");
requestParamSb.append(cloudCredentialId);
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 + "/launchconfigurations?" + requestParam);
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<LaunchConfiguration>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 27
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取服务目录订单列表
*
* @param status
* 查询条件:订单状态,可选值参考 @see ServiceCatalogOrderStatus (可选)
* @param sort
* 排序字段 (可选)
* @param order
* 排序方式 (可选)
* @param pageSize
* 分页大小,(可选,默认9999)
* @param pageNum
* 分页编号,(可选,默认1)
* @return
* @throws Fit2CloudException
*/
public List<ServiceCatalogOrder> getServiceCatalogOrders(String status, String sort, String order, Integer pageSize,
Integer pageNum) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/servicecatalog/orders?status=" + status
+ "&sort=" + sort + "&order=" + order + "&pageSize=" + pageSize + "&pageNum=" + pageNum);
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<ServiceCatalogOrder>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 28
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取指定主机组下的所有监控项
*
* @param clusterRoleId
* 主机组ID
* @return
* @throws Fit2CloudException
*/
public List<KeyPair> getSupportedServerMetrics(Long clusterRoleId) throws Fit2CloudException {
if (clusterRoleId == null || clusterRoleId <= 0) {
throw new Fit2CloudException("请检查clusterRoleId的输入!");
}
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/metrics?clusterRoleId=" + clusterRoleId);
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<KeyPair>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
Example 29
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
/**
* 获取指定监控项的端口监控信息(端口监控间隔时间为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);
}
}
Example 30
| Project: fit2cloud-general-java-sdk File: Fit2CloudClient.java View source code | 6 votes |
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;
}
}
Example 31
| Project: gerrit-oauth-provider File: BitbucketApi.java View source code | 6 votes |
@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()));
}
Example 32
| Project: pac4j-oauth-tencent File: TencentApi.java View source code | 6 votes |
@Override
public String getAuthorizationUrl(OAuthConfig config, String state) {
// http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token
final String authorizationEndpoint = "https://graph.qq.com/oauth2.0/authorize";
OAuthRequest request = new OAuthRequest(Verb.GET, authorizationEndpoint);
request.addQuerystringParameter("response_type", "code");
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addQuerystringParameter("state", state);
if (config.hasScope()) {
request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
}
return request.getCompleteUrl();
}
Example 33
| Project: cas4.0.x-server-wechat File: WeiXinOAuth20ServiceImpl.java View source code | 5 votes |
/**
* 获取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());
}
Example 34
| Project: cas4.0.x-server-wechat File: WeiXinOAuth20ServiceImpl.java View source code | 5 votes |
@Override
public void signRequest(final Token accessToken, final OAuthRequest request) {
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
String response = accessToken.getRawResponse();
Matcher matcher = openIdPattern.matcher(response);
if (matcher.find()) {
request.addQuerystringParameter("openid", matcher.group(1));
} else {
throw new OAuthException("微信接口返回数据miss openid: " + response);
}
}
Example 35
| Project: tradeshift-app-samples File: TokenServiceImpl.java View source code | 5 votes |
/**
* 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;
}
Example 36
| Project: tradeshift-app-samples File: TokenServiceImpl.java View source code | 5 votes |
/**
* 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);
}
}
Example 37
| Project: jira-dvcs-connector File: HttpClientThrreeLoOAuth10aServiceImpl.java View source code | 5 votes |
private void addOAuthParams(OAuthRequest request, Token token)
{
request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds());
request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce());
request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey());
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod());
request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
if(config.hasScope()) request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope());
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters()));
}
Example 38
| Project: jira-dvcs-connector File: HttpClientThrreeLoOAuth10aServiceImpl.java View source code | 5 votes |
/**
* {@inheritDoc}
*/
public void signRequest(Token token, OAuthRequest request)
{
config.log("signing request: " + request.getCompleteUrl());
request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
config.log("setting token to: " + token);
addOAuthParams(request, token);
appendSignature(request);
}
Example 39
| Project: jira-dvcs-connector File: HttpClientThrreeLoOAuth10aServiceImpl.java View source code | 5 votes |
private String getSignature(OAuthRequest request, Token token)
{
config.log("generating signature...");
String baseString = api.getBaseStringExtractor().extract(request);
String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), token.getSecret());
config.log("base string is: " + baseString);
config.log("signature is: " + signature);
return signature;
}
Example 40
| Project: jira-dvcs-connector File: TwoLoOAuth10aServiceImpl.java View source code | 5 votes |
private void addOAuthParams(OAuthRequest request, Token token)
{
request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds());
request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce());
request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey());
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod());
request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
if (config.hasScope())
request.addOAuthParameter(OAuthConstants.SCOPE, config.getScope());
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters()));
}

