Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit649cf21

Browse files
[SignalR] Don't throw for message headers in Java client (#62783)
Co-authored-by: Brennan <brecon@microsoft.com>
1 parent612bc0d commit649cf21

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

‎src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ public List<HubMessage> parseMessages(ByteBuffer payload, InvocationBinder binde
126126
}
127127
break;
128128
case"headers":
129-
thrownewRuntimeException("Headers not implemented yet.");
129+
// Parse headers as Map<String, String> but don't store for now as it's unused
130+
reader.beginObject();
131+
while (reader.hasNext()) {
132+
reader.nextName();// Read the key
133+
reader.nextString();// Read the value
134+
}
135+
reader.endObject();
136+
break;
130137
default:
131138
// Skip unknown property, allows new clients to still work with old protocols
132139
reader.skipValue();

‎src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/GsonHubProtocolTest.java‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,98 @@ public void canRegisterTypeAdaptorWithoutAffectingJsonProtocol() {
527527
assertEquals(3, (int)invocationMessage.getArguments()[0]);
528528
assertEquals("four",invocationMessage.getArguments()[1]);
529529
}
530+
531+
@Test
532+
publicvoidcanParseInvocationMessageWithHeaders() {
533+
StringstringifiedMessage ="{\"type\":1,\"target\":\"test\",\"arguments\":[42],\"headers\":{\"a\":\"b\",\"c\":\"d\"}}\u001E";
534+
ByteBuffermessage =TestUtils.stringToByteBuffer(stringifiedMessage);
535+
TestBinderbinder =newTestBinder(newType[] {int.class },null);
536+
537+
List<HubMessage>messages =hubProtocol.parseMessages(message,binder);
538+
539+
assertNotNull(messages);
540+
assertEquals(1,messages.size());
541+
542+
assertEquals(HubMessageType.INVOCATION,messages.get(0).getMessageType());
543+
InvocationMessageinvocationMessage = (InvocationMessage)messages.get(0);
544+
545+
assertEquals("test",invocationMessage.getTarget());
546+
assertEquals(null,invocationMessage.getInvocationId());
547+
intmessageResult = (int)invocationMessage.getArguments()[0];
548+
assertEquals(42,messageResult);
549+
// Headers are parsed but not stored, so we just verify the message was processed successfully
550+
}
551+
552+
@Test
553+
publicvoidcanParseInvocationMessageWithEmptyHeaders() {
554+
StringstringifiedMessage ="{\"type\":1,\"target\":\"test\",\"arguments\":[42],\"headers\":{}}\u001E";
555+
ByteBuffermessage =TestUtils.stringToByteBuffer(stringifiedMessage);
556+
TestBinderbinder =newTestBinder(newType[] {int.class },null);
557+
558+
List<HubMessage>messages =hubProtocol.parseMessages(message,binder);
559+
560+
assertNotNull(messages);
561+
assertEquals(1,messages.size());
562+
563+
assertEquals(HubMessageType.INVOCATION,messages.get(0).getMessageType());
564+
InvocationMessageinvocationMessage = (InvocationMessage)messages.get(0);
565+
566+
assertEquals("test",invocationMessage.getTarget());
567+
intmessageResult = (int)invocationMessage.getArguments()[0];
568+
assertEquals(42,messageResult);
569+
}
570+
571+
@Test
572+
publicvoidcanParseCompletionMessageWithHeaders() {
573+
StringstringifiedMessage ="{\"type\":3,\"invocationId\":\"1\",\"result\":42,\"headers\":{\"a\":\"b\",\"c\":\"d\"}}\u001E";
574+
ByteBuffermessage =TestUtils.stringToByteBuffer(stringifiedMessage);
575+
TestBinderbinder =newTestBinder(null,int.class);
576+
577+
List<HubMessage>messages =hubProtocol.parseMessages(message,binder);
578+
579+
assertNotNull(messages);
580+
assertEquals(1,messages.size());
581+
582+
assertEquals(HubMessageType.COMPLETION,messages.get(0).getMessageType());
583+
CompletionMessagecompletionMessage = (CompletionMessage)messages.get(0);
584+
assertEquals("1",completionMessage.getInvocationId());
585+
assertEquals(42,completionMessage.getResult());
586+
assertEquals(null,completionMessage.getError());
587+
}
588+
589+
@Test
590+
publicvoidcanParseStreamItemMessageWithHeaders() {
591+
StringstringifiedMessage ="{\"type\":2,\"invocationId\":\"1\",\"item\":\"test-item\",\"headers\":{\"a\":\"b\"}}\u001E";
592+
ByteBuffermessage =TestUtils.stringToByteBuffer(stringifiedMessage);
593+
TestBinderbinder =newTestBinder(null,String.class);
594+
595+
List<HubMessage>messages =hubProtocol.parseMessages(message,binder);
596+
597+
assertNotNull(messages);
598+
assertEquals(1,messages.size());
599+
600+
assertEquals(HubMessageType.STREAM_ITEM,messages.get(0).getMessageType());
601+
StreamItemstreamItem = (StreamItem)messages.get(0);
602+
assertEquals("1",streamItem.getInvocationId());
603+
assertEquals("test-item",streamItem.getItem());
604+
}
605+
606+
@Test
607+
publicvoidcanParseMessageWithHeadersInDifferentOrder() {
608+
StringstringifiedMessage ="{\"headers\":{\"First\":\"value1\",\"Second\":\"value2\"},\"type\":1,\"target\":\"test\",\"arguments\":[42]}\u001E";
609+
ByteBuffermessage =TestUtils.stringToByteBuffer(stringifiedMessage);
610+
TestBinderbinder =newTestBinder(newType[] {int.class },null);
611+
612+
List<HubMessage>messages =hubProtocol.parseMessages(message,binder);
613+
614+
assertNotNull(messages);
615+
assertEquals(1,messages.size());
616+
617+
assertEquals(HubMessageType.INVOCATION,messages.get(0).getMessageType());
618+
InvocationMessageinvocationMessage = (InvocationMessage)messages.get(0);
619+
620+
assertEquals("test",invocationMessage.getTarget());
621+
intmessageResult = (int)invocationMessage.getArguments()[0];
622+
assertEquals(42,messageResult);
623+
}
530624
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp