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


Java HttpStatus.SC_OK屬性代碼示例

本文整理匯總了Java中org.apache.http.HttpStatus.SC_OK屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.SC_OK屬性的具體用法?Java HttpStatus.SC_OK怎麽用?Java HttpStatus.SC_OK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.http.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.SC_OK屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: postHandle

@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response,
                             final Object o, final ModelAndView modelAndView) throws Exception {
    if (!HttpMethod.POST.name().equals(request.getMethod())) {
        return;
    }

    final boolean recordEvent = response.getStatus() != HttpStatus.SC_CREATED
                             && response.getStatus() != HttpStatus.SC_OK;

    if (recordEvent) {
        LOGGER.debug("Recording submission failure for [{}]", request.getRequestURI());
        recordSubmissionFailure(request);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:15,代碼來源:AbstractThrottledSubmissionHandlerInterceptorAdapter.java

示例2: ensureApiCalled

private void ensureApiCalled() {

        if (!this.available) {
            return;
        }

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpGet getRequest = new HttpGet(RELEASE_COVERS_ENDPOINT + releaseId);
        getRequest.addHeader("accept", "application/json");

        try {

            HttpResponse response = httpClient.execute(getRequest);
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                this.available = false;
                return;
            }

            this.coverArtResponse = mapper.readValue(response.getEntity().getContent(), CoverArtArchiveResponse.class);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:mapr-demos,項目名稱:mapr-music,代碼行數:24,代碼來源:CoverArtArchiveClient.java

示例3: doActivate

/**
 * Perform the replication. All logic is covered in {@link ElasticSearchIndexContentBuilder} so we only need to transmit the JSON to ElasticSearch
 *
 * @param ctx
 * @param tx
 * @param restClient
 * @return
 * @throws ReplicationException
 */
private ReplicationResult doActivate(TransportContext ctx, ReplicationTransaction tx, RestClient restClient) throws ReplicationException, JSONException, IOException {
  ReplicationLog log = tx.getLog();
  ObjectMapper mapper = new ObjectMapper();
  IndexEntry content = mapper.readValue(tx.getContent().getInputStream(), IndexEntry.class);
  if (content != null) {
    log.info(getClass().getSimpleName() + ": Indexing " + content.getPath());
    String contentString = mapper.writeValueAsString(content.getContent());
    log.debug(getClass().getSimpleName() + ": Index-Content: " + contentString);
    LOG.debug("Index-Content: " + contentString);

    HttpEntity entity = new NStringEntity(contentString, "UTF-8");
    Response indexResponse = restClient.performRequest(
            "PUT",
            "/" + content.getIndex() + "/" + content.getType() + "/" + DigestUtils.md5Hex(content.getPath()),
            Collections.<String, String>emptyMap(),
            entity);
    LOG.debug(indexResponse.toString());
    log.info(getClass().getSimpleName() + ": " + indexResponse.getStatusLine().getStatusCode() + ": " + indexResponse.getStatusLine().getReasonPhrase());
    if (indexResponse.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED || indexResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      return ReplicationResult.OK;
    }
  }
  LOG.error("Could not replicate");
  return new ReplicationResult(false, 0, "Replication failed");
}
 
開發者ID:deveth0,項目名稱:elasticsearch-aem,代碼行數:34,代碼來源:ElasticSearchTransportHandler.java

示例4: introspect

@Override
public String introspect(String token) throws IOException
{
    HttpPost post = new HttpPost(_introspectionUri);

    post.setHeader(ACCEPT, ContentType.APPLICATION_JSON.getMimeType());

    List<NameValuePair> params = new ArrayList<>(3);

    params.add(new BasicNameValuePair("token", token));
    params.add(new BasicNameValuePair("client_id", _clientId));
    params.add(new BasicNameValuePair("client_secret", _clientSecret));

    post.setEntity(new UrlEncodedFormEntity(params));

    HttpResponse response = _httpClient.execute(post);

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
    {
        _logger.severe(() -> "Got error from introspection server: " + response.getStatusLine().getStatusCode());

        throw new IOException("Got error from introspection server: " + response.getStatusLine().getStatusCode());
    }

    return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
}
 
開發者ID:curityio,項目名稱:oauth-filter-for-java,代碼行數:26,代碼來源:DefaultIntrospectClient.java

示例5: accountAuth

/**
 * 正しい認証情報を使用してすべてのユーザがアクセス可能なコレクションに対して$batchをした場合処理が受付けられること.
 * batchの実行順
 * 1.POST(登録)
 * 2.GET(一覧取得)
 * 3.GET(取得)
 * 4.PUT(更新)
 * 5.DELETE(削除)
 */
@Test
public final void 正しい認証情報を使用してすべてのユーザがアクセス可能なコレクションに対して$batchをした場合処理が受付けられること() {

    // 認証トークン取得
    String[] tokens = accountAuth();
    // ※本テストではACLをSetupのデフォルト値から変更しているため、実際はREAD_WRITE権限は持っていない。
    String token = tokens[READ_WRITE];

    // ACL設定
    String path = String.format("%s/%s/%s", TEST_CELL1, BOX_NAME, COL_NAME);
    DavResourceUtils.setACLPrivilegeAllForAllUser(TEST_CELL1, MASTER_TOKEN, HttpStatus.SC_OK, path, "none");

    // READとWRITE→全てOK
    TResponse res = UserDataUtils.batch(TEST_CELL1, BOX_NAME, COL_NAME, BOUNDARY, TEST_BODY,
            token, HttpStatus.SC_ACCEPTED);
    // 期待するレスポンスコード
    int[] expectedCodes = new int[] {HttpStatus.SC_CREATED,
            HttpStatus.SC_OK,
            HttpStatus.SC_OK,
            HttpStatus.SC_NO_CONTENT,
            HttpStatus.SC_NO_CONTENT };
    // レスポンスボディのチェック(ステータス)
    checkBatchResponseBody(res, expectedCodes);

}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:34,代碼來源:AuthBatchTest.java

示例6: callWebProxy

public void callWebProxy(String url) {
    String resultCode = "";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();
            resultCode = ResponseCode.CALLRESPONSEERROR;
            if (entity != null) {
                String responseString = EntityUtils.toString(entity);
                if (responseString.contains("Spark Jobs") && responseString.contains("Stages")
                        && responseString.contains("Storage") && responseString.contains("Environment")
                        && responseString.contains("Executors")) {
                    resultCode = ResponseCode.CALLSUCCESS;
                }
            }
        } else if (statusCode == HttpStatus.SC_MOVED_TEMPORARILY
                || statusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
            resultCode = ResponseCode.CALLFORBIDDEN;
        } else {
            resultCode = ResponseCode.OTHER_RESPONSE + String.valueOf(statusCode);
        }
    } catch (Exception e) {
        LOG.warn("WebProxyCall exception " + e.getMessage());
        resultCode = ResponseCode.CALLEXCEPTION;
    } finally {
        httpclient.close();
    }
    LOG.info("WebProxyCall result " + resultCode);
    if (!resultCode.equals(ResponseCode.CALLSUCCESS)) {
        System.exit(1);
    }
}
 
開發者ID:aliyun,項目名稱:aliyun-cupid-sdk,代碼行數:36,代碼來源:WebProxyCall.java

示例7: isHostActive

/**
 * Determine if the specified Selenium Grid host (hub or node) is active.
 * 
 * @param host HTTP host connection to be checked
 * @param request request path (may include parameters)
 * @return 'true' if specified host is active; otherwise 'false'
 */
private static boolean isHostActive(HttpHost host, String request) {
    try {
        HttpResponse response = getHttpResponse(host, request);
        return (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK);
    } catch (IOException e) {
        return false;
    }
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:15,代碼來源:GridUtility.java

示例8: execute

public HttpResponse execute() throws Exception {
	HttpResponse httpResponse = null;
	httpClient = HttpClients.createDefault();
	httpResponse = httpClient.execute(httpRequestBase);
	int statusCode = httpResponse.getStatusLine().getStatusCode();
	if (statusCode != HttpStatus.SC_OK && statusCode != 221) {
		String response = EntityUtils.toString(httpResponse.getEntity());
		logger.error("request failed  status:{}, response::{}",statusCode, response);
		throw new OnenetApiException("request failed: " + response);
	}
	return httpResponse;

}
 
開發者ID:cm-heclouds,項目名稱:JAVA-HTTP-SDK,代碼行數:13,代碼來源:HttpPutMethod.java

示例9: get

public GoPipelineInstance get(final String pipelineName, final int counter) {
	try {
		HttpResponse response = goApiClient.execute(new HttpGet("/go/api/pipelines/" + URLEncoder.encode(pipelineName, "UTF-8") + "/instance/" + counter));
		if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
			String content = Streams.readAsString(response.getEntity().getContent());
			return new Gson().fromJson(content, GoPipelineInstance.class);
		} else {
			Log.error("Request got HTTP-" + response.getStatusLine().getStatusCode());
		}
	} catch (IOException e) {
		Log.error("Could not perform request", e);
	}
	return null;
}
 
開發者ID:Haufe-Lexware,項目名稱:octane-gocd-plugin,代碼行數:14,代碼來源:GoGetPipelineInstance.java

示例10: setResponseData

public void setResponseData(HttpEntity entity) {
    mStatusCode = HttpStatus.SC_OK;
    mResponseEntity = entity;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:4,代碼來源:MockHttpClient.java

示例11: doMultiPart

/**
 * Executes MultiPart upload request to an endpoint with provided headers.
 *
 * @param uri
 *            endpoint that needs to be hit
 * @param file
 *            file to be uploaded
 * @param headers
 *            Key Value pair of headers
 * @return Response Body after executing Multipart
 * @throws StockException
 *             if api doesnt return with success code or when null/empty
 *             endpoint is passed in uri
 */
public static String doMultiPart(final String uri, final byte[] file,
        final Map<String, String> headers) throws StockException {
    if (sHttpClient == null) {
        sHttpClient = HttpUtils.initialize();
    }

    HttpResponse response = null;
    String responseBody = null;

    if (uri == null || uri.isEmpty()) {
        throw new StockException(-1, "URI cannot be null or Empty");
    }

    HttpPost request = new HttpPost(uri);

    if (headers != null) {
        for (Entry<String, String> entry : headers.entrySet()) {
            request.setHeader(entry.getKey(), entry.getValue());
        }
    }

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

    try {
        if (file != null) {
            String contentType = URLConnection.guessContentTypeFromStream(
                    new ByteArrayInputStream(file));
            builder.addBinaryBody("similar_image", file,
                    ContentType.create(contentType), "file");
        }
        HttpEntity entity = builder.build();
        request.setEntity(entity);
        response = sHttpClient.execute(request);

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK
                || response.getStatusLine().getStatusCode()
                    == HttpStatus.SC_CREATED) {
            responseBody = EntityUtils.toString(response.getEntity());
        } else if (response.getStatusLine().getStatusCode()
                / HTTP_STATUS_CODE_DIVISOR
                    == HTTP_STATUS_CODE_API_ERROR) {
            responseBody = EntityUtils.toString(response.getEntity());
            throw new StockException(response.getStatusLine()
                    .getStatusCode(), responseBody);
        } else if (response.getStatusLine().getStatusCode()
                / HTTP_STATUS_CODE_DIVISOR
                    == HTTP_STATUS_CODE_SERVER_ERROR) {
            throw new StockException(response.getStatusLine()
                    .getStatusCode(), "API returned with Server Error");

        }

    } catch (StockException se) {
        throw se;
    } catch (Exception ex) {
        throw new StockException(-1, ex.getMessage());
    }

    return responseBody;

}
 
開發者ID:adobe,項目名稱:stock-api-sdk,代碼行數:76,代碼來源:ApiUtils.java

示例12: isSuccess

public boolean isSuccess() {
    return statusCode == HttpStatus.SC_OK && result != null;
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:3,代碼來源:Page.java

示例13: setErrorCode

public void setErrorCode(int statusCode) {
    if (statusCode == HttpStatus.SC_OK) {
        throw new IllegalArgumentException("statusCode cannot be 200 for an error");
    }
    mStatusCode = statusCode;
}
 
開發者ID:Ace201m,項目名稱:Codeforces,代碼行數:6,代碼來源:MockHttpClient.java

示例14: NetworkResponse

public NetworkResponse(byte[] data) {
    this(HttpStatus.SC_OK, data, Collections.<String, String>emptyMap(), false, 0);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:3,代碼來源:NetworkResponse.java

示例15: NetworkResponse

public NetworkResponse(byte[] data, Map<String, String> headers) {
    this(HttpStatus.SC_OK, data, headers, false);
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:3,代碼來源:NetworkResponse.java


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