当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientResponse.statusCode方法代码示例

本文整理汇总了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());
  }
}
 
开发者ID:dazraf,项目名称:vertx-futures,代码行数:12,代码来源:HttpFutures.java

示例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)
    );
}
 
开发者ID:statful,项目名称:statful-client-vertx,代码行数:21,代码来源:HttpClientMetricsImpl.java

示例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);
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:13,代码来源:ResponseHandler.java

示例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 + "}"));
			});
		}
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:39,代码来源:ModelResponseHandler.java

示例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 + "}"));
		});
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:30,代码来源:JsonObjectSuccessHandler.java

示例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));
}
 
开发者ID:etourdot,项目名称:vertx-marklogic,代码行数:30,代码来源:AuthHttpHandler.java

示例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);
}
 
开发者ID:etourdot,项目名称:vertx-marklogic,代码行数:11,代码来源:DefaultResponse.java


注:本文中的io.vertx.core.http.HttpClientResponse.statusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。