本文整理汇总了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();
}
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例10: setResponseData
public void setResponseData(HttpEntity entity) {
mStatusCode = HttpStatus.SC_OK;
mResponseEntity = entity;
}
示例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;
}
示例12: isSuccess
public boolean isSuccess() {
return statusCode == HttpStatus.SC_OK && result != null;
}
示例13: setErrorCode
public void setErrorCode(int statusCode) {
if (statusCode == HttpStatus.SC_OK) {
throw new IllegalArgumentException("statusCode cannot be 200 for an error");
}
mStatusCode = statusCode;
}
示例14: NetworkResponse
public NetworkResponse(byte[] data) {
this(HttpStatus.SC_OK, data, Collections.<String, String>emptyMap(), false, 0);
}
示例15: NetworkResponse
public NetworkResponse(byte[] data, Map<String, String> headers) {
this(HttpStatus.SC_OK, data, headers, false);
}