Tabnine Logo
LiveHttpRequest.aggregate
Code IndexAdd Tabnine to your IDE (free)

How to use
aggregate
method
in
com.hotels.styx.api.LiveHttpRequest

Best Java code snippets using com.hotels.styx.api.LiveHttpRequest.aggregate (Showing top 9 results out of 315)

origin: HotelsDotCom/styx

@Test(dataProvider = "emptyBodyRequests")
public void encodesToStreamingHttpRequestWithEmptyBody(LiveHttpRequest streamingRequest) throws Exception {
  HttpRequest full = Mono.from(streamingRequest.aggregate(0x1000)).block();
  assertThat(full.body(), is(new byte[0]));
}
origin: HotelsDotCom/styx

  @Override
  protected LiveHttpResponse doHandle(LiveHttpRequest request) {
    HttpRequest fullRequest = Mono.from(request.aggregate(0x100000)).block();

    String responseBody = format("Response From %s - %s, received content digest: %s",
        origin.hostAndPortString(),
        randomUUID(),
        fullRequest.bodyAs(UTF_8).hashCode());

    return HttpResponse.response(OK)
        .header(CONTENT_TYPE, HTML_UTF_8.toString())
        .header(CONTENT_LENGTH, responseBody.getBytes(UTF_8).length)
        .body(responseBody, UTF_8)
        .build()
        .stream();
  }
}
origin: HotelsDotCom/styx

private static Eventual<PluginEnabledState> requestedNewState(LiveHttpRequest request) {
  return request.aggregate(MAX_CONTENT_SIZE)
      .map(fullRequest -> fullRequest.bodyAs(UTF_8))
      .map(PluginToggleHandler::parseToBoolean)
      .map(PluginEnabledState::fromBoolean);
}
origin: HotelsDotCom/styx

private static HttpHandler newHandler(String originId, RequestHandler wireMockHandler) {
  return (httpRequest, ctx) ->
      httpRequest.aggregate(MAX_CONTENT_LENGTH)
          .map(fullRequest -> {
            LOGGER.info("{} received: {}\n{}", new Object[]{originId, fullRequest.url(), fullRequest.body()});
            return fullRequest;
          })
          .flatMap(fullRequest -> {
            Request wmRequest = new WiremockStyxRequestAdapter(fullRequest);
            com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest);
            return Eventual.of(toStyxResponse(wmResponse).stream());
          });
}
origin: HotelsDotCom/styx

  private static HttpHandler newHandler(RequestHandler wireMockHandler) {
    return (httpRequest, ctx) ->
        httpRequest.aggregate(MAX_CONTENT_LENGTH)
            .map(fullRequest -> {
              LOGGER.info("Received: {}\n{}", new Object[]{fullRequest.url(), fullRequest.body()});
              return fullRequest;
            })
            .flatMap(fullRequest -> {
              Request wmRequest = new WiremockStyxRequestAdapter(fullRequest);
              com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest);
              return Eventual.of(toStyxResponse(wmResponse).stream());
            });
  }
}
origin: HotelsDotCom/styx

@Test
public void toFullRequestReleasesOriginalReferenceCountedBuffers() throws ExecutionException, InterruptedException {
  Buffer content = new Buffer("original", UTF_8);
  LiveHttpRequest original = LiveHttpRequest.get("/foo")
      .body(new ByteStream(Flux.just(content)))
      .build();
  HttpRequest fullRequest = Mono.from(original.aggregate(100)).block();
  assertThat(content.delegate().refCnt(), is(0));
  assertThat(fullRequest.bodyAs(UTF_8), is("original"));
}
origin: HotelsDotCom/styx

@Test
public void decodesToFullHttpRequest() throws Exception {
  LiveHttpRequest streamingRequest = post("/foo/bar", body("foo", "bar"))
      .version(HTTP_1_0)
      .header("HeaderName", "HeaderValue")
      .cookies(requestCookie("CookieName", "CookieValue"))
      .build();
  HttpRequest full = Mono.from(streamingRequest.aggregate(0x1000)).block();
  assertThat(full.method(), is(POST));
  assertThat(full.url(), is(url("/foo/bar").build()));
  assertThat(full.version(), is(HTTP_1_0));
  assertThat(full.headers(), containsInAnyOrder(
      header("HeaderName", "HeaderValue"),
      header("Cookie", "CookieName=CookieValue")));
  assertThat(full.cookies(), contains(requestCookie("CookieName", "CookieValue")));
  assertThat(full.body(), is(bytes("foobar")));
}
origin: HotelsDotCom/styx

  @Override
  public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) {
    return request.aggregate(config.maxContentLength())
            .flatMap(fullHttpRequest -> Eventual.from(asyncOperation(config.delayMillis())))
            .map(outcome -> request.newBuilder().header("X-Outcome", outcome.result()))
            .flatMap(x -> chain.proceed(request));
  }
}
origin: HotelsDotCom/styx

@Test
public void convertsToStreamingHttpRequest() throws Exception {
  HttpRequest fullRequest = new HttpRequest.Builder(POST, "/foo/bar").body("foobar", UTF_8)
      .version(HTTP_1_1)
      .header("HeaderName", "HeaderValue")
      .cookies(requestCookie("CookieName", "CookieValue"))
      .build();
  LiveHttpRequest streaming = fullRequest.stream();
  assertThat(streaming.method(), is(HttpMethod.POST));
  assertThat(streaming.url(), is(url("/foo/bar").build()));
  assertThat(streaming.version(), is(HTTP_1_1));
  assertThat(streaming.headers(), containsInAnyOrder(
      header("Content-Length", "6"),
      header("HeaderName", "HeaderValue"),
      header("Cookie", "CookieName=CookieValue")));
  assertThat(streaming.cookies(), contains(requestCookie("CookieName", "CookieValue")));
  StepVerifier.create(streaming.aggregate(0x10000).map(it -> it.bodyAs(UTF_8)))
      .expectNext("foobar")
      .verifyComplete();
}
com.hotels.styx.apiLiveHttpRequestaggregate

Javadoc

Aggregates content stream and converts this request to a HttpRequest.

Returns a Eventual that eventually produces a HttpRequest. The resulting full request object has the same request line, headers, and content as this request.

The content stream is aggregated asynchronously. The stream may be connected to a network socket or some other content producer. Once aggregated, a HttpRequest object is emitted on the returned Eventual.

A sole maxContentBytes argument is a backstop defence against excessively long content streams. The maxContentBytes should be set to a sensible value according to your application requirements and heap size. When the content size stream exceeds the maxContentBytes, a @{link ContentOverflowException} is emitted on the returned observable.

Popular methods of LiveHttpRequest

  • headers
  • id
  • newBuilder
    Return a new Builder that will inherit properties from this request. This allows a new request to be
  • method
  • url
  • path
  • version
  • body
  • header
  • queryParam
    Get a query parameter by name if present.
  • cookie
    Decodes the "Cookie" header in this request and returns the specified cookie.
  • cookies
    Decodes the "Cookie" header in this request and returns the cookies.
  • cookie,
  • cookies,
  • get,
  • keepAlive,
  • post,
  • toString,
  • <init>,
  • chunked,
  • consume

Popular in Java

  • Making http post requests using okhttp
  • getApplicationContext (Context)
  • addToBackStack (FragmentTransaction)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • Collectors (java.util.stream)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now