io.reactivex.netty.protocol.http.client.HttpClientRequest Java Examples

The following examples show how to use io.reactivex.netty.protocol.http.client.HttpClientRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MesosClientTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserAgentContains_MesosRxJavaCore_RxNetty() throws Exception {
    final String clientName = "unit-tests";
    final MesosClient<String, String> client = MesosClientBuilder.<String, String>newBuilder()
        .sendCodec(StringMessageCodec.UTF8_STRING)
        .receiveCodec(StringMessageCodec.UTF8_STRING)
        .mesosUri(URI.create("http://localhost:12345"))
        .applicationUserAgentEntry(literal(clientName, "latest"))
        .subscribe("subscribe")
        .processStream(events -> events.map(e -> Optional.<SinkOperation<String>>empty()))
        .build();

    final HttpClientRequest<ByteBuf> request = client.createPost
        .call("ACK")
        .toBlocking()
        .first();

    final Map<String, String> headers = headersToMap(request.getHeaders());
    assertThat(headers).containsKeys("User-Agent");
    final String ua = headers.get("User-Agent");
    assertThat(ua).startsWith(String.format("%s/%s", clientName, "latest"));
    assertThat(ua).contains("mesos-rxjava-client/");
}
 
Example #2
Source File: TestUtils.java    From Prana with Apache License 2.0 6 votes vote down vote up
public static String getResponse(HttpClientRequest<ByteBuf> request, HttpClient<ByteBuf, ByteBuf> client) {
    return client.submit(request).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<String>>() {
        @Override
        public Observable<String> call(HttpClientResponse<ByteBuf> response) {
            return response.getContent().map(new Func1<ByteBuf, String>() {
                @Override
                public String call(ByteBuf byteBuf) {
                    return byteBuf.toString(Charset.defaultCharset());
                }
            });
        }
    }).onErrorFlatMap(new Func1<OnErrorThrowable, Observable<String>>() {
        @Override
        public Observable<String> call(OnErrorThrowable onErrorThrowable) {
            throw onErrorThrowable;
        }
    }).toBlocking().first();
}
 
Example #3
Source File: HttpResourceObservableCommand.java    From ribbon with Apache License 2.0 6 votes vote down vote up
public HttpResourceObservableCommand(HttpClient<ByteBuf, ByteBuf> httpClient,
                                     HttpClientRequest<ByteBuf> httpRequest, String hystrixCacheKey,
                                     Map<String, Object> requestProperties,
                                     FallbackHandler<T> fallbackHandler,
                                     ResponseValidator<HttpClientResponse<ByteBuf>> validator,
                                     Class<? extends T> classType,
                                     HystrixObservableCommand.Setter setter) {
    super(setter);
    this.httpClient = httpClient;
    this.fallbackHandler = fallbackHandler;
    this.validator = validator;
    this.httpRequest = httpRequest;
    this.hystrixCacheKey = hystrixCacheKey;
    this.classType = classType;
    this.requestProperties = requestProperties;
}
 
Example #4
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void testPostWithByteBuf() throws Exception {
    Person myPerson = new Person("netty", 5);
    ObjectMapper mapper = new ObjectMapper();
    byte[] raw = mapper.writeValueAsBytes(myPerson);
    ByteBuf buffer = Unpooled.copiedBuffer(raw);
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createPost(SERVICE_URI + "testAsync/person")
            .withHeader("Content-type", "application/json")
            .withHeader("Content-length", String.valueOf(raw.length))
            .withContent(buffer);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient(
            DefaultClientConfigImpl.getClientConfigWithDefaultValues().set(CommonClientConfigKey.ReadTimeout, 10000));
    Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(request);
    Person person = getPersonObservable(response).toBlocking().single();
    assertEquals(myPerson, person);
}
 
Example #5
Source File: LoadBalancingHttpClient.java    From ribbon with Apache License 2.0 6 votes vote down vote up
protected LoadBalancingHttpClient(Builder<I, O> builder) {
    super(builder.lb, builder.config, new RequestSpecificRetryHandler(true, true, builder.retryHandler, null), builder.pipelineConfigurator, builder.poolCleanerScheduler);
    requestIdHeaderName = getProperty(IClientConfigKey.Keys.RequestIdHeaderName, null, null);
    requestIdProvider = (requestIdHeaderName != null) 
                      ? new HttpRequestIdProvider(requestIdHeaderName, RxContexts.DEFAULT_CORRELATOR)
                      : null;
    this.listeners = new CopyOnWriteArrayList<ExecutionListener<HttpClientRequest<I>, HttpClientResponse<O>>>(builder.listeners);
    defaultCommandBuilder = LoadBalancerCommand.<HttpClientResponse<O>>builder()
            .withLoadBalancerContext(lbContext)
            .withListeners(this.listeners)
            .withClientConfig(builder.config)
            .withRetryHandler(builder.retryHandler)
            .build();
    this.responseToErrorPolicy = builder.responseToErrorPolicy;
    this.backoffStrategy = builder.backoffStrategy;
}
 
Example #6
Source File: SpyClientUnderTestFactory.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
void initRequestCapture(CompositeHttpClient<ByteBuf, ByteBuf> spyClient) {

            doAnswer(new Answer() {
                @Override
                public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                    RxClient.ServerInfo serverInfo = invocationOnMock.getArgumentAt(0, RxClient.ServerInfo.class);
                    HttpClientRequest<ByteBuf> httpReq = invocationOnMock.getArgumentAt(1, HttpClientRequest.class);

                    CompletableFuture<HttpResponseHeaders> f = new CompletableFuture<>();
                    requestsResponsePairs.add(Pair.of(httpReq, f));

                    return origHttpClient.submit(serverInfo, httpReq)
                            .doOnNext(
                                    res -> f.complete(res.getHeaders())
                            ).doOnError(
                                    e -> f.completeExceptionally(e)
                            );

                }
            }).when(spyClient).submit(Mockito.any(RxClient.ServerInfo.class), Mockito.any(HttpClientRequest.class));
        }
 
Example #7
Source File: HealthCheckHandler.java    From Prana with Apache License 2.0 6 votes vote down vote up
private Observable<HttpClientResponse<ByteBuf>> getResponse(String externalHealthCheckURL) {
    String host = "localhost";
    int port = DEFAULT_APPLICATION_PORT;
    String path = "/healthcheck";
    try {
        URL url = new URL(externalHealthCheckURL);
        host = url.getHost();
        port = url.getPort();
        path = url.getPath();
    } catch (MalformedURLException e) {
        //continue
    }
    Integer timeout = DynamicProperty.getInstance("prana.host.healthcheck.timeout").getInteger(DEFAULT_CONNECTION_TIMEOUT);
    HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port)
            .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
            .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout)
            .build();
    return httpClient.submit(HttpClientRequest.createGet(path));

}
 
Example #8
Source File: HttpTransportClient.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
private Single<StoreResponse> processHttpResponse(String resourceAddress, HttpClientRequest<ByteBuf> request, String activityId, HttpClientResponse<ByteBuf> response, URI physicalAddress) {
    if (response == null) {
        InternalServerErrorException exception =
            new InternalServerErrorException(
                String.format(
                    RMResources.ExceptionMessage,
                    RMResources.InvalidBackendResponse),
                null,
                physicalAddress);
        exception.getResponseHeaders().put(HttpConstants.HttpHeaders.ACTIVITY_ID,
            activityId);
        exception.getResponseHeaders().put(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "1");

        return Single.error(exception);
    }

    // If the status code is < 300 or 304 NotModified (we treat not modified as success) then it means that it's a success code and shouldn't throw.
    if (response.getStatus().code() < HttpConstants.StatusCodes.MINIMUM_STATUSCODE_AS_ERROR_GATEWAY ||
        response.getStatus().code() == HttpConstants.StatusCodes.NOT_MODIFIED) {
        return HttpTransportClient.createStoreResponseFromHttpResponse(response);
    }
    else {
        return this.createErrorResponseFromHttpResponse(resourceAddress, activityId, request, response);
    }
}
 
Example #9
Source File: SecuredTransportFactory.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public HttpClient<ByteBuf, ByteBuf> newHttpClient(final IClientConfig config) {
    final List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = new ArrayList<>();
    listeners.add(createBearerHeaderAdder());
    final PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator = new PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, 
            HttpClientRequest<ByteBuf>>(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(),
            new HttpObjectAggregationConfigurator(maxChunkSize));
    final LoadBalancingHttpClient<ByteBuf, ByteBuf> client = LoadBalancingHttpClient.<ByteBuf, ByteBuf>builder()
            .withClientConfig(config)
            .withExecutorListeners(listeners)
            .withRetryHandler(getDefaultHttpRetryHandlerWithConfig(config))
            .withPipelineConfigurator(pipelineConfigurator)
            .withPoolCleanerScheduler(RibbonTransport.poolCleanerScheduler)
            .build();

    return client;
}
 
Example #10
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreamWithLoadBalancer() throws Exception {
    // NettyHttpLoadBalancerErrorHandler errorHandler = new NettyHttpLoadBalancerErrorHandler(1, 3, true);
    // IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    IClientConfig config = IClientConfig.Builder.newBuilder().withRetryOnAllOperations(true)
            .withMaxAutoRetries(1)
            .withMaxAutoRetriesNextServer(3)
            .build();
    BaseLoadBalancer lb = new BaseLoadBalancer(new DummyPing(), new AvailabilityFilteringRule());
    LoadBalancingHttpClient<ByteBuf, ServerSentEvent> lbObservables = (LoadBalancingHttpClient<ByteBuf, ServerSentEvent>) RibbonTransport.newSSEClient(lb, config);
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/personStream");
    List<Person> result = Lists.newArrayList();
    Server goodServer = new Server("localhost:" + port);
    Server badServer = new Server("localhost:12245");
    List<Server> servers = Lists.newArrayList(badServer, badServer, badServer, goodServer);
    lb.setServersList(servers);
    result = getPersonListFromResponse(lbObservables.submit(request, null, null));
    assertEquals(EmbeddedResources.entityStream, result);
}
 
Example #11
Source File: RxMovieTransportExample.java    From ribbon with Apache License 2.0 6 votes vote down vote up
private Observable<Void> registerMovie(Movie movie) {
    HttpClientRequest<ByteBuf> httpRequest = HttpClientRequest.createPost("/movies")
            .withHeader("X-Platform-Version", "xyz")
            .withHeader("X-Auth-Token", "abc")
            .withRawContentSource(Observable.just(movie), new RxMovieTransformer());

    return client.submit(httpRequest).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<Void>>() {
        @Override
        public Observable<Void> call(HttpClientResponse<ByteBuf> httpClientResponse) {
            if (httpClientResponse.getStatus().code() / 100 != 2) {
                return Observable.error(new RuntimeException(
                        format("HTTP request failed (status code=%s)", httpClientResponse.getStatus())));
            }
            return Observable.empty();
        }
    });
}
 
Example #12
Source File: MesosClientTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicAuthHeaderAddedToRequestWhenUserInfoPresentInUri() throws Exception {
    final Func1<String, Observable<HttpClientRequest<ByteBuf>>> createPost = MesosClient.curryCreatePost(
        URI.create("http://testuser:testpassword@localhost:12345/api/v1/scheduler"),
        StringMessageCodec.UTF8_STRING,
        StringMessageCodec.UTF8_STRING,
        new UserAgent(
            literal("testing", "latest")
        ),
        new AtomicReference<>(null)
    );

    final HttpClientRequest<ByteBuf> request = createPost.call("something")
        .toBlocking()
        .first();

    final String authHeaderName = HttpHeaderNames.AUTHORIZATION.toString();
    final Map<String, String> headers = headersToMap(request.getHeaders());
    assertThat(headers).containsKeys(authHeaderName);
    final String authorization = headers.get(authHeaderName);
    assertThat(authorization).isEqualTo("Basic dGVzdHVzZXI6dGVzdHBhc3N3b3Jk");

    final String base64UserPass = authorization.substring("Basic ".length());
    final String userPass = new String(Base64.getDecoder().decode(base64UserPass));
    assertThat(userPass).isEqualTo("testuser:testpassword");
}
 
Example #13
Source File: MesosClientTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void testMesosStreamIdAddedToRequestWhenNonNull() throws Exception {
    final Func1<String, Observable<HttpClientRequest<ByteBuf>>> createPost = MesosClient.curryCreatePost(
        URI.create("http://localhost:12345/api/v1/scheduler"),
        StringMessageCodec.UTF8_STRING,
        StringMessageCodec.UTF8_STRING,
        new UserAgent(
            literal("testing", "latest")
        ),
        new AtomicReference<>("streamId")
    );

    final HttpClientRequest<ByteBuf> request = createPost.call("something")
        .toBlocking()
        .first();

    final Map<String, String> headers = headersToMap(request.getHeaders());
    assertThat(headers).containsKeys("Mesos-Stream-Id");
    assertThat(headers.get("Mesos-Stream-Id")).isEqualTo("streamId");
}
 
Example #14
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void testObservable() throws Exception {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/person");
    LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient();
    Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(request);
    Person person = getPersonObservable(response).toBlocking().single();
    assertEquals(EmbeddedResources.defaultPerson, person);
    final HttpClientListener listener = observableClient.getListener();
    assertEquals(1, listener.getPoolAcquires());
    assertEquals(1, listener.getConnectionCount());
    waitUntilTrueOrTimeout(1000, new Func0<Boolean>() {
        @Override
        public Boolean call() {
            return listener.getPoolReleases() == 1;
        }
    });
}
 
Example #15
Source File: MesosClientTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void testMesosStreamIdNotPresentWhenNull() throws Exception {
    final Func1<String, Observable<HttpClientRequest<ByteBuf>>> createPost = MesosClient.curryCreatePost(
        URI.create("http://localhost:12345/api/v1/scheduler"),
        StringMessageCodec.UTF8_STRING,
        StringMessageCodec.UTF8_STRING,
        new UserAgent(
            literal("testing", "latest")
        ),
        new AtomicReference<>(null)
    );

    final HttpClientRequest<ByteBuf> request = createPost.call("something")
        .toBlocking()
        .first();

    final Map<String, String> headers = headersToMap(request.getHeaders());
    assertThat(headers).doesNotContainKeys("Mesos-Stream-Id");
}
 
Example #16
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void testPoolReuse() throws Exception {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/person");
    LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient(
            IClientConfig.Builder.newBuilder().withDefaultValues()
            .withMaxAutoRetries(1)
            .withMaxAutoRetriesNextServer(1).build());
    Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(request);
    Person person = getPersonObservable(response).toBlocking().single();
    assertEquals(EmbeddedResources.defaultPerson, person);
    response = observableClient.submit(request);
    person = getPersonObservable(response).toBlocking().single();
    assertEquals(EmbeddedResources.defaultPerson, person);
    final HttpClientListener listener = observableClient.getListener();
    assertEquals(2, listener.getPoolAcquires());
    waitUntilTrueOrTimeout(1000, new Func0<Boolean>() {
        @Override
        public Boolean call() {
            return listener.getPoolReleases() == 2;
        }
    });
    assertEquals(1, listener.getConnectionCount());
    assertEquals(1, listener.getPoolReuse());
}
 
Example #17
Source File: SimpleGet.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@edu.umd.cs.findbugs.annotations.SuppressWarnings
public static void main(String[] args) throws Exception {
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient();
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("http://www.google.com/");
    final CountDownLatch latch = new CountDownLatch(1);
    client.submit(request)
        .toBlocking()
        .forEach(new Action1<HttpClientResponse<ByteBuf>>() {
            @Override
            public void call(HttpClientResponse<ByteBuf> t1) {
                System.out.println("Status code: " + t1.getStatus());
                t1.getContent().subscribe(new Action1<ByteBuf>() {

                    @Override
                    public void call(ByteBuf content) {
                        System.out.println("Response content: " + content.toString(Charset.defaultCharset()));
                        latch.countDown();
                    }
                    
                });
            }
        });
    latch.await(2, TimeUnit.SECONDS);
}
 
Example #18
Source File: LoadBalancingHttpClient.java    From ribbon with Apache License 2.0 5 votes vote down vote up
private RetryHandler getRequestRetryHandler(HttpClientRequest<?> request, IClientConfig requestConfig) {
    return new RequestSpecificRetryHandler(
            true, 
            request.getMethod().equals(HttpMethod.GET),     // Default only allows retrys for GET
            defaultRetryHandler, 
            requestConfig);
}
 
Example #19
Source File: WSClient.java    From WSPerfLab with Apache License 2.0 5 votes vote down vote up
public WSClient(String host, int port, int firstStep, int stepSize, int stepDuration, String query) {
    this.host = host;
    this.port = port;
    this.firstStep = firstStep;
    this.stepSize = stepSize;
    this.stepDuration = stepDuration;
    this.query = query;

    System.out.println("Starting client with hostname: " + host + "  port: " + port + "  first-step: " + firstStep + "  step-size: " + stepSize + "  step-duration: " + stepDuration + "s  query: " + query);

    httpClient = new HttpClientBuilder<ByteBuf, ByteBuf>(this.host, this.port)
            .withMaxConnections(15000)
            .config(new HttpClient.HttpClientConfig.Builder().readTimeout(1, TimeUnit.MINUTES).build())
            .build();
    stats = new ConnectionPoolMetricListener();
    httpClient.subscribe(stats);

    client = httpClient.submit(HttpClientRequest.createGet(this.query))
            .flatMap(response -> {
                if (response.getStatus().code() == 200) {
                    counter.increment(CounterEvent.SUCCESS);
                } else {
                    counter.increment(CounterEvent.HTTP_ERROR);
                }
                return response.getContent().doOnNext(bb -> {
                    counter.add(CounterEvent.BYTES, bb.readableBytes());
                });
            }).doOnError((t) -> {
                if (t instanceof PoolExhaustedException) {
                    counter.increment(CounterEvent.POOL_EXHAUSTED);
                } else {
                    counter.increment(CounterEvent.NETTY_ERROR);
                }
            });
}
 
Example #20
Source File: RibbonTransport.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public static LoadBalancingHttpClient<ByteBuf, ByteBuf> newHttpClient(ILoadBalancer loadBalancer, IClientConfig config, RetryHandler retryHandler,
                                                              List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners) {
    return LoadBalancingHttpClient.<ByteBuf, ByteBuf>builder()
            .withLoadBalancer(loadBalancer)
            .withClientConfig(config)
            .withRetryHandler(retryHandler)
            .withPipelineConfigurator(DEFAULT_HTTP_PIPELINE_CONFIGURATOR)
            .withPoolCleanerScheduler(poolCleanerScheduler)
            .withExecutorListeners(listeners)
            .build();
}
 
Example #21
Source File: TemplateBuilderTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarReplacement() {
    HttpResourceGroup group = Ribbon.createHttpResourceGroupBuilder("test").build();
    
    HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("testVarReplacement", ByteBuf.class)
            .withMethod("GET")
            .withUriTemplate("/foo/{id}?name={name}").build();
    HttpClientRequest<ByteBuf> request = template
            .requestBuilder()
            .withRequestProperty("id", "3")
            .withRequestProperty("name", "netflix")
            .createClientRequest();
    assertEquals("/foo/3?name=netflix", request.getUri());
}
 
Example #22
Source File: TestExecutionListener.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Override
public void onExceptionWithServer(ExecutionContext<HttpClientRequest<I>> context, Throwable exception, ExecutionInfo info) {
    checkContext(context);
    checkExecutionInfo(info);
    numAttemptsOnServer.incrementAndGet();
    errors.add(exception);
    exceptionWithServerCounter.incrementAndGet();
}
 
Example #23
Source File: BearerHeaderAdder.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void onExceptionWithServer(ExecutionContext<HttpClientRequest<ByteBuf>> context, Throwable exception, ExecutionInfo info) {
    KeycloakSecurityContext securityContext = (KeycloakSecurityContext) context.get(KeycloakSecurityContextAssociation.class.getName());
    if (securityContext != null) {
        KeycloakSecurityContextAssociation.associate(securityContext);
    } else {
        KeycloakSecurityContextAssociation.disassociate();
    }
}
 
Example #24
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostWithObservable() throws Exception {
    Person myPerson = new Person("netty", 5);
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createPost(SERVICE_URI + "testAsync/person")
            .withHeader("Content-type", "application/json")
            .withContent(SerializationUtils.serializeToBytes(JacksonCodec.getInstance(), myPerson, null));
    LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient(
            DefaultClientConfigImpl.getClientConfigWithDefaultValues().set(CommonClientConfigKey.ReadTimeout, 10000));
    Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(new Server(host, port), request);
    Person person = getPersonObservable(response).toBlocking().single();
    assertEquals(myPerson, person);
}
 
Example #25
Source File: BearerHeaderAdder.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void onExecutionFailed(ExecutionContext<HttpClientRequest<ByteBuf>> context, Throwable finalException, ExecutionInfo info) {
    KeycloakSecurityContext securityContext = (KeycloakSecurityContext) context.get(KeycloakSecurityContextAssociation.class.getName());
    if (securityContext != null) {
        KeycloakSecurityContextAssociation.associate(securityContext);
    } else {
        KeycloakSecurityContextAssociation.disassociate();
    }
}
 
Example #26
Source File: VideoMetadataCommand.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
@Override
protected Observable<VideoMetadata> construct() {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/metadata?" + UrlGenerator.generate("videoId",
                                                                                                          videos));
    return loadBalancer.choose()
                       .map(holder -> holder.getClient())
                       .<VideoMetadata>flatMap(client -> client.submit(request)
                                                .flatMap(r -> r.getContent()
                                                               .map((ServerSentEvent sse) -> VideoMetadata.fromJson(sse.contentAsString()))))
                       .retry(1);
}
 
Example #27
Source File: GeoCommand.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
@Override
protected Observable<GeoIP> construct() {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/geo?" + UrlGenerator.generate("ip", ips));
    return loadBalancer.choose()
                       .map(holder -> holder.getClient())
                       .<GeoIP>flatMap(client -> client.submit(request)
                                                .flatMap(r -> r.getContent()
                                                               .map((ServerSentEvent sse) -> GeoIP.fromJson(sse.contentAsString()))))
                       .retry(1);
}
 
Example #28
Source File: UserCommand.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
@Override
protected Observable<User> construct() {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/user?" + UrlGenerator.generate("userId", userIds));
    return loadBalancer.choose().map(holder -> holder.getClient())
            .<User>flatMap(client -> client.submit(request)
                                     .flatMap(r -> r.getContent().map(
                                             (ServerSentEvent sse) -> {
                                                 String user = sse.contentAsString();
                                                 return User.fromJson(user);
                                             })))
            .retry(1);
}
 
Example #29
Source File: SocialCommand.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
@Override
protected Observable<Social> construct() {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/social?" + UrlGenerator.generate("userId", users));
    return loadBalancer.choose().map(holder -> holder.getClient())
            .<Social>flatMap(client -> client.submit(request)
                                     .flatMap(r -> r.getContent().map((ServerSentEvent sse) -> {
                                         String social = sse.contentAsString();
                                         return Social.fromJson(social);
                                     })))
            .retry(1);
}
 
Example #30
Source File: RatingsCommand.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
@Override
protected Observable<Rating> construct() {
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/ratings?" + UrlGenerator.generate("videoId", videos));
    return loadBalancer.choose()
                       .map(holder -> holder.getClient())
                       .<Rating>flatMap(client -> client.submit(request)
                                                .flatMap(r -> r.getContent()
                                                               .map((ServerSentEvent sse) -> Rating.fromJson(sse.contentAsString()))))
                       .retry(1);
}