diff --git a/src/SignalR/build.cmd b/src/SignalR/build.cmd index 82cc47e85530..4617421f3e7d 100644 --- a/src/SignalR/build.cmd +++ b/src/SignalR/build.cmd @@ -1,3 +1,3 @@ @ECHO OFF SET RepoRoot=%~dp0..\.. -%RepoRoot%\eng\build.cmd -buildJava -projects %~dp0**\*.*proj %* +%RepoRoot%\eng\build.cmd -nobuildnative -buildJava -projects %~dp0**\*.*proj %* diff --git a/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HttpHubConnectionBuilder.java b/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HttpHubConnectionBuilder.java index 24722eba1753..09a4c04eddd1 100644 --- a/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HttpHubConnectionBuilder.java +++ b/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HttpHubConnectionBuilder.java @@ -69,7 +69,8 @@ public HttpHubConnectionBuilder withHubProtocol(HubProtocol protocol) { /** * Indicates to the {@link HubConnection} that it should skip the negotiate process. - * Note: This option only works with the Websockets transport and the Azure SignalR Service require the negotiate step. + * Note: This option only works with the {@link TransportEnum#WEBSOCKETS} transport selected via {@link #withTransport(TransportEnum) withTransport}, + * additionally the Azure SignalR Service requires the negotiate step so this will fail when using the Azure SignalR Service. * * @param skipNegotiate Boolean indicating if the {@link HubConnection} should skip the negotiate step. * @return This instance of the HttpHubConnectionBuilder. diff --git a/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java b/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java index c20e051eab46..5710823b7cba 100644 --- a/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java +++ b/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java @@ -264,7 +264,16 @@ public Completable start() { Transport transport = customTransport; if (transport == null) { Single tokenProvider = negotiateResponse.getAccessToken() != null ? Single.just(negotiateResponse.getAccessToken()) : accessTokenProvider; - switch (negotiateResponse.getChosenTransport()) { + TransportEnum chosenTransport; + if (this.skipNegotiate) { + if (this.transportEnum != TransportEnum.WEBSOCKETS) { + throw new RuntimeException("Negotiation can only be skipped when using the WebSocket transport directly with '.withTransport(TransportEnum.WEBSOCKETS)' on the 'HubConnectionBuilder'."); + } + chosenTransport = this.transportEnum; + } else { + chosenTransport = negotiateResponse.getChosenTransport(); + } + switch (chosenTransport) { case LONG_POLLING: transport = new LongPollingTransport(localHeaders, httpClient, tokenProvider); break; diff --git a/src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/HubConnectionTest.java b/src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/HubConnectionTest.java index 330288f3cfba..3b694570e7ef 100644 --- a/src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/HubConnectionTest.java +++ b/src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/HubConnectionTest.java @@ -2743,6 +2743,63 @@ public void noConnectionIdWhenSkippingNegotiate() { assertNull(hubConnection.getConnectionId()); } + @Test + public void SkippingNegotiateDoesNotNegotiate() { + try (TestLogger logger = new TestLogger(WebSocketTransport.class.getName())) { + AtomicBoolean negotiateCalled = new AtomicBoolean(false); + TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1", + (req) -> { + negotiateCalled.set(true); + return Single.just(new HttpResponse(200, "", + TestUtils.stringToByteBuffer("{\"connectionId\":\"bVOiRPG8-6YiJ6d7ZcTOVQ\",\"" + + "availableTransports\":[{\"transport\":\"WebSockets\",\"transferFormats\":[\"Text\",\"Binary\"]}]}"))); + }); + + HubConnection hubConnection = HubConnectionBuilder + .create("http://example") + .withTransport(TransportEnum.WEBSOCKETS) + .shouldSkipNegotiate(true) + .withHttpClient(client) + .build(); + + try { + hubConnection.start().timeout(30, TimeUnit.SECONDS).blockingAwait(); + } catch (Exception e) { + assertEquals("WebSockets isn't supported in testing currently.", e.getMessage()); + } + assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState()); + assertFalse(negotiateCalled.get()); + + logger.assertLog("Starting Websocket connection."); + } + } + + @Test + public void ThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets() { + AtomicBoolean negotiateCalled = new AtomicBoolean(false); + TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1", + (req) -> { + negotiateCalled.set(true); + return Single.just(new HttpResponse(200, "", + TestUtils.stringToByteBuffer("{\"connectionId\":\"bVOiRPG8-6YiJ6d7ZcTOVQ\",\"" + + "availableTransports\":[{\"transport\":\"WebSockets\",\"transferFormats\":[\"Text\",\"Binary\"]}]}"))); + }); + + HubConnection hubConnection = HubConnectionBuilder + .create("http://example") + .shouldSkipNegotiate(true) + .withHttpClient(client) + .build(); + + try { + hubConnection.start().timeout(30, TimeUnit.SECONDS).blockingAwait(); + } catch (Exception e) { + assertEquals("Negotiation can only be skipped when using the WebSocket transport directly with '.withTransport(TransportEnum.WEBSOCKETS)' on the 'HubConnectionBuilder'.", e.getMessage()); + } + assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState()); + assertFalse(negotiateCalled.get()); + } + @Test public void connectionIdIsAvailableAfterStart() { TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1",