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


Java HttpClientResponse类代码示例

本文整理汇总了Java中io.vertx.core.http.HttpClientResponse的典型用法代码示例。如果您正苦于以下问题:Java HttpClientResponse类的具体用法?Java HttpClientResponse怎么用?Java HttpClientResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpClientResponse类属于io.vertx.core.http包,在下文中一共展示了HttpClientResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: syncHandlerEx

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
private Handler<RestResponse> syncHandlerEx(CountDownLatch countDownLatch, Holder<ResponseWrapper> holder) {
  return restResponse -> {
    RequestContext requestContext = restResponse.getRequestContext();
    HttpClientResponse response = restResponse.getResponse();
    if (response == null) {
      // 请求失败,触发请求SC的其他实例
      if (!requestContext.isRetry()) {
        retry(requestContext, syncHandlerEx(countDownLatch, holder));
      } else {
        countDownLatch.countDown();
      }

      return;
    }

    response.bodyHandler(bodyBuffer -> {
      ResponseWrapper responseWrapper = new ResponseWrapper();
      responseWrapper.response = response;
      responseWrapper.bodyBuffer = bodyBuffer;
      holder.value = responseWrapper;
      countDownLatch.countDown();
    });
  };
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:ServiceRegistryClientImpl.java

示例2: unregisterMicroserviceInstance

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
@Override
public boolean unregisterMicroserviceInstance(String microserviceId, String microserviceInstanceId) {
  Holder<HttpClientResponse> holder = new Holder<>();
  IpPort ipPort = ipPortManager.getAvailableAddress();

  CountDownLatch countDownLatch = new CountDownLatch(1);
  RestUtils.delete(ipPort,
      String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ONE, microserviceId, microserviceInstanceId),
      new RequestParam(),
      syncHandler(countDownLatch, HttpClientResponse.class, holder));
  try {
    countDownLatch.await();
    if (holder.value != null) {
      if (holder.value.statusCode() == Status.OK.getStatusCode()) {
        return true;
      }
      LOGGER.warn(holder.value.statusMessage());
    }
  } catch (Exception e) {
    LOGGER.error("unregister microservice instance {}/{} failed",
        microserviceId,
        microserviceInstanceId,
        e);
  }
  return false;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:27,代码来源:ServiceRegistryClientImpl.java

示例3: handleResponse

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
void handleResponse(Invocation invocation, HttpClientResponse clientResponse,
    AsyncResponse asyncResp) {
  clientResponse.bodyHandler(responseBuf -> {
    // 此时是在网络线程中,不应该就地处理,通过dispatcher转移线程
    invocation.getResponseExecutor().execute(() -> {
      try {
        HttpServletResponseEx responseEx =
            new VertxClientResponseToHttpServletResponse(clientResponse, responseBuf);
        for (HttpClientFilter filter : httpClientFilters) {
          Response response = filter.afterReceiveResponse(invocation, responseEx);
          if (response != null) {
            asyncResp.complete(response);
            return;
          }
        }
      } catch (Throwable e) {
        asyncResp.fail(invocation.getInvocationType(), e);
      }
    });
  });
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:VertxHttpMethod.java

示例4: testSetCseContext

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSetCseContext() {
  boolean status = false;
  try {
    Invocation invocation = mock(Invocation.class);
    HttpClientResponse httpResponse = mock(HttpClientResponse.class);
    OperationMeta operationMeta = mock(OperationMeta.class);
    RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
    HttpClientRequest request = mock(HttpClientRequest.class);

    Endpoint endpoint = mock(Endpoint.class);
    when(invocation.getOperationMeta()).thenReturn(operationMeta);
    URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
    when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
    operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
    when(invocation.getEndpoint()).thenReturn(endpoint);
    String contentType = httpResponse.getHeader("Content-Type");
    ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
    when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
    this.setCseContext(invocation, request);
  } catch (Exception ex) {
    status = true;
  }
  Assert.assertFalse(status);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:27,代码来源:TestVertxHttpMethod.java

示例5: json

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
public static Handler<HttpClientResponse> json(
  CompletableFuture<JsonResponse> completed) {

  return response -> {
    response.bodyHandler(buffer -> {
      try {
        int statusCode = response.statusCode();
        String body = BufferHelper.stringFromBuffer(buffer);

        System.out.println(String.format("Response: %s", body));
        log.debug(String.format("Response: %s", body));

        completed.complete(new JsonResponse(statusCode, body));

      } catch(Exception e) {
        completed.completeExceptionally(e);
      }
    });
  };
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:21,代码来源:ResponseHandler.java

示例6: jsonErrors

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
public static Handler<HttpClientResponse> jsonErrors(
  CompletableFuture<JsonErrorResponse> completed) {

  return response -> {
    response.bodyHandler(buffer -> {
      try {
        int statusCode = response.statusCode();
        String body = BufferHelper.stringFromBuffer(buffer);

        completed.complete(new JsonErrorResponse(statusCode, body));

      } catch (Exception e) {
        completed.completeExceptionally(e);
      }
    });
  };
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:18,代码来源:ResponseHandler.java

示例7: text

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
public static Handler<HttpClientResponse> text(
  CompletableFuture<TextResponse> completed) {

  return response -> {
      int statusCode = response.statusCode();

      response.bodyHandler(buffer -> {
        try {
          String body = BufferHelper.stringFromBuffer(buffer);

          completed.complete(new TextResponse(statusCode, body));

        } catch (Exception e) {
          completed.completeExceptionally(e);
        }
      });
  };
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:19,代码来源:ResponseHandler.java

示例8: proxyUserRequest

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
/**
 * Proxies the specified HTTP request, enriching its headers with authentication information.
 *
 * @param userId  the ID of the user making the request.
 * @param origReq the original request (i.e., {@link RoutingContext#request()}.
 * @param origRes the original response (i.e., {@link RoutingContext#request()}.
 */
public void proxyUserRequest(final String userId,
                             final HttpServerRequest origReq,
                             final HttpServerResponse origRes) {
    final Handler<HttpClientResponse> proxiedResHandler = proxiedRes -> {
        origRes.setChunked(true);
        origRes.setStatusCode(proxiedRes.statusCode());
        origRes.headers().setAll(proxiedRes.headers());
        proxiedRes.handler(origRes::write);
        proxiedRes.endHandler(v -> origRes.end());
    };

    final HttpClientRequest proxiedReq;
    proxiedReq = httpClient.request(origReq.method(), port, host, origReq.uri(), proxiedResHandler);
    proxiedReq.setChunked(true);
    proxiedReq.headers().add(X_FORWARDED_PROTO, getHeader(origReq, X_FORWARDED_PROTO, origReq.scheme()));
    proxiedReq.headers().add(X_FORWARDED_FOR, getHeader(origReq, X_FORWARDED_FOR, origReq.remoteAddress().host()));
    proxiedReq.headers().addAll(origReq.headers());
    injectRutHeader(proxiedReq, userId);
    origReq.handler(proxiedReq::write);
    origReq.endHandler(v -> proxiedReq.end());
}
 
开发者ID:travelaudience,项目名称:nexus-proxy,代码行数:29,代码来源:NexusHttpProxy.java

示例9: put

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
public void put(URL url,
                Object body,
                String tenantId,
                Handler<HttpClientResponse> responseHandler) {

  HttpClientRequest request = client.putAbs(url.toString(), responseHandler);

  request.headers().add("Accept","application/json, text/plain");
  request.headers().add("Content-type","application/json");

  if(tenantId != null) {
    request.headers().add(TENANT_HEADER, tenantId);
  }

  request.end(Json.encodePrettily(body));
}
 
开发者ID:folio-org,项目名称:deprecated-mod-metadata,代码行数:17,代码来源:HttpClient.java

示例10: prepareContainer

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
protected Observable<Void> prepareContainer(TestContext context) {
    return just((Void) null)
            .flatMap(aVoid -> vertxContext.verticle().getNodeStats().forceUpdate(vertxContext))
            .flatMap(aVoid -> vertxContext.verticle().getClusterInfo().forceRefresh(vertxContext))
            .flatMap(new WaitForCluster(vertxContext))
            .flatMap(new PostAccount(httpClient, accountName, authAdmin))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_NO_CONTENT))
            .map(new ToVoid<HttpClientResponse>())
            .flatMap(new PutContainer(httpClient, accountName, containerName, authNonAdmin))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_CREATED))
            .map(new ToVoid<HttpClientResponse>())
            .count()
            .map(new ToVoid<Integer>());
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:17,代码来源:PurgeTest.java

示例11: testHeadContainerImplicitAllow

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testHeadContainerImplicitAllow(TestContext context) {

    Producer authNonAdmin0 = httpBasic("user", "user");

    Async async = context.async();
    just((Void) null)
            .flatMap(new PostAccount(httpClient, accountName, authAdmin))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_NO_CONTENT))
            .map(new ToVoid<HttpClientResponse>())
            .flatMap(new PutContainer(httpClient, accountName, containerName, authNonAdmin0))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_CREATED))
            .map(new ToVoid<HttpClientResponse>())
            .flatMap(new HeadContainer(httpClient, accountName, containerName, authNonAdmin0))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_NO_CONTENT))
            .map(new ToVoid<HttpClientResponse>())
            .subscribe(new TestSubscriber(context, async));
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:22,代码来源:ContainerPermissionsHeadContainerTest.java

示例12: handle204

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
private void handle204(HttpClientResponse res, String msg,
  Handler<AsyncResult<Void>> future) {
  Buffer body = Buffer.buffer();
  res.handler(body::appendBuffer);
  res.endHandler(d -> {
    if (res.statusCode() == 204) {
      future.handle(Future.succeededFuture());
    } else {
      String m = msg + " HTTP error "
        + Integer.toString(res.statusCode()) + "\n"
        + body.toString();
      logger.error(m);
      future.handle(Future.failedFuture(m));
    }
  });

}
 
开发者ID:folio-org,项目名称:okapi,代码行数:18,代码来源:DockerModuleHandle.java

示例13: DigestBlob

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
public DigestBlob(HttpClientResponse httpClientResponse) {
    super(httpClientResponse);
    digests = new HashMap<>();
    BaseEncoding baseEncoding = base64();
    MultiMap headers = httpClientResponse.headers();
    for (String headerName : headers.names()) {
        Matcher matcher = COMPUTED_DIGEST.matcher(headerName);
        if (matcher.find()) {
            String digestName = matcher.group(1);
            Optional<MessageDigestFactory> oMessageDigestFactory = fromValueIfExists(digestName);
            if (oMessageDigestFactory.isPresent()) {
                MessageDigestFactory messageDigestFactory = oMessageDigestFactory.get();
                withDigest(messageDigestFactory, baseEncoding.decode(headers.get(headerName)));
            }
        }
    }
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:18,代码来源:DigestBlob.java

示例14: updateCredentials

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
private static final Future<HttpClientResponse> updateCredentials(final String authId, final String type, final JsonObject requestPayload, final int expectedResult) {

        final Future<HttpClientResponse> result = Future.future();
        final String uri = String.format(TEMPLATE_URI_CREDENTIALS_INSTANCE, authId, type);

        final HttpClientRequest req = vertx.createHttpClient().put(getPort(), HOST, uri)
                .putHeader(HttpHeaders.CONTENT_TYPE, HttpUtils.CONTENT_TYPE_JSON)
                .handler(response -> {
                    if (response.statusCode() == expectedResult) {
                        result.complete(response);
                    } else {
                        result.fail("update credentials failed, expected status code " + expectedResult + " but got " + response.statusCode());
                    }
                })
                .exceptionHandler(result::fail);

        if (requestPayload == null) {
            req.end();
        } else {
            req.end(requestPayload.encodePrettily());
        }
        return result;
    }
 
开发者ID:eclipse,项目名称:hono,代码行数:24,代码来源:CredentialsRestServerTest.java

示例15: testListContainerExplicitAllow

import io.vertx.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testListContainerExplicitAllow(TestContext context) {
    Producer authNonAdmin0 = httpBasic("user", "user");

    Async async = context.async();
    just((Void) null)
            .flatMap(new PostAccount(httpClient, accountName, authAdmin))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_NO_CONTENT))
            .map(new ToVoid<HttpClientResponse>())
            .flatMap(new PutContainer(httpClient, accountName, containerName, authNonAdmin0))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_CREATED))
            .map(new ToVoid<HttpClientResponse>())
            .flatMap(new RefreshIndex(httpClient, authAdmin))
            .flatMap(new GetContainer(httpClient, accountName, containerName, authNonAdmin0))
            .map(new HttpClientResponseHeaderLogger())
            .map(new AssertHttpClientResponseStatusCode(context, HTTP_OK))
            .flatMap(new HttpClientResponseBodyBuffer())
            .map(new HttpBodyLogger())
            .map(new ToVoid<Buffer>())
            .subscribe(new TestSubscriber(context, async));
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:24,代码来源:ContainerPermissionsGetContainerTest.java


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