Detect Classic SignalR Server in Java Client (#7817)
This commit is contained in:
parent
c0e6722020
commit
745941058c
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue