public EndpointServerBuilder setupHealthAndStats(final HttpServerBuilder httpServerBuilder) { if (isEnableStatEndpoint() || isEnableHealthEndpoint()) { final boolean healthEnabled = isEnableHealthEndpoint(); final boolean statsEnabled = isEnableStatEndpoint(); final HealthServiceAsync healthServiceAsync = healthEnabled ? getHealthService() : null; final StatCollection statCollection = statsEnabled ? getStatsCollection() : null; httpServerBuilder.addShouldContinueHttpRequestPredicate( new EndPointHealthPredicate(healthEnabled, statsEnabled, healthServiceAsync, statCollection)); } return this; }
httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> { count.incrementAndGet(); return true; httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> { count.incrementAndGet(); httpRequest.getReceiver().response(666, "foo-content", "foo"); httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> { count.incrementAndGet(); return true;
@Test public void testChainLastContinueFalse() { EndpointServerBuilder endpointServerBuilder = EndpointServerBuilder.endpointServerBuilder() .setEnableHealthEndpoint(true).setEnableStatEndpoint(true); AtomicInteger count = new AtomicInteger(); HttpServerBuilder httpServerBuilder = endpointServerBuilder.getHttpServerBuilder(); for (int i = 0; i < 10; i++) { httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> { count.incrementAndGet(); return true; }); } serviceEndpointServer = endpointServerBuilder.addService(new EmployeeServiceCollectionTestService()).build(); serviceEndpointServer.startServer(); final HttpTextResponse httpResponse = httpServerSimulator.postBody("/es/sendEmployees", Lists.list(new Employee(1, "Rick"), new Employee(2, "Diana"))); assertEquals(202, httpResponse.code()); assertEquals("\"success\"", httpResponse.body()); assertEquals(10, count.get()); }
@Test public void testChainContinueTrue() { EndpointServerBuilder endpointServerBuilder = EndpointServerBuilder.endpointServerBuilder() .setEnableHealthEndpoint(true).setEnableStatEndpoint(true); HttpServerBuilder httpServerBuilder = endpointServerBuilder.getHttpServerBuilder(); httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> true); serviceEndpointServer = endpointServerBuilder.addService(new EmployeeServiceCollectionTestService()).build(); serviceEndpointServer.startServer(); final HttpTextResponse httpResponse = httpServerSimulator.postBody("/es/sendEmployees", Lists.list(new Employee(1, "Rick"), new Employee(2, "Diana"))); assertEquals(202, httpResponse.code()); assertEquals("\"success\"", httpResponse.body()); }
@Test public void testChainWithResponse() { EndpointServerBuilder endpointServerBuilder = EndpointServerBuilder.endpointServerBuilder() .setEnableHealthEndpoint(true).setEnableStatEndpoint(true); HttpServerBuilder httpServerBuilder = endpointServerBuilder.getHttpServerBuilder(); httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> { httpRequest.getReceiver().response(666, "foo-content", "foo"); return false; }); serviceEndpointServer = endpointServerBuilder.addService(new EmployeeServiceCollectionTestService()).build(); serviceEndpointServer.startServer(); final HttpTextResponse httpResponse = httpServerSimulator.postBody("/es/sendEmployees", Lists.list(new Employee(1, "Rick"), new Employee(2, "Diana"))); assertEquals(666, httpResponse.code()); assertEquals("foo", httpResponse.body()); }
@Test public void testChain() { EndpointServerBuilder endpointServerBuilder = EndpointServerBuilder.endpointServerBuilder() .setEnableHealthEndpoint(true).setEnableStatEndpoint(true); HttpServerBuilder httpServerBuilder = endpointServerBuilder.getHttpServerBuilder(); httpServerBuilder.addShouldContinueHttpRequestPredicate(httpRequest -> false); serviceEndpointServer = endpointServerBuilder.addService(new EmployeeServiceCollectionTestService()).build(); serviceEndpointServer.startServer(); final HttpTextResponse httpResponse = httpServerSimulator.postBody("/es/sendEmployees", Lists.list(new Employee(1, "Rick"), new Employee(2, "Diana"))); assertNull(httpResponse); }
public EndpointServerBuilder setupHealthAndStats(final HttpServerBuilder httpServerBuilder) { if (isEnableStatEndpoint() || isEnableHealthEndpoint()) { final boolean healthEnabled = isEnableHealthEndpoint(); final boolean statsEnabled = isEnableStatEndpoint(); final HealthServiceAsync healthServiceAsync = healthEnabled ? getHealthService() : null; final StatCollection statCollection = statsEnabled ? getStatsCollection() : null; httpServerBuilder.addShouldContinueHttpRequestPredicate( new EndPointHealthPredicate(healthEnabled, statsEnabled, healthServiceAsync, statCollection)); } return this; }
public EndpointServerBuilder setupHealthAndStats(final HttpServerBuilder httpServerBuilder) { if (isEnableStatEndpoint() || isEnableHealthEndpoint()) { final boolean healthEnabled = isEnableHealthEndpoint(); final boolean statsEnabled = isEnableStatEndpoint(); final HealthServiceAsync healthServiceAsync = healthEnabled ? getHealthService() : null; final StatCollection statCollection = statsEnabled ? getStatsCollection() : null; httpServerBuilder.addShouldContinueHttpRequestPredicate( new EndPointHealthPredicate(healthEnabled, statsEnabled, healthServiceAsync, statCollection)); } return this; }