Java Code Examples for io.vertx.core.http.RequestOptions#setHost()
The following examples show how to use
io.vertx.core.http.RequestOptions#setHost() .
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: ListenerVertx.java From symbol-sdk-java with Apache License 2.0 | 6 votes |
/** * @return a {@link CompletableFuture} that resolves when the websocket connection is opened */ @Override public CompletableFuture<Void> open() { CompletableFuture<Void> future = new CompletableFuture<>(); if (this.webSocket != null) { return CompletableFuture.completedFuture(null); } RequestOptions requestOptions = new RequestOptions(); requestOptions.setHost(this.url.getHost()); requestOptions.setPort(this.url.getPort()); requestOptions.setURI("/ws"); httpClient.websocket( requestOptions, ws -> { this.webSocket = ws; ws.handler( handler -> { ObjectNode message = getJsonHelper() .convert(handler.toJsonObject(), ObjectNode.class); handle(message, future); }); }); return future; }
Example 2
Source File: WebSocketServiceLoginTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void websocketServiceWithBadHeaderAuthenticationToken(final TestContext context) { final Async async = context.async(); final String request = "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"syncing\"]}"; final String expectedResponse = "{\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":-40100,\"message\":\"Unauthorized\"}}"; RequestOptions options = new RequestOptions(); options.setURI("/"); options.setHost(websocketConfiguration.getHost()); options.setPort(websocketConfiguration.getPort()); final MultiMap headers = new VertxHttpHeaders(); String badtoken = "badtoken"; if (badtoken != null) { headers.add("Authorization", "Bearer " + badtoken); } httpClient.websocket( options, headers, webSocket -> { webSocket.writeTextMessage(request); webSocket.handler( buffer -> { context.assertEquals(expectedResponse, buffer.toString()); async.complete(); }); }); async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS); }
Example 3
Source File: WebSocketServiceLoginTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void websocketServiceWithGoodHeaderAuthenticationToken(final TestContext context) { final Async async = context.async(); final JWTOptions jwtOptions = new JWTOptions().setExpiresInMinutes(5).setAlgorithm("RS256"); final JsonObject jwtContents = new JsonObject().put("permissions", Lists.newArrayList("eth:*")).put("username", "user"); final String goodToken = jwtAuth.generateToken(jwtContents, jwtOptions); final String requestSub = "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"syncing\"]}"; final String expectedResponse = "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}"; RequestOptions options = new RequestOptions(); options.setURI("/"); options.setHost(websocketConfiguration.getHost()); options.setPort(websocketConfiguration.getPort()); final MultiMap headers = new VertxHttpHeaders(); if (goodToken != null) { headers.add("Authorization", "Bearer " + goodToken); } httpClient.websocket( options, headers, webSocket -> { webSocket.writeTextMessage(requestSub); webSocket.handler( buffer -> { context.assertEquals(expectedResponse, buffer.toString()); async.complete(); }); }); async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS); }
Example 4
Source File: WebSocketConnection.java From besu with Apache License 2.0 | 5 votes |
public WebSocketConnection(final Vertx vertx, final NodeConfiguration node) { if (!node.getJsonRpcWebSocketPort().isPresent()) { throw new IllegalStateException( "Can't start websocket connection for node with RPC disabled"); } subscriptionEvents = new ConcurrentLinkedDeque<>(); options = new RequestOptions(); options.setPort(node.getJsonRpcWebSocketPort().get()); options.setHost(node.getHostName()); connect(vertx); }