本文整理汇总了Java中com.mashape.unirest.http.HttpResponse.getStatus方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getStatus方法的具体用法?Java HttpResponse.getStatus怎么用?Java HttpResponse.getStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mashape.unirest.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processHttpRequest
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
public static String processHttpRequest(String completeURL,
Map<String, Object> params,
Map<String, String> customHeaders,
HttpMethod method) throws IOException {
Map<String, String> headers = getDefaultHeader();
if (customHeaders != null) {
headers.putAll(customHeaders);
}
HttpResponse<JsonNode> result = executeHttpMethod(completeURL, params, headers, method);
if (result == null) {
return null;
}
if (result.getStatus() != 200) {
String exceptionResponse = result.getBody().toString();
throw new ServiceException((result.getStatus() + result.getStatusText()),
exceptionResponse);
}
return result.getBody().toString();
}
示例2: test
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
@Test
public void test() throws UnirestException {
gitHubSourceTask.config = new GitHubSourceConnectorConfig(initialConfig());
gitHubSourceTask.nextPageToVisit = 1;
gitHubSourceTask.nextQuerySince = Instant.parse("2017-01-01T00:00:00Z");
gitHubSourceTask.gitHubHttpAPIClient = new GitHubAPIHttpClient(gitHubSourceTask.config);
String url = gitHubSourceTask.gitHubHttpAPIClient.constructUrl(gitHubSourceTask.nextPageToVisit, gitHubSourceTask.nextQuerySince);
System.out.println(url);
HttpResponse<JsonNode> httpResponse = gitHubSourceTask.gitHubHttpAPIClient.getNextIssuesAPI(gitHubSourceTask.nextPageToVisit, gitHubSourceTask.nextQuerySince);
if (httpResponse.getStatus() != 403) {
assertEquals(200, httpResponse.getStatus());
Set<String> headers = httpResponse.getHeaders().keySet();
assertTrue(headers.contains("ETag"));
assertTrue(headers.contains("X-RateLimit-Limit"));
assertTrue(headers.contains("X-RateLimit-Remaining"));
assertTrue(headers.contains("X-RateLimit-Reset"));
assertEquals(batchSize.intValue(), httpResponse.getBody().getArray().length());
JSONObject jsonObject = (JSONObject) httpResponse.getBody().getArray().get(0);
Issue issue = Issue.fromJson(jsonObject);
assertNotNull(issue);
assertNotNull(issue.getNumber());
assertEquals(2072, issue.getNumber().intValue());
}
}
示例3: notifyEvent
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
static void notifyEvent(String lastFetchedRound, String shortName) {
System.out.printf("Notify round \"%s\", event \"%s\"%n", lastFetchedRound, shortName);
if (!isRecordingRequired()) {
return;
}
try {
HttpResponse<String> stringHttpResponse = Unirest.post(RECORDING_SYSTEM_ENDPOINT + "/notify")
.body(lastFetchedRound+"/"+shortName)
.asString();
if (stringHttpResponse.getStatus() != 200) {
System.err.println("Recording system returned code: "+stringHttpResponse.getStatus());
return;
}
if (!stringHttpResponse.getBody().startsWith("ACK")) {
System.err.println("Recording system returned body: "+stringHttpResponse.getStatus());
}
} catch (UnirestException e) {
System.err.println("Could not reach recording system: " + e.getMessage());
}
}
示例4: handleErrorCode
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void handleErrorCode(HttpResponse response) {
HttpCode error = HttpCode.getByKey(response.getStatus());
if (error.isServerError() || error.isFailure()) {
if (error.equals(HttpCode.TOO_MANY_REQUESTS)) { // Rate limited
checkRateLimit(response);
} else {
throw new HttpErrorException(error);
}
} else if (error == HttpCode.UNKNOWN){
throw new HttpErrorException(response.getStatus(), response.getStatusText());
}
}
示例5: downloadLatestMetadataZip
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
protected InputStream downloadLatestMetadataZip(String token) throws UnirestException {
final HttpResponse<InputStream> response = Unirest.get(metadataUrl + "file/latestMeta")
.header("X-Auth-Token", token)
.asBinary();
if (response.getStatus() == 404) return null;
return response.getBody();
}
示例6: getToken
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
public Optional<String> getToken() {
final ListenableFuture<String> masterPassword = encyptionKeyProvider.getMasterPassword();
if (!masterPassword.isDone()) {
return Optional.empty();
}
final String key = encyptionKeyProvider.getImmediatePassword();
final String s = key + " meta";
final ECKey privKey = ECKey.fromPrivate(Sha256Hash.twiceOf(s.getBytes(Charsets.UTF_8)).getBytes());
/*
@POST
@Path("/token")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response createToken(@QueryParam("timestamp") Long nonce, @QueryParam("signature") String signature) {
*/
// }
final long timeStamp = Instant.now().toEpochMilli();
try {
final String url = rootPath + "auth/token";
final HttpResponse<String> token = Unirest.post(url)
.queryString("timestamp", timeStamp)
.queryString("signature", privKey.signMessage(String.valueOf(timeStamp)))
.asString();
if (token.getStatus() != 200) {
return Optional.empty();
}
return Optional.of(token.getBody());
} catch (UnirestException e) {
LOGGER.error("exception from remote service when trying to get token", e);
return Optional.empty();
}
}
示例7: statusGood
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
private static boolean statusGood(HttpResponse<String> response) {
if (response == null) {
return false;
}
final int status = response.getStatus();
return status >= 200 && status < 300;
}
示例8: getToken
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
/**
* 该方法用于后台取Token
*/
public Map<String, Object> getToken(HttpServletRequest request) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("isSuccess", false);
String username = request.getParameter("username");
String password = request.getParameter("password");
String accessId = request.getParameter("accessId");
String accessSecret = request.getParameter("accessSecret");
if (username == null || password == null) {
username = accessId;
password = accessSecret;
}
if (username == null || password == null) {
result.put("reason", "Parameter Error");
return result;
}
HttpResponse<String> response;
try {
String url = "http://localhost:8080/loginServer/oauth/token?grant_type=password&username=%s&password=%s";
response = Unirest.post(String.format(url, username, password))
.header("authorization", "Basic Z29vZHNhdmU6Z29vZHNhdmU=")
.header("cache-control", "no-cache")
.asString();
if (response.getStatus() >= 200 && response.getStatus() < 400) {
result.put("isSuccess", true);
result.put("access_token", JSON.parseObject(response.getBody()).get("access_token"));
result.put("token_type", JSON.parseObject(response.getBody()).get("token_type"));
result.put("refresh_token", JSON.parseObject(response.getBody()).get("refresh_token"));
result.put("expires_in", JSON.parseObject(response.getBody()).get("expires_in"));
result.put("scope", JSON.parseObject(response.getBody()).get("scope"));
} else {
result.put("reason", "username or password failed");
}
} catch (UnirestException e) {
e.printStackTrace();
result.put("isSuccess", false);
result.put("reason", "inner error");
}
return result;
}
示例9: onResponse
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
public static void onResponse(HttpResponse response) throws AirtableException {
final Integer statusCode = response.getStatus();
String message = convertStreamToString(response.getRawBody());
final Gson gson = new Gson();
Error err = gson.fromJson(message, Error.class);
switch (statusCode) {
case 401:
throw new AirtableException("AUTHENTICATION_REQUIRED", "You should provide valid api key to perform this operation", statusCode);
case 403:
throw new AirtableException("NOT_AUTHORIZED", "You are not authorized to perform this operation", statusCode);
case 404:
message = ( err.getMessage() != null) ? err.getMessage() : "Could not find what you are looking for";
throw new AirtableException("NOT_FOUND", message, statusCode);
case 413:
throw new AirtableException("REQUEST_TOO_LARGE", "Request body is too large", statusCode);
case 422:
throw new AirtableException(err.getType(), err.getMessage(), statusCode);
case 429:
throw new AirtableException("TOO_MANY_REQUESTS", "You have made too many requests in a short period of time. Please retry your request later", statusCode);
case 500:
throw new AirtableException("SERVER_ERROR", "Try again. If the problem persists, contact support.", statusCode);
case 503:
throw new AirtableException("SERVICE_UNAVAILABLE", "The service is temporarily unavailable. Please retry shortly.", statusCode);
default:
throw new AirtableException("UNDEFINED_ERROR", message, statusCode);
}
}
示例10: destroy
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
/**
* Delete Record by given id
*
* @param id Id of the row to delete.
* @return true if success.
* @throws AirtableException
*/
public boolean destroy(String id) throws AirtableException {
boolean isDeleted;
HttpResponse<Delete> response;
try {
response = Unirest.delete(getTableEndpointUrl() + "/" + id)
.header("accept", MIME_TYPE_JSON)
.header("Authorization", getBearerToken())
.asObject(Delete.class);
} catch (UnirestException e) {
throw new AirtableException(e);
}
int code = response.getStatus();
if (200 == code) {
Delete body = response.getBody();
isDeleted = body.isDeleted();
} else {
isDeleted = false;
HttpResponseExceptionHandler.onResponse(response);
}
// if (!body.isDeleted()) {
// throw new AirtableException("Record id: " + body.getId() + " could not be deleted.");
// }
return isDeleted;
}
示例11: getStatus
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
/**
* Makes a request and returns {@link Status}.
*
* @return a Results object
* @since 1.0.0
*/
public Status getStatus() {
final HttpResponse<JsonNode> response = makeRequest(STATUS_URL);
if (response != null) {
if (response.getStatus() == 200) {
final VulnDbParser parser = new VulnDbParser();
return parser.parseStatus(response.getBody());
} else {
logHttpResponseError(response);
}
}
return new Status();
}
示例12: getResults
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
/**
* Makes a request and returns the results
*
* @param url the URL being requested
* @param clazz the model vulndb model class to parse
* @param size the number of items to fetch
* @param page the page number of the fetched items
* @return a parsed Results object
* @since 1.0.0
*/
private Results getResults(String url, Class clazz, int size, int page) {
url = (url.contains("?")) ? url + "&" : url + "?";
final HttpResponse<JsonNode> response = makeRequest(url + "size=" + size + "&page=" + page);
if (response != null) {
if (response.getStatus() == 200) {
final VulnDbParser parser = new VulnDbParser();
return parser.parse(response.getBody(), clazz);
} else {
logHttpResponseError(response);
}
}
return new Results();
}
示例13: login
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
public void login(YggdrasilUserAuthentication auth) throws Exception {
if(!auth.isLoggedIn()){
throw new Exception("You must be logged with with mojang before you can log into hearth");
}
HttpResponse<String> response = Unirest.post(HearthApi.API_URL + "/auth/login/" + auth.getAuthenticatedToken() + "/" + auth.getAuthenticationService().getClientToken()).asString();
if (response.getStatus() == 403) {
throw new Exception(response.getBody());
}
OneClientLogging.logger.info("Successfully logged into hearth");
authentication = JsonUtil.GSON.fromJson(response.getBody(), ClientAuthentication.class);
MinecraftAuthController.setAccessToken(auth, authentication.accessToken);
ContentPanes.PRIVATE_PACK_PANE.onLogin();
}
示例14: getUser
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
public User getUser() throws UnirestException {
OneClientLogging.logger.info("Getting user details");
if (authentication == null || authentication.accessToken.isEmpty()) {
return null;
}
HttpResponse<String> response = Unirest.get(HearthApi.API_URL + "/" + authentication.accessToken + "/user/data").asString();
if (response.getStatus() == 403) {
OneClientLogging.logger.error("Failed to get client permissions");
return null;
}
User user = JsonUtil.GSON.fromJson(response.getBody(), User.class);
return user;
}
示例15: isRunning
import com.mashape.unirest.http.HttpResponse; //导入方法依赖的package包/类
private static boolean isRunning() {
try {
HttpResponse<String> stringHttpResponse = Unirest.get(RECORDING_SYSTEM_ENDPOINT + "/status").asString();
if (stringHttpResponse.getStatus() == 200 && stringHttpResponse.getBody().startsWith("OK")) {
return true;
}
} catch (UnirestException e) {
System.err.println("Could not reach recording system: " + e.getMessage());
}
return false;
}