Tabnine Logo
Eventual.of
Code IndexAdd Tabnine to your IDE (free)

How to use
of
method
in
com.hotels.styx.api.Eventual

Best Java code snippets using com.hotels.styx.api.Eventual.of (Showing top 20 results out of 315)

origin: HotelsDotCom/styx

private static Eventual<LiveHttpResponse> handleErrors(Throwable e, HttpInterceptor.Context context) {
  if (e instanceof PluginNotFoundException) {
    return Eventual.of(responseWith(NOT_FOUND, e.getMessage()));
  }
  if (e instanceof BadPluginToggleRequestException) {
    return Eventual.of(responseWith(BAD_REQUEST, e.getMessage()));
  }
  LOGGER.error("Plugin toggle error", e);
  return Eventual.of(responseWith(INTERNAL_SERVER_ERROR, ""));
}
origin: HotelsDotCom/styx

@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
  return Eventual.of(doHandle(request));
}
origin: HotelsDotCom/styx

@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
  return Eventual.of(generateResponse());
}
origin: HotelsDotCom/styx

private Eventual<LiveHttpResponse> putNewState(LiveHttpRequest request, HttpInterceptor.Context context) {
  return Eventual.of(request)
      .flatMap(this::requestedUpdate)
      .map(this::applyUpdate);
}
origin: HotelsDotCom/styx

@Override
public Map<String, HttpHandler> adminInterfaceHandlers() {
  return ImmutableMap.of("status", (request, context) -> Eventual.of(
      response(OK)
          .addHeader(CONTENT_TYPE, APPLICATION_JSON)
          .body(format("{ name: \"%s\" status: \"%s\" }", name, status), UTF_8)
          .build()
          .stream()));
}
origin: HotelsDotCom/styx

@Override
public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) {
  if (CONNECT.equals(request.method())) {
    return Eventual.of(response(METHOD_NOT_ALLOWED).build());
  } else {
    return chain.proceed(request);
  }
}
origin: HotelsDotCom/styx

  static ImmutableMap<String, HttpHandler> adminHandlers(String endpoint, String responseContent) {
    return ImmutableMap.of(endpoint, (request, context) -> Eventual.of(response(OK)
        .body(responseContent, UTF_8)
        .build().stream()));
  }
}
origin: HotelsDotCom/styx

  static ImmutableMap<String, HttpHandler> adminHandlers(String endpoint, String responseContent) {
    return ImmutableMap.of(endpoint, (request, context) -> Eventual.of(response(OK)
        .body(responseContent, UTF_8)
        .build()
        .stream()
    ));
  }
}
origin: HotelsDotCom/styx

private Eventual<LiveHttpResponse> getCurrentOrPutNewState(LiveHttpRequest request, HttpInterceptor.Context context) {
  if (GET.equals(request.method())) {
    return getCurrentState(request, context);
  } else if (PUT.equals(request.method())) {
    return putNewState(request, context);
  } else {
    return Eventual.of(response(METHOD_NOT_ALLOWED).build());
  }
}
origin: HotelsDotCom/styx

@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
  Stream<NamedPlugin> enabled = plugins.stream().filter(NamedPlugin::enabled);
  Stream<NamedPlugin> disabled = plugins.stream().filter(plugin -> !plugin.enabled());
  String output = section("Enabled", enabled)
      + section("Disabled", disabled);
  return Eventual.of(response(OK)
      .body(output, UTF_8)
      .addHeader(CONTENT_TYPE, HTML_UTF_8.toString())
      .build()
      .stream());
}
origin: HotelsDotCom/styx

private static HttpHandler buildFallbackHandler(List<String> parents, RouteHandlerFactory routeHandlerFactory, ConditionRouterConfig config) {
  if (config.fallback == null) {
    return (request, context) -> Eventual.of(LiveHttpResponse.response(BAD_GATEWAY).build());
  } else {
    return routeHandlerFactory.build(append(parents, "fallback"), config.fallback);
  }
}
origin: HotelsDotCom/styx

@Test
public void flatMapsValues() {
  Eventual<String> eventual = Eventual.of("hello")
      .flatMap(it -> Eventual.of(it + " world"));
  StepVerifier.create(eventual)
      .expectNext("hello world")
      .verifyComplete();
}
origin: HotelsDotCom/styx

  @Override
  public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
    if (!method.equals(request.method())) {
      return Eventual.of(
          HttpResponse.response(METHOD_NOT_ALLOWED)
              .body(errorBody, StandardCharsets.UTF_8)
              .build()
              .stream()
      );
    }

    return httpHandler.handle(request, context);
  }
}
origin: HotelsDotCom/styx

private Eventual<LiveHttpResponse> getCurrentState(LiveHttpRequest request, HttpInterceptor.Context context) {
  return Eventual.of(request)
      .map(this::plugin)
      .map(this::currentState)
      .map(state -> responseWith(OK, state.toString()));
}
origin: HotelsDotCom/styx

@Test
public void createFromValue() {
  StepVerifier.create(Eventual.of("x"))
      .expectNext("x")
      .verifyComplete();
}
origin: HotelsDotCom/styx

  @Test
  public void mapsErrors() {
    Eventual<String> eventual = Eventual.<String>error(new RuntimeException("ouch"))
        .onError(it -> Eventual.of("mapped error: " + it.getMessage()));

    StepVerifier.create(eventual)
        .expectNext("mapped error: ouch")
        .verifyComplete();
  }
}
origin: HotelsDotCom/styx

@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
  MetricRequest metricRequest = new MetricRequest(request);
  return metricRequest.fullMetrics()
      ? super.handle(request, context)
      : Eventual.of(restrictedMetricsResponse(metricRequest).build().stream());
}
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

@Override
public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) {
  return Eventual.of(response(statusWithCode(status)).body(new ByteStream(Flux.just(new Buffer(text, UTF_8)))).build());
}
com.hotels.styx.apiEventualof

Javadoc

Creates a new Eventual object from given value.

Popular methods of Eventual

  • map
    Transforms an element synchronously by applying a mapping function.
  • <init>
    Constructs a new Eventual object from an reactive streams Publisher.
  • flatMap
    Transform an element asynchronously by applying a mapping function.
  • from
    Creates a new Eventual from a CompletionStage.
  • error
    Creates a new (@link Eventual} that emits an error.
  • onError
    Transforms an error by applying an error handler function.
  • fromMono

Popular in Java

  • Reading from database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • setRequestProperty (URLConnection)
  • putExtra (Intent)
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • JButton (javax.swing)
  • Option (scala)
  • Top Vim plugins
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