本文整理汇总了Java中org.scribe.model.Response.getCode方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getCode方法的具体用法?Java Response.getCode怎么用?Java Response.getCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scribe.model.Response
的用法示例。
在下文中一共展示了Response.getCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDeploymentEventLogs
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* 获取指定代码部署任务中,每台主机部署的情况
*
* @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);
}
}
示例2: getLaunchconfigurations
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* 获取虚机创建模板列表
*
* @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);
}
}
示例3: executeScript
import org.scribe.model.Response; //导入方法依赖的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);
}
}
示例4: launchServerAsync
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* 创建虚机. 此接口将立刻返回虚机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);
}
}
示例5: setClusterParam
import org.scribe.model.Response; //导入方法依赖的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());
}
}
示例6: updateAccessToken
import org.scribe.model.Response; //导入方法依赖的package包/类
@Override
protected void updateAccessToken() throws IOException
{
Helper.debug( "Google access token has expired. Refreshing..." );
OAuthRequest request = new OAuthRequest( Verb.POST, "https://accounts.google.com/o/oauth2/token" );
request.addBodyParameter( "refresh_token", AccountPrefs.getGPlusRefreshToken() );
request.addBodyParameter( "client_id", GPlusConfig.GPLUS_OAUTH_CLIENT_ID );
request.addBodyParameter( "client_secret", GPlusConfig.GPLUS_OAUTH_CLIENT_SECRET );
request.addBodyParameter( "grant_type", "refresh_token" );
Response response = request.send();
if ( response.getCode() == 200 )
{
String accessToken = Helper.extractJsonStringField( response.getBody(), "access_token" );
AccountPrefs.updateGPlusAccessToken( accessToken );
Helper.debug( "Google access token updated and stored successfully" );
}
else
{
String failure = "Failed to update google access token";
Helper.debug( failure );
throw new IOException( failure );
}
}
示例7: executeScript
import org.scribe.model.Response; //导入方法依赖的package包/类
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);
}
}
示例8: sendVideoChunk
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* Send a chunk of the upload to the vimeo endpoint
*
* @param endpoint
* @param contentLength
* @param contentType
* @param contentRange
* @param chunk
* @param addContentRange
* @return
*/
private static long sendVideoChunk(String endpoint, String contentLength, String contentType, String contentRange,
byte[] chunk, boolean addContentRange){
OAuthRequest req = new OAuthRequest(Verb.PUT, endpoint);
req.addHeader("Content-Length", contentLength);
req.addHeader("Content-Type",contentType);
if (addContentRange){
req.addHeader("Content-Range","bytes " + contentRange);
}
req.addPayload(chunk);
service.signRequest(secretToken, req);
//printRequest(req,"Send Video To" + endpoint); //DEBUG
Response resp = req.send();
if(resp.getCode() != 200 && !resp.isSuccessful()){
return -1;
}
return verifyUpload(endpoint);
}
示例9: sendRequest
import org.scribe.model.Response; //导入方法依赖的package包/类
public ClientResponse sendRequest(String uri, Verb verb, ParamList paramList, ParamList headers) throws TagMyCodeException {
OAuthRequest request = signRequest(uri, verb, paramList, headers);
try {
Response response = request.send();
if (response.getCode() == 401) {
refreshOauthToken();
request = signRequest(uri, verb, paramList, headers);
response = request.send();
}
return getClientResponse(response);
} catch (OAuthException ex) {
throw new TagMyCodeConnectionException(ex);
}
}
示例10: newApiException
import org.scribe.model.Response; //导入方法依赖的package包/类
protected XeroApiException newApiException(Response response) {
ApiException exception = null;
try {
exception = unmarshallResponse(response.getBody(), ApiException.class);
} catch (Exception e) {
}
// Jibx doesn't support xsi:type, so we pull out errors this somewhat-hacky way
Matcher matcher = MESSAGE_PATTERN.matcher(response.getBody());
StringBuilder messages = new StringBuilder();
while (matcher.find()) {
if (messages.length() > 0) {
messages.append(", ");
}
messages.append(matcher.group(1));
}
if (exception == null) {
if (messages.length() > 0) {
return new XeroApiException(response.getCode(), messages.toString());
}
return new XeroApiException(response.getCode());
}
return new XeroApiException(response.getCode(), "Error number " + exception.getErrorNumber() + ". " + messages);
}
示例11: get
import org.scribe.model.Response; //导入方法依赖的package包/类
protected com.connectifier.xeroclient.models.Response get(String endPoint, Date modifiedAfter, Map<String,String> params) {
OAuthRequest request = new OAuthRequest(Verb.GET, BASE_URL + endPoint);
if (modifiedAfter != null) {
request.addHeader("If-Modified-Since", utcFormatter.format(modifiedAfter));
}
if (params != null) {
for (Map.Entry<String,String> param : params.entrySet()) {
request.addQuerystringParameter(param.getKey(), param.getValue());
}
}
service.signRequest(token, request);
Response response = request.send();
if (response.getCode() != 200) {
throw newApiException(response);
}
return unmarshallResponse(response.getBody(), com.connectifier.xeroclient.models.Response.class);
}
示例12: handle
import org.scribe.model.Response; //导入方法依赖的package包/类
public void handle(Request request, Response response) {
switch (response.getCode()) {
case 400:
on400();
break;
case 401:
on401();
break;
case 403:
on403();
break;
case 404:
on404();
break;
case 412:
on412();
break;
case 500:
on500();
break;
}
}
示例13: executeRequest
import org.scribe.model.Response; //导入方法依赖的package包/类
protected Response executeRequest(OAuthRequest request) throws RavelryException {
if (PrefsUtils.isSet(prefs.accessToken())
&& PrefsUtils.isSet(prefs.username())) {
signRequest(request);
request.setConnectTimeout(10, TimeUnit.SECONDS);
final Response response = request.send();
switch (response.getCode()) {
case 200:
case 304:
return response;
case 401:
case 403:
case 404:
throw new RavelryException(response.getCode());
default:
Log.w("TAG", request.getCompleteUrl());
throw new IllegalArgumentException(
"Unknown Response code: "
+ response.getCode());
}
} else {
throw new RavelryException(401);
}
}
示例14: clear
import org.scribe.model.Response; //导入方法依赖的package包/类
ResponseWrapper clear(Response response) {
if (response.getCode() == 200 || response.getCode() == 201) {
String json = response.getBody();
try {
Gson gson = new GsonBuilder().
registerTypeAdapter(JsonElement.class, new JsonElementDeserializer()).
create();
ResponseWrapper wrapper = gson.fromJson(json, ResponseWrapper.class);
if (wrapper == null) {
throw new JumblrException(response);
}
wrapper.setClient(client);
return wrapper;
} catch (JsonSyntaxException ex) {
throw new JumblrException(response);
}
} else {
throw new JumblrException(response);
}
}
示例15: JumblrException
import org.scribe.model.Response; //导入方法依赖的package包/类
/**
* Instantiate a new JumblrException given a bad response to wrap
* @param response the response to wrap
*/
public JumblrException(Response response) {
this.responseCode = response.getCode();
String body = response.getBody();
JsonParser parser = new JsonParser();
try {
final JsonElement element = parser.parse(body);
if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
this.extractMessage(object);
this.extractErrors(object);
} else {
this.message = body;
}
} catch (JsonParseException ex) {
this.message = body;
}
}