io.vertx.reactivex.ext.web.client.HttpResponse.statusCode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中io.vertx.reactivex.ext.web.client.HttpResponse.statusCode()方法的一些代码示例,展示了HttpResponse.statusCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.statusCode()方法的具体详情如下:
包路径:io.vertx.reactivex.ext.web.client.HttpResponse
类名称:HttpResponse
方法名:statusCode

HttpResponse.statusCode介绍

暂无

代码示例

代码示例来源:origin: nemtech/nem2-sdk-java

static JsonObject mapJsonObjectOrError(final HttpResponse<JsonObject> response) {
  if (response.statusCode() < 200 || response.statusCode() > 299) {
    throw new RuntimeException(response.statusMessage());
  }
  return response.body();
}

代码示例来源:origin: nemtech/nem2-sdk-java

static JsonArray mapJsonArrayOrError(final HttpResponse<JsonArray> response) {
    if (response.statusCode() < 200 || response.statusCode() > 299) {
      throw new RuntimeException(response.statusMessage());
    }
    return response.body();
  }
}

代码示例来源:origin: io.knotx/knotx-databridge-adapter-http

private void logResponse(Pair<ClientRequest, HttpDataSourceSettings> request,
             HttpResponse<Buffer> resp) {
 if (resp.statusCode() >= 400 && resp.statusCode() < 600) {
  LOGGER.error("{} {} -> Got response {}, headers[{}]",
    logResponseData(request, resp));
 } else if (LOGGER.isDebugEnabled()) {
  LOGGER.debug("{} {} -> Got response {}, headers[{}]",
    logResponseData(request, resp));
 }
}

代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http

private void logResponse(Pair<ClientRequest, HttpFormsSettings> request,
  HttpResponse<Buffer> resp) {
 if (resp.statusCode() >= 400 && resp.statusCode() < 600) {
  LOGGER.error("{} {} -> Got response {}, headers[{}]",
    logResponseData(request, resp));
 } else if (LOGGER.isDebugEnabled()) {
  LOGGER.debug("{} {} -> Got response {}, headers[{}]",
    logResponseData(request, resp));
 }
}

代码示例来源:origin: Cognifide/knotx

private void logResponse(Pair<ClientRequest, ServiceSettings> request,
  HttpResponse<Buffer> resp) {
 if (resp.statusCode() >= 400 && resp.statusCode() < 600) {
  LOGGER.error("{} {} -> Got response {}, headers[{}]",
    logResponseData(request, resp));
 } else if (LOGGER.isDebugEnabled()) {
  LOGGER.debug("{} {} -> Got response {}, headers[{}]",
    logResponseData(request, resp));
 }
}

代码示例来源:origin: io.knotx/knotx-databridge-adapter-http

private Object[] logResponseData(Pair<ClientRequest, HttpDataSourceSettings> request,
                 HttpResponse<Buffer> resp) {
 Object[] data = {
   request.getLeft().getMethod(),
   toUrl(request),
   resp.statusCode(),
   DataObjectsUtil.toString(resp.headers())};
 return data;
}

代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http

private Object[] logResponseData(Pair<ClientRequest, HttpFormsSettings> request,
  HttpResponse<Buffer> resp) {
 Object[] data = {
   request.getLeft().getMethod(),
   toUrl(request),
   resp.statusCode(),
   DataObjectsUtil.toString(resp.headers())};
 return data;
}

代码示例来源:origin: Cognifide/knotx

private Object[] logResponseData(Pair<ClientRequest, ServiceSettings> request,
  HttpResponse<Buffer> resp) {
 Object[] data = {
   request.getLeft().getMethod(),
   toUrl(request),
   resp.statusCode(),
   DataObjectsUtil.toString(resp.headers())};
 return data;
}

代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch

@Override
public Completable putTemplate(String templateName, String template) {
  return httpClient
      .put(URL_TEMPLATE + '/' + templateName)
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
      .rxSendBuffer(Buffer.buffer(template))
      .flatMapCompletable(response -> {
        if (response.statusCode() != HttpStatusCode.OK_200) {
          logger.error("Unable to put template mapping: status[{}] template[{}] response[{}]",
              response.statusCode(), template, response.body());
          return Completable.error(new ElasticsearchException("Unable to put template mapping"));
        }
        return Completable.complete();
      });
}

代码示例来源:origin: io.knotx/knotx-databridge-adapter-http

private Single<ClientResponse> wrapResponse(HttpResponse<Buffer> response) {
 return toBody(response)
   .doOnSuccess(this::traceServiceCall)
   .map(buffer -> new ClientResponse()
     .setBody(buffer.getDelegate())
     .setHeaders(response.headers())
     .setStatusCode(response.statusCode())
   );
}

代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http

private Single<ClientResponse> wrapResponse(HttpResponse<Buffer> response) {
 return toBody(response)
   .doOnSuccess(this::traceServiceCall)
   .map(buffer -> new ClientResponse()
     .setBody(buffer.getDelegate())
     .setHeaders(response.headers())
     .setStatusCode(response.statusCode())
   );
}

代码示例来源:origin: Cognifide/knotx

private Single<ClientResponse> wrapResponse(HttpResponse<Buffer> response) {
 return toBody(response)
   .doOnSuccess(this::traceServiceCall)
   .map(buffer -> new ClientResponse()
     .setBody(buffer.getDelegate())
     .setHeaders(response.headers())
     .setStatusCode(response.statusCode())
   );
}

代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-github

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-oauth2-generic

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

代码示例来源:origin: Cognifide/knotx

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server.json")
public void whenRequestingPostGlobalPathAndActionDoRedirect_expectRedirectResponse(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleFailingKnot(vertx, "A-post-engine", HttpResponseStatus.MOVED_PERMANENTLY.code(),
   MultiMap.caseInsensitiveMultiMap().add("location", "/content/failed.html"));
 testPostRequest(context, vertx, "/content/local/simple.html", resp -> {
  assertEquals(HttpResponseStatus.MOVED_PERMANENTLY.code(), resp.statusCode());
  assertEquals("/content/failed.html", resp.getHeader("location"));
  assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
  assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
    resp.getHeader(EXPECTED_RESPONSE_HEADER));
 });
}

代码示例来源:origin: Cognifide/knotx

private void testGetRequest(VertxTestContext context, Vertx vertx, String url,
  String expectedResult) {
 WebClient client = WebClient.create(vertx);
 Single<HttpResponse<Buffer>> httpResponseSingle = client
   .get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url).rxSend();
 subscribeToResult_shouldSucceed(context, httpResponseSingle,
   resp -> {
    assertEquals(expectedResult, resp.body().toString(),
      "Wrong engines processed request, expected " + expectedResult);
    assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
    assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
    assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
      resp.getHeader(EXPECTED_RESPONSE_HEADER));
   });
}

代码示例来源:origin: Cognifide/knotx

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostSecureWithoutCSRF_expectForbidden(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleKnot(vertx, "some-knot", "test", null);
 MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
 WebClient client = WebClient.create(vertx);
 Single<HttpResponse<Buffer>> httpResponseSingle = client
   .post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
   .rxSendForm(body);
 subscribeToResult_shouldSucceed(context, httpResponseSingle, result -> {
  assertEquals(HttpResponseStatus.FORBIDDEN.code(), result.statusCode());
 });
}

代码示例来源:origin: Cognifide/knotx

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostPublicWithoutCSRF_expectOk(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleKnot(vertx, "some-knot", "test", null);
 MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
 WebClient client = WebClient.create(vertx);
 Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> httpResponseSingle = client
   .post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/public.html")
   .rxSendForm(body);
 subscribeToResult_shouldSucceed(context, httpResponseSingle, resp -> {
  assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
 });
}

相关文章