Merge branch 'release/2.2'

This commit is contained in:
unknown 2018-08-08 18:06:19 -07:00
commit d32a5c14e1
45 changed files with 171 additions and 70 deletions

View File

@ -126,15 +126,9 @@
</Target> </Target>
<ItemGroup> <ItemGroup>
<JavaBuildFiles Include="signalr-client-$(JavaClientVersion).jar;signalr-client-$(JavaClientVersion)-javadoc.jar;signalr-client-$(JavaClientVersion)-sources.jar;signalr-client-$(JavaClientVersion).pom"/> <Jars Include="signalr-$(JavaClientVersion).jar;signalr-$(JavaClientVersion)-javadoc.jar;signalr-$(JavaClientVersion)-sources.jar;" />
</ItemGroup> <PomFile Include="signalr-$(JavaClientVersion).pom" />
<JavaBuildFiles Include="@(Jars);@(PomFile)"/>
<ItemGroup>
<Jars Include="signalr-client-$(JavaClientVersion).jar;signalr-client-$(JavaClientVersion)-javadoc.jar;signalr-client-$(JavaClientVersion)-sources.jar;" />
</ItemGroup>
<ItemGroup>
<PomFile Include="signalr-client-$(JavaClientVersion).pom" />
</ItemGroup> </ItemGroup>
<Target Name="PackJavaClient" Condition="'$(HasJdk)' == 'true'"> <Target Name="PackJavaClient" Condition="'$(HasJdk)' == 'true'">

View File

@ -3,7 +3,7 @@ plugins {
id 'maven' id 'maven'
} }
group 'com.microsoft.aspnetcore' group 'com.microsoft.aspnet'
version '0.1.0-preview1' version '0.1.0-preview1'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@ -31,11 +31,10 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
task generatePOM { task generatePOM {
pom { pom {
project { project {
groupId 'com.microsoft.aspnetcore'
artifactId 'signalr'
version '0.1.0-preview1'
inceptionYear '2018' inceptionYear '2018'
description 'ASP.NET Core SignalR Client for Java applications'
url 'https://github.com/aspnet/SignalR'
name groupId + ':' + artifactId
licenses { licenses {
license { license {
name 'The Apache Software License, Version 2.0' name 'The Apache Software License, Version 2.0'
@ -43,9 +42,20 @@ task generatePOM {
distribution 'repo' distribution 'repo'
} }
} }
scm {
connection 'scm:git:git://github.com/aspnet/SignalR.git'
developerConnection 'scm:git:git://github.com/aspnet/SignalR.git'
url 'http://github.com/aspnet/SignalR/tree/master'
}
developers {
developer {
id 'microsoft'
name 'Microsoft'
}
}
} }
}.writeTo("signalr-client-0.1.0-preview1.pom") }.writeTo("signalr-0.1.0-preview1.pom")
ant.move file: "signalr-client-0.1.0-preview1.pom", ant.move file: "signalr-0.1.0-preview1.pom",
todir: "${buildDir}/libs" todir: "${buildDir}/libs"
} }

View File

@ -1,3 +1,3 @@
rootProject.name = 'signalr-client' rootProject.name = 'signalr'
include 'main' include 'main'

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action { public interface Action {
void invoke(); void invoke();
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action1<T1> { public interface Action1<T1> {
void invoke(T1 param1); void invoke(T1 param1);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action2<T1, T2> { public interface Action2<T1, T2> {
void invoke(T1 param1, T2 param2); void invoke(T1 param1, T2 param2);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action3<T1, T2, T3> { public interface Action3<T1, T2, T3> {
void invoke(T1 param1, T2 param2, T3 param3); void invoke(T1 param1, T2 param2, T3 param3);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action4<T1, T2, T3, T4> { public interface Action4<T1, T2, T3, T4> {
void invoke(T1 param1, T2 param2, T3 param3, T4 param4); void invoke(T1 param1, T2 param2, T3 param3, T4 param4);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action5<T1, T2, T3, T4, T5> { public interface Action5<T1, T2, T3, T4, T5> {
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5); void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action6<T1, T2, T3, T4, T5, T6> { public interface Action6<T1, T2, T3, T4, T5, T6> {
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6); void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action7<T1, T2, T3, T4, T5, T6, T7> { public interface Action7<T1, T2, T3, T4, T5, T6, T7> {
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7); void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Action8<T1, T2, T3, T4, T5, T6, T7, T8> { public interface Action8<T1, T2, T3, T4, T5, T6, T7, T8> {
void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8); void invoke(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface ActionBase { public interface ActionBase {
void invoke(Object ... params); void invoke(Object ... params);
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -1,6 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
import com.microsoft.aspnet.signalr.HubConnection;
import java.util.Scanner; import java.util.Scanner;
public class Chat { public class Chat {

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public class ConsoleLogger implements Logger { public class ConsoleLogger implements Logger {
private LogLevel logLevel; private LogLevel logLevel;
public ConsoleLogger(LogLevel logLevel) { public ConsoleLogger(LogLevel logLevel) {

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
import com.google.gson.Gson; import com.google.gson.Gson;
public class HandshakeProtocol { public class HandshakeProtocol {

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public class HandshakeRequestMessage { public class HandshakeRequestMessage {
String protocol; String protocol;
int version; int version;

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public class HandshakeResponseMessage { public class HandshakeResponseMessage {
public String error; public String error;

View File

@ -1,9 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public enum HubConnectionState { public enum HubConnectionState {
CONNECTED, CONNECTED,
DISCONNECTED, DISCONNECTED,

View File

@ -1,9 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
/** /**
* A base class for hub messages. * A base class for hub messages.
*/ */
public abstract class HubMessage { public abstract class HubMessage {
abstract HubMessageType getMessageType(); public abstract HubMessageType getMessageType();
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public enum HubMessageType { public enum HubMessageType {
INVOCATION(1), INVOCATION(1),
STREAM_ITEM(2), STREAM_ITEM(2),

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
/** /**
* A protocol abstraction for communicating with SignalR hubs. * A protocol abstraction for communicating with SignalR hubs.
*/ */

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public class InvocationMessage extends HubMessage { public class InvocationMessage extends HubMessage {
int type = HubMessageType.INVOCATION.value; int type = HubMessageType.INVOCATION.value;
String invocationId; String invocationId;
@ -37,7 +39,7 @@ public class InvocationMessage extends HubMessage {
} }
@Override @Override
HubMessageType getMessageType() { public HubMessageType getMessageType() {
return HubMessageType.INVOCATION; return HubMessageType.INVOCATION;
} }
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public enum LogLevel { public enum LogLevel {
Trace(0), Trace(0),
Debug(1), Debug(1),

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Logger { public interface Logger {
void log(LogLevel logLevel, String message); void log(LogLevel logLevel, String message);
void log(LogLevel logLevel, String formattedMessage, Object ... args); void log(LogLevel logLevel, String formattedMessage, Object ... args);

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public class NullLogger implements Logger { public class NullLogger implements Logger {
@Override @Override
public void log(LogLevel logLevel, String message) { } public void log(LogLevel logLevel, String message) { }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.google.gson.JsonObject; package com.microsoft.aspnet.signalr;
public interface OnReceiveCallBack { public interface OnReceiveCallBack {
void invoke(String message) throws Exception; void invoke(String message) throws Exception;

View File

@ -1,12 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public class PingMessage extends HubMessage { public class PingMessage extends HubMessage {
int type = HubMessageType.PING.value; int type = HubMessageType.PING.value;
@Override @Override
HubMessageType getMessageType() { public HubMessageType getMessageType() {
return HubMessageType.PING; return HubMessageType.PING;
} }
} }

View File

@ -1,12 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
import java.util.List; import java.util.List;
public class Subscription { public class Subscription {
private CallbackMap handlers; private CallbackMap handlers;
private ActionBase action; private ActionBase action;
private String target; private String target;
public Subscription(CallbackMap handlers, ActionBase action, String target) { public Subscription(CallbackMap handlers, ActionBase action, String target) {
this.handlers = handlers; this.handlers = handlers;
this.action = action; this.action = action;

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public enum TransferFormat { public enum TransferFormat {
Text, Text,
Binary Binary

View File

@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr;
public interface Transport { public interface Transport {
void start() throws InterruptedException; void start() throws InterruptedException;
void send(String message) throws Exception; void send(String message) throws Exception;

View File

@ -1,11 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import org.java_websocket.client.WebSocketClient; package com.microsoft.aspnet.signalr;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
public class WebSocketTransport implements Transport { public class WebSocketTransport implements Transport {
private WebSocketClient webSocketClient; private WebSocketClient webSocketClient;

View File

@ -1,6 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.microsoft.aspnet.signalr.HandshakeProtocol;
import com.microsoft.aspnet.signalr.HandshakeRequestMessage;
import com.microsoft.aspnet.signalr.HandshakeResponseMessage;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import org.junit.Test; import com.microsoft.aspnet.signalr.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.microsoft.aspnet.signalr.*;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
@ -57,10 +58,10 @@ public class JsonHubProtocolTest {
//We can safely cast here because we know that it's an invocation message. //We can safely cast here because we know that it's an invocation message.
InvocationMessage invocationMessage = (InvocationMessage) messages[0]; InvocationMessage invocationMessage = (InvocationMessage) messages[0];
assertEquals("test", invocationMessage.target); assertEquals("test", invocationMessage.getTarget());
assertEquals(null, invocationMessage.invocationId); assertEquals(null, invocationMessage.getInvocationId());
JsonArray messageResult = (JsonArray) invocationMessage.arguments[0]; JsonArray messageResult = (JsonArray) invocationMessage.getArguments()[0];
assertEquals(42, messageResult.getAsInt()); assertEquals(42, messageResult.getAsInt());
} }
@ -95,9 +96,9 @@ public class JsonHubProtocolTest {
//Now that we know we have an invocation message we can cast the hubMessage. //Now that we know we have an invocation message we can cast the hubMessage.
InvocationMessage invocationMessage = (InvocationMessage) messages[0]; InvocationMessage invocationMessage = (InvocationMessage) messages[0];
assertEquals("one", invocationMessage.target); assertEquals("one", invocationMessage.getTarget());
assertEquals(null, invocationMessage.invocationId); assertEquals(null, invocationMessage.getInvocationId());
JsonArray messageResult = (JsonArray) invocationMessage.arguments[0]; JsonArray messageResult = (JsonArray) invocationMessage.getArguments()[0];
assertEquals(42, messageResult.getAsInt()); assertEquals(42, messageResult.getAsInt());
// Check the second message // Check the second message
@ -106,9 +107,9 @@ public class JsonHubProtocolTest {
//Now that we know we have an invocation message we can cast the hubMessage. //Now that we know we have an invocation message we can cast the hubMessage.
InvocationMessage invocationMessage2 = (InvocationMessage) messages[1]; InvocationMessage invocationMessage2 = (InvocationMessage) messages[1];
assertEquals("two", invocationMessage2.target); assertEquals("two", invocationMessage2.getTarget());
assertEquals(null, invocationMessage2.invocationId); assertEquals(null, invocationMessage2.getInvocationId());
JsonArray secondMessageResult = (JsonArray) invocationMessage2.arguments[0]; JsonArray secondMessageResult = (JsonArray) invocationMessage2.getArguments()[0];
assertEquals(43, secondMessageResult.getAsInt()); assertEquals(43, secondMessageResult.getAsInt());
} }
@ -121,9 +122,9 @@ public class JsonHubProtocolTest {
assertEquals(HubMessageType.INVOCATION, messages[0].getMessageType()); assertEquals(HubMessageType.INVOCATION, messages[0].getMessageType());
InvocationMessage message = (InvocationMessage)messages[0]; InvocationMessage message = (InvocationMessage)messages[0];
assertEquals("test", message.target); assertEquals("test", message.getTarget());
assertEquals(null, message.invocationId); assertEquals(null, message.getInvocationId());
JsonArray messageResult = ((JsonArray) message.arguments[0]); JsonArray messageResult = ((JsonArray) message.getArguments()[0]);
assertEquals(42, messageResult.get(0).getAsInt()); assertEquals(42, messageResult.get(0).getAsInt());
assertEquals(24, messageResult.get(1).getAsInt()); assertEquals(24, messageResult.get(1).getAsInt());
} }

View File

@ -1,13 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import org.junit.Test; import com.microsoft.aspnet.signalr.NullLogger;
import org.junit.runner.RunWith; import com.microsoft.aspnet.signalr.WebSocketTransport;
import org.junit.runners.Parameterized;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.*; import static org.junit.Assert.*;

View File

@ -35,6 +35,12 @@ export class HubConnectionBuilder {
* @returns The {@link @aspnet/signalr.HubConnectionBuilder} instance, for chaining. * @returns The {@link @aspnet/signalr.HubConnectionBuilder} instance, for chaining.
*/ */
public configureLogging(logger: ILogger): HubConnectionBuilder; public configureLogging(logger: ILogger): HubConnectionBuilder;
/** Configures custom logging for the {@link @aspnet/signalr.HubConnection}.
*
* @param {LogLevel | ILogger} logging An object implementing the {@link @aspnet/signalr.ILogger} interface or {@link @aspnet/signalr.LogLevel}.
* @returns The {@link @aspnet/signalr.HubConnectionBuilder} instance, for chaining.
*/
public configureLogging(logging: LogLevel | ILogger): HubConnectionBuilder;
public configureLogging(logging: LogLevel | ILogger): HubConnectionBuilder { public configureLogging(logging: LogLevel | ILogger): HubConnectionBuilder {
Arg.isRequired(logging, "logging"); Arg.isRequired(logging, "logging");

View File

@ -428,6 +428,7 @@ namespace Microsoft.AspNetCore.SignalR.Client
{ {
CheckDisposed(); CheckDisposed();
CheckConnectionActive(nameof(StreamAsChannelCoreAsync)); CheckConnectionActive(nameof(StreamAsChannelCoreAsync));
cancellationToken.ThrowIfCancellationRequested();
// I just want an excuse to use 'irq' as a variable name... // I just want an excuse to use 'irq' as a variable name...
var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel); var irq = InvocationRequest.Stream(cancellationToken, returnType, _connectionState.GetNextId(), _loggerFactory, this, out channel);

View File

@ -160,6 +160,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
{ {
Log.ReceivedStreamItem(_logger, message); Log.ReceivedStreamItem(_logger, message);
return connection.StreamTracker.ProcessItem(message); return connection.StreamTracker.ProcessItem(message);
} }
private Task ProcessInvocation(HubConnectionContext connection, private Task ProcessInvocation(HubConnectionContext connection,
@ -496,9 +497,8 @@ namespace Microsoft.AspNetCore.SignalR.Internal
{ {
if (!_methods.TryGetValue(methodName, out var descriptor)) if (!_methods.TryGetValue(methodName, out var descriptor))
{ {
return Type.EmptyTypes; throw new HubException("Method does not exist.");
} }
return descriptor.ParameterTypes; return descriptor.ParameterTypes;
} }
} }

View File

@ -163,10 +163,10 @@ namespace Microsoft.AspNetCore.SignalR.Protocol
} }
var target = ReadString(input, ref offset, "target"); var target = ReadString(input, ref offset, "target");
var parameterTypes = binder.GetParameterTypes(target);
try try
{ {
var parameterTypes = binder.GetParameterTypes(target);
var arguments = BindArguments(input, ref offset, parameterTypes, resolver); var arguments = BindArguments(input, ref offset, parameterTypes, resolver);
return ApplyHeaders(headers, new InvocationMessage(invocationId, target, arguments)); return ApplyHeaders(headers, new InvocationMessage(invocationId, target, arguments));
} }
@ -182,10 +182,9 @@ namespace Microsoft.AspNetCore.SignalR.Protocol
var invocationId = ReadInvocationId(input, ref offset); var invocationId = ReadInvocationId(input, ref offset);
var target = ReadString(input, ref offset, "target"); var target = ReadString(input, ref offset, "target");
var parameterTypes = binder.GetParameterTypes(target);
try try
{ {
var parameterTypes = binder.GetParameterTypes(target);
var arguments = BindArguments(input, ref offset, parameterTypes, resolver); var arguments = BindArguments(input, ref offset, parameterTypes, resolver);
return ApplyHeaders(headers, new StreamInvocationMessage(invocationId, target, arguments)); return ApplyHeaders(headers, new StreamInvocationMessage(invocationId, target, arguments));
} }

View File

@ -398,15 +398,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))] [MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path) public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{ {
bool ExpectedErrors(WriteContext writeContext)
{
return (writeContext.LoggerName == nameof(Http.Connections.Client.Internal.ServerSentEventsTransport) ||
writeContext.LoggerName == nameof(Http.Connections.Client.Internal.LongPollingTransport)) &&
writeContext.EventId.Name == "ErrorSending";
}
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(path, transportType, protocol, loggerFactory);
try try
@ -416,10 +409,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
cts.Cancel(); cts.Cancel();
var channel = await connection.StreamAsChannelAsync<int>("Stream", 5, cts.Token).OrTimeout(); await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>connection.StreamAsChannelAsync<int>("Stream", 5, cts.Token).OrTimeout());
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
channel.WaitToReadAsync().AsTask().OrTimeout());
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -474,7 +464,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
bool ExpectedErrors(WriteContext writeContext) bool ExpectedErrors(WriteContext writeContext)
{ {
return writeContext.LoggerName == DefaultHubDispatcherLoggerName && return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "UnknownHubMethod"; writeContext.EventId.Name == "FailedInvokingHubMethod";
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
@ -486,7 +476,40 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
var ex = await Assert.ThrowsAsync<HubException>(() => connection.InvokeAsync("!@#$%")).OrTimeout(); var ex = await Assert.ThrowsAsync<HubException>(() => connection.InvokeAsync("!@#$%")).OrTimeout();
Assert.Equal("Unknown hub method '!@#$%'", ex.Message); Assert.Equal("Failed to invoke '!@#$%' due to an error on the server. HubException: Method does not exist.", ex.Message);
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
{
await connection.DisposeAsync().OrTimeout();
}
}
}
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn(string hubProtocolName, HttpTransportType transportType, string hubPath)
{
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "FailedInvokingHubMethod";
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory);
try
{
await connection.StartAsync().OrTimeout();
var ex = await Assert.ThrowsAsync<HubException>(() => connection.InvokeAsync("!@#$%", 10, "test")).OrTimeout();
Assert.Equal("Failed to invoke '!@#$%' due to an error on the server. HubException: Method does not exist.", ex.Message);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -573,7 +596,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
bool ExpectedErrors(WriteContext writeContext) bool ExpectedErrors(WriteContext writeContext)
{ {
return writeContext.LoggerName == DefaultHubDispatcherLoggerName && return writeContext.LoggerName == DefaultHubDispatcherLoggerName &&
writeContext.EventId.Name == "UnknownHubMethod"; writeContext.EventId.Name == "FailedInvokingHubMethod";
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
@ -586,7 +609,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var channel = await connection.StreamAsChannelAsync<int>("!@#$%"); var channel = await connection.StreamAsChannelAsync<int>("!@#$%");
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout()); var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
Assert.Equal("Unknown hub method '!@#$%'", ex.Message); Assert.Equal("Failed to invoke '!@#$%' due to an error on the server. HubException: Method does not exist.", ex.Message);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -800,7 +800,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
var result = await client.InvokeAsync(nameof(MethodHub.OnDisconnectedAsync)).OrTimeout(); var result = await client.InvokeAsync(nameof(MethodHub.OnDisconnectedAsync)).OrTimeout();
Assert.Equal("Unknown hub method 'OnDisconnectedAsync'", result.Error); Assert.Equal("Failed to invoke 'OnDisconnectedAsync' due to an error on the server. HubException: Method does not exist.", result.Error);
// kill the connection // kill the connection
client.Dispose(); client.Dispose();
@ -838,7 +838,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
var result = await client.InvokeAsync(nameof(MethodHub.StaticMethod)).OrTimeout(); var result = await client.InvokeAsync(nameof(MethodHub.StaticMethod)).OrTimeout();
Assert.Equal("Unknown hub method 'StaticMethod'", result.Error); Assert.Equal("Failed to invoke 'StaticMethod' due to an error on the server. HubException: Method does not exist.", result.Error);
// kill the connection // kill the connection
client.Dispose(); client.Dispose();
@ -859,16 +859,16 @@ namespace Microsoft.AspNetCore.SignalR.Tests
var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
var result = await client.InvokeAsync(nameof(MethodHub.ToString)).OrTimeout(); var result = await client.InvokeAsync(nameof(MethodHub.ToString)).OrTimeout();
Assert.Equal("Unknown hub method 'ToString'", result.Error); Assert.Equal("Failed to invoke 'ToString' due to an error on the server. HubException: Method does not exist.", result.Error);
result = await client.InvokeAsync(nameof(MethodHub.GetHashCode)).OrTimeout(); result = await client.InvokeAsync(nameof(MethodHub.GetHashCode)).OrTimeout();
Assert.Equal("Unknown hub method 'GetHashCode'", result.Error); Assert.Equal("Failed to invoke 'GetHashCode' due to an error on the server. HubException: Method does not exist.", result.Error);
result = await client.InvokeAsync(nameof(MethodHub.Equals)).OrTimeout(); result = await client.InvokeAsync(nameof(MethodHub.Equals)).OrTimeout();
Assert.Equal("Unknown hub method 'Equals'", result.Error); Assert.Equal("Failed to invoke 'Equals' due to an error on the server. HubException: Method does not exist.", result.Error);
result = await client.InvokeAsync(nameof(MethodHub.ReferenceEquals)).OrTimeout(); result = await client.InvokeAsync(nameof(MethodHub.ReferenceEquals)).OrTimeout();
Assert.Equal("Unknown hub method 'ReferenceEquals'", result.Error); Assert.Equal("Failed to invoke 'ReferenceEquals' due to an error on the server. HubException: Method does not exist.", result.Error);
// kill the connection // kill the connection
client.Dispose(); client.Dispose();
@ -890,7 +890,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
var result = await client.InvokeAsync(nameof(MethodHub.Dispose)).OrTimeout(); var result = await client.InvokeAsync(nameof(MethodHub.Dispose)).OrTimeout();
Assert.Equal("Unknown hub method 'Dispose'", result.Error); Assert.Equal("Failed to invoke 'Dispose' due to an error on the server. HubException: Method does not exist.", result.Error);
// kill the connection // kill the connection
client.Dispose(); client.Dispose();