當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponse.getStatus方法代碼示例

本文整理匯總了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();
}
 
開發者ID:dixantmittal,項目名稱:scalable-task-scheduler,代碼行數:22,代碼來源:HttpUtils.java

示例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());
    }
}
 
開發者ID:simplesteph,項目名稱:kafka-connect-github-source,代碼行數:25,代碼來源:GitHubSourceTaskTest.java

示例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());
    }
}
 
開發者ID:julianghionoiu,項目名稱:tdl-runner-scala,代碼行數:24,代碼來源:RecordingSystem.java

示例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());
    }
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:14,代碼來源:Requester.java

示例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();
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:8,代碼來源:DownloadFactory.java

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

    }
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:35,代碼來源:RemoteTokenService.java

示例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;
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:8,代碼來源:SiaUtil.java

示例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;
}
 
開發者ID:MinsxCloud,項目名稱:minsx-framework,代碼行數:43,代碼來源:SystemServiceImpl.java

示例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);
        }
    }
 
開發者ID:Sybit-Education,項目名稱:airtable.java,代碼行數:37,代碼來源:HttpResponseExceptionHandler.java

示例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;
    }
 
開發者ID:Sybit-Education,項目名稱:airtable.java,代碼行數:39,代碼來源:Table.java

示例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();
}
 
開發者ID:stevespringett,項目名稱:vulndb-data-mirror,代碼行數:19,代碼來源:VulnDbApi.java

示例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();
}
 
開發者ID:stevespringett,項目名稱:vulndb-data-mirror,代碼行數:24,代碼來源:VulnDbApi.java

示例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();
}
 
開發者ID:HearthProject,項目名稱:OneClient,代碼行數:14,代碼來源:HearthAuthentication.java

示例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;
}
 
開發者ID:HearthProject,項目名稱:OneClient,代碼行數:14,代碼來源:HearthAuthentication.java

示例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;
}
 
開發者ID:julianghionoiu,項目名稱:tdl-runner-scala,代碼行數:13,代碼來源:RecordingSystem.java


注:本文中的com.mashape.unirest.http.HttpResponse.getStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。