Detect Classic SignalR Server in Java Client (#7817)

This commit is contained in:
Mikael Mengistu 2019-02-28 18:12:53 -08:00 committed by GitHub
parent c0e6722020
commit 745941058c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -28,6 +28,9 @@ class NegotiateResponse {
case "error":
this.error = reader.nextString();
break;
case "ProtocolVersion":
this.error = "Detected an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.";
return;
case "url":
this.redirectUrl = reader.nextString();
break;
@ -69,7 +72,6 @@ class NegotiateResponse {
break;
}
} while (reader.hasNext());
reader.endObject();
reader.close();
} catch (IOException ex) {

View File

@ -1256,6 +1256,32 @@ class HubConnectionTest {
assertEquals("Test error.", exception.getMessage());
}
@Test
public void DetectWhenTryingToConnectToClassicSignalRServer() {
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate",
(req) -> Single.just(new HttpResponse(200, "", "{\"Url\":\"/signalr\"," +
"\"ConnectionToken\":\"X97dw3uxW4NPPggQsYVcNcyQcuz4w2\"," +
"\"ConnectionId\":\"05265228-1e2c-46c5-82a1-6a5bcc3f0143\"," +
"\"KeepAliveTimeout\":10.0," +
"\"DisconnectTimeout\":5.0," +
"\"TryWebSockets\":true," +
"\"ProtocolVersion\":\"1.5\"," +
"\"TransportConnectTimeout\":30.0," +
"\"LongPollDelay\":0.0}")));
MockTransport transport = new MockTransport(true);
HubConnection hubConnection = HubConnectionBuilder
.create("http://example.com")
.withHttpClient(client)
.withTransportImplementation(transport)
.build();
RuntimeException exception = assertThrows(RuntimeException.class,
() -> hubConnection.start().timeout(1, TimeUnit.SECONDS).blockingAwait());
assertEquals("Detected an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.",
exception.getMessage());
}
@Test
public void negotiateRedirectIsFollowed() {
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate",