本文整理汇总了Java中io.vertx.core.http.HttpClientResponse.statusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientResponse.statusCode方法的具体用法?Java HttpClientResponse.statusCode怎么用?Java HttpClientResponse.statusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpClientResponse
的用法示例。
在下文中一共展示了HttpClientResponse.statusCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkHttpSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
* A helper function that checks the response code for a client or server error state 4xx, 5xx
* @param response the response from a http request
* @throws HttpException if 4xx or 5xx
*/
static void checkHttpSuccess(HttpClientResponse response) throws HttpException {
int category = response.statusCode() / 100;
if (category == 4 || category == 5) {
throw new HttpException(response, "HTTP request failed with status code " + response.statusCode());
}
}
示例2: responseEnd
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
* Handles request time measurements and builds the data point
*
* @param requestMetric If the request is not be tracked this will be null
* @param response http client response
*/
@Override
public void responseEnd(@Nullable final HttpRequestMetrics requestMetric, final HttpClientResponse response) {
if (requestMetric == null) {
return;
}
String responseTime = String.valueOf(requestMetric.elapsed());
super.addMetric(
new HttpClientDataPoint(super.getOptions(), "execution", requestMetric.getRequestTag(),
requestMetric.getMethod(), responseTime, response.statusCode(), HttpClientDataPoint.Type.CLIENT)
);
}
示例3: handle
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
default void handle(HttpClientResponse response) {
getFuture().setRawResponse(response);
int code = response.statusCode();
if (code >= 200 && code < 300) {
handleSuccess(response);
} else if (code == 304) {
handleNotModified(response);
} else {
handleError(response);
}
}
示例4: handleSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
* Handle the mesh response. This method will deserialise the JSON response.
*/
public void handleSuccess(HttpClientResponse response) {
String contentType = response.getHeader("Content-Type");
//FIXME TODO in theory it would also be possible that a customer uploads JSON into mesh. In those cases we would also need to return it directly (without parsing)
if (contentType == null && response.statusCode() == NO_CONTENT.code()) {
if (log.isDebugEnabled()) {
log.debug("Got {" + NO_CONTENT.code() + "} response.");
}
future.complete();
} else if (contentType != null && contentType.startsWith(HttpConstants.APPLICATION_JSON)) {
response.bodyHandler(bh -> {
String json = bh.toString();
if (log.isDebugEnabled()) {
log.debug(json);
}
try {
T restObj = JsonUtil.readValue(json, classOfT);
future.complete(restObj);
} catch (Exception e) {
log.error("Failed to deserialize json to class {" + classOfT + "}", e);
future.fail(e);
}
});
} else {
//TODO move regular string success handler into dedicated interface
if (classOfT.isAssignableFrom(String.class)) {
response.bodyHandler(buffer -> {
future.complete((T) buffer.toString());
});
} else {
response.bodyHandler(buffer -> {
future.fail(new RuntimeException("Request can't be handled by this handler since the content type was {" + contentType + "}"));
});
}
}
}
示例5: handleSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
default void handleSuccess(HttpClientResponse response) {
String contentType = response.getHeader("Content-Type");
// FIXME TODO in theory it would also be possible that a customer uploads JSON into mesh. In those cases we would also need to return it directly
// (without parsing)
if (contentType == null && response.statusCode() == NO_CONTENT.code()) {
if (log.isDebugEnabled()) {
log.debug("Got {" + NO_CONTENT.code() + "} response.");
}
getFuture().complete();
} else if (contentType.startsWith(HttpConstants.APPLICATION_JSON)) {
response.bodyHandler(bh -> {
String json = bh.toString();
if (log.isDebugEnabled()) {
log.debug(json);
}
try {
getFuture().setBodyJson(json);
getFuture().complete(new JsonObject(json));
} catch (Exception e) {
log.error("Failed to deserialize json", e);
getFuture().fail(e);
}
});
} else {
response.bodyHandler(buffer -> {
getFuture().fail(new RuntimeException("Request can't be handled by this handler since the content type was {" + contentType + "}"));
});
}
}
示例6: handle
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpClientResponse httpClientResponse) {
if (HttpResponseStatus.UNAUTHORIZED.code() == httpClientResponse.statusCode() &&
!request.authSchemes().containsKey(request.uri())) {
if (httpClientResponse.headers() != null) {
final String headerAuthenticate = httpClientResponse.headers().get("WWW-Authenticate");
if (headerAuthenticate != null) {
final String[] parts = headerAuthenticate.trim().split("\\s+", 2);
if (parts.length == 2) {
final AuthScheme.Type schemeNeeded = AuthScheme.Type.valueOf(parts[0].toUpperCase());
if (schemeNeeded != null) {
final AuthScheme authScheme;
if (schemeNeeded == request.realm().getSchemeType()) {
authScheme = AuthSchemeFactory.newScheme(request.realm());
} else {
authScheme = AuthSchemeFactory.newScheme(request.realm(), schemeNeeded);
}
if (AuthScheme.Type.DIGEST == authScheme.getType()) {
authScheme.schemeParts(new String[]{parts[1], request.method(), request.uri()});
}
request.authorize(request.uri(), authScheme).execute();
return;
}
}
}
}
}
responseHandler.handle(new DefaultResponse(httpClientResponse));
}
示例7: DefaultResponse
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
public DefaultResponse(HttpClientResponse response) {
this.response = response;
this.statusCode = response.statusCode();
this.statusMessage = response.statusMessage();
MultiMap headers = response.headers();
this.format = HttpUtils.extractFormat(headers);
this.documentUri = HttpUtils.extractDocumentUri(headers);
this.contentLength = HttpUtils.extractContentLength(headers);
this.contentType = HttpUtils.extractContentType(headers);
}