[Java] Fix skip negotiate null ref (#30482)
* [Java] Fix skip negotiate null ref * comment * fixup * minimize change
This commit is contained in:
parent
08df1c0ff2
commit
586b8bb5af
|
|
@ -264,7 +264,13 @@ public class HubConnection implements AutoCloseable {
|
|||
Transport transport = customTransport;
|
||||
if (transport == null) {
|
||||
Single<String> tokenProvider = negotiateResponse.getAccessToken() != null ? Single.just(negotiateResponse.getAccessToken()) : accessTokenProvider;
|
||||
switch (negotiateResponse.getChosenTransport()) {
|
||||
TransportEnum chosenTransport;
|
||||
if (this.skipNegotiate) {
|
||||
chosenTransport = this.transportEnum;
|
||||
} else {
|
||||
chosenTransport = negotiateResponse.getChosenTransport();
|
||||
}
|
||||
switch (chosenTransport) {
|
||||
case LONG_POLLING:
|
||||
transport = new LongPollingTransport(localHeaders, httpClient, tokenProvider);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -2743,6 +2743,37 @@ class HubConnectionTest {
|
|||
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 connectionIdIsAvailableAfterStart() {
|
||||
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1",
|
||||
|
|
|
|||
Loading…
Reference in New Issue