Пример #1
0
  HttpClientResponse forward() throws Exception {

    NFRequestContext context = NFRequestContext.getCurrentContext();
    HttpClientRequest httpClientRequest =
        HttpClientRequest.newBuilder()
            .setVerb(verb)
            .setUri(uri)
            .setHeaders(headers)
            .setEntity(requestEntity)
            .setQueryParams(params)
            .build();

    HttpClientResponse response = restClient.executeWithLoadBalancer(httpClientRequest);
    context.setZuulResponse(response);
    return response;
  }
Пример #2
0
  @Override
  protected String run() {
    try {
      // The named client param must match the prefix for the ribbon
      // configuration specified in the edge.properties file
      RestClient client = (RestClient) ClientFactory.getNamedClient("middletier-client");

      // MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
      // headers.putSingle("Content-Type", "text/plain");

      // Note: If running locally on MacOS, you'll need to make sure your
      // /etc/hosts file contains the following entry:
      // 127.0.0.1 <hostname>.local
      // or else this will likely fail.
      HttpClientRequest request =
          HttpClientRequest.newBuilder()
              .setVerb(Verb.GET)
              .setUri(
                  new URI(
                      "/"
                          + FluxConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
                          + "/"
                          + FluxConstants.MIDDLETIER_WEB_RESOURCE_VERSION
                          + "/"
                          + FluxConstants.MIDDLETIER_WEB_RESOURCE_GET_PATH
                          + "/"
                          + key))
              // .setHeaders(headers)
              .build();

      HttpClientResponse response = client.executeWithLoadBalancer(request);

      if (response.getStatus() != 200) {
        logger.error("error status: {}", response.getStatus());
        throw new Exception("error status: " + response.getStatus());
      }

      return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
    } catch (Exception exc) {
      logger.error("Exception calling middletier while retrieving logs.", exc);
      throw new RuntimeException("Exception", exc);
    }
  }