@Test public void test() throws Exception { ok = objectUnderTest.setHost("host").getHost().equals("host") || die(); ok = objectUnderTest.setHost("localhost").getHost().equals("localhost") || die(); ok = objectUnderTest.setPipeline(true).isPipeline() || die(); ok = !objectUnderTest.setPipeline(false).isPipeline() || die(); ok = objectUnderTest.setPort(9090).getPort() == 9090 || die(); ok = objectUnderTest.setPort(8080).getPort() == 8080 || die(); ok = objectUnderTest.setFlushInterval(909).getFlushInterval() == 909 || die(); ok = objectUnderTest.setFlushInterval(808).getFlushInterval() == 808 || die(); objectUnderTest.build(); } }
public void connect() { port = PortUtils.findOpenPortStartAt(port); server = new HttpServerBuilder().setPort(port).build(); client = new HttpClientBuilder().setPoolSize(1).setPort(port).build(); requestReceived = new AtomicBoolean(); responseReceived = new AtomicBoolean(); messageBody = new AtomicReference<>(); responseCode = new AtomicInteger(); port++; }
public HttpServer build() { final HttpServer httpServer = getFactory().createHttpServer( this.getConfig(), this.getEndpointName(), this.getSystemManager(), this.getServiceDiscovery(), this.getHealthServiceAsync(), this.getServiceDiscoveryTtl(), this.getServiceDiscoveryTtlTimeUnit(), this.getResponseDecorators(), this.getHttpResponseCreator(), this.getRequestBodyContinuePredicate() ); if (requestContinuePredicate != null) { httpServer.setShouldContinueHttpRequest(requestContinuePredicate); } if (qBitSystemManager != null) { qBitSystemManager.registerServer(httpServer); } return httpServer; }
public HttpServerBuilder getHttpServerBuilder() { if (httpServerBuilder == null) { httpServerBuilder = httpServerBuilder().setPort(getPort()) .setHost(getHost()) .setFlushInterval(this.getFlushInterval()) .setSystemManager(getSystemManager()); setupHealthAndStats(httpServerBuilder); } return httpServerBuilder; }
/** * @return http server builder */ public HttpServerBuilder getHttpServerBuilder() { if (httpServerBuilder == null) { httpServerBuilder = HttpServerBuilder.httpServerBuilder(); int port = getPort(); if (!Str.isEmpty(port)) { httpServerBuilder.setPort(port); } } return httpServerBuilder; }
@Test public void testBinary() throws Exception { final int port = PortUtils.findOpenPortStartAt(4001); final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build(); final AtomicReference<Object> bodyRef = new AtomicReference<>(); final AtomicReference<byte[]> messageRef = new AtomicReference<>(); final CountDownLatch countDownLatch = new CountDownLatch(2); httpServer.setWebSocketMessageConsumer(webSocketMessage -> { bodyRef.set(webSocketMessage.body()); webSocketMessage.getSender().sendBytes("world".getBytes()); countDownLatch.countDown(); }); httpServer.startServerAndWait(); final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart(); final WebSocket webSocket = httpClient.createWebSocket("/foo"); webSocket.setBinaryMessageConsumer(message -> { messageRef.set(message); countDownLatch.countDown(); }); webSocket.openAndWait(); webSocket.sendBinary("hello".getBytes()); countDownLatch.await(5, TimeUnit.SECONDS); assertEquals("world", new String(messageRef.get(), StandardCharsets.UTF_8)); assertEquals("hello", new String(((byte[]) bodyRef.get()), StandardCharsets.UTF_8)); }
public HttpServer getHttpServer() { if (httpServer == null) { httpServer = getHttpServerBuilder() .setPort(getPort()) .setHost(getHost()) .build(); final Supplier<String> webPageContentsSupplier = getWebPageContentsSupplier(); httpServer.setShouldContinueHttpRequest(httpRequest -> { /* If not the page uri we want to then, just continue by returning true. */ if (!httpRequest.getUri().equals(getHtmlPageLocation())) { return true; } final String webPageContents = webPageContentsSupplier.get(); /* Send the HTML file out to the browser. */ httpRequest.getReceiver().response(200, "text/html", webPageContents); return false; }); } return httpServer; }
server = new HttpServerBuilder().setPort(port - 1) .addRequestBodyContinuePredicate(httpRequest -> { if (httpRequest.getContentLength() > 0) { httpRequest.getReceiver().response(500, "applicaiton/json", "\"too big\""); .build();
public HttpTransport getHttpServer() { if (httpServer == null) { httpServer = getHttpServerBuilder().build(); } return httpServer; }
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 HttpServerBuilder getHttpServerBuilder() { if (httpServerBuilder == null) { httpServerBuilder = HttpServerBuilder.httpServerBuilder(); } return httpServerBuilder; }
public static HttpServerBuilder httpServerBuilder() { return new HttpServerBuilder(); }
super.getConfig().getFlushInterval(), this.getEndpointName(), this.getVertx(), this.getSystemManager(), this.getServiceDiscovery(), this.getHealthServiceAsync(), getServiceDiscoveryTtl(),
@Test public void testText() throws Exception { final int port = PortUtils.findOpenPortStartAt(4000); final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build(); final AtomicReference<Object> bodyRef = new AtomicReference<>(); final AtomicReference<String> messageRef = new AtomicReference<>(); final CountDownLatch countDownLatch = new CountDownLatch(2); httpServer.setWebSocketMessageConsumer(webSocketMessage -> { bodyRef.set(webSocketMessage.body()); webSocketMessage.getSender().sendText("world"); countDownLatch.countDown(); }); httpServer.startServerAndWait(); final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart(); final WebSocket webSocket = httpClient.createWebSocket("/foo"); webSocket.setTextMessageConsumer(message -> { messageRef.set(message); countDownLatch.countDown(); }); webSocket.openAndWait(); webSocket.sendText("hello"); countDownLatch.await(5, TimeUnit.SECONDS); assertEquals("world", messageRef.get()); assertEquals("hello", bodyRef.get().toString()); }
public HttpServerBuilder getHttpServerBuilder() { if (httpServerBuilder == null) { httpServerBuilder = httpServerBuilder().setPort(getPort()) .setHost(getHost()) .setFlushInterval(this.getFlushInterval()) .setSystemManager(getSystemManager()); setupHealthAndStats(httpServerBuilder); } return httpServerBuilder; }
public HttpProxy build() { return new HttpProxy(getHttpServerBuilder().build(), getProxyBuilder().buildProxy()); } }
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;
public HttpServerBuilder getHttpServerBuilder() { if (httpServerBuilder == null) { httpServerBuilder = HttpServerBuilder.httpServerBuilder(); } return httpServerBuilder; }
public static HttpServerBuilder httpServerBuilder() { return new HttpServerBuilder(); }
super.getConfig().getFlushInterval(), this.getEndpointName(), this.getVertx(), this.getSystemManager(), this.getServiceDiscovery(), this.getHealthServiceAsync(), getServiceDiscoveryTtl(),