Describe the bug
I am following https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/communication/azure-communication-chat/src/samples/java/com/azure/communication/chat/ReadmeSamples.java to setup chat client for azure communication service using Java Sdk.
I am able to get valid user access token but when I am trying to create chat thread using
createChatThread() function
I am getting 401 exception
Exception or Stack Trace
Exception in thread "main" com.azure.communication.chat.models.ErrorException: Status code 401, (empty body)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.azure.core.http.rest.RestProxy.instantiateUnexpectedException(RestProxy.java:334)
at com.azure.core.http.rest.RestProxy.lambda$ensureExpectedStatus$8(RestProxy.java:395)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.core.publisher.Mono.subscribe(Mono.java:4213)
at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:75)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onComplete(MonoFlatMap.java:174)
at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onComplete(FluxDoFinally.java:138)
at reactor.core.publisher.FluxHandle$HandleSubscriber.onComplete(FluxHandle.java:206)
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onComplete(FluxMap.java:262)
at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onComplete(FluxDoFinally.java:138)
at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:195)
at reactor.core.publisher.FluxContextStart$ContextStartSubscriber.onNext(FluxContextStart.java:96)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1782)
at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:121)
at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:252)
at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:136)
at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:374)
at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:373)
at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:429)
at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:655)
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:96)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1526)
at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1287)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1324)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:501)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:440)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.kqueue.AbstractKQueueStreamChannel$KQueueStreamUnsafe.readReady(AbstractKQueueStreamChannel.java:544)
at io.netty.channel.kqueue.AbstractKQueueChannel$AbstractKQueueUnsafe.readReady(AbstractKQueueChannel.java:381)
at io.netty.channel.kqueue.KQueueEventLoop.processReady(KQueueEventLoop.java:211)
at io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:289)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
at reactor.core.publisher.Mono.block(Mono.java:1680)
at com.azure.communication.chat.ChatClient.createChatThread(ChatClient.java:59)
at App.createChatThread(App.java:87)
at App.main(App.java:20)
To Reproduce
Step 1: Generate user access token for Azure communication trusted service
Step 2: Add main function in https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/communication/azure-communication-chat/src/samples/java/com/azure/communication/chat/ReadmeSamples.java
Step 3: Update values of endpoint and token.
Step 4: call createChatThread() function
Code Snippet
ChatThreadClient chatThreadClient = chatClient.createChatThread(createChatThreadOptions);
Expected behavior
Function should create a chat thread using the sync chat client.
Setup (please complete the following information):
@RezaJooyandeh could you please follow up?
@juancamilor and @angiurgiu do you mind looking into this issue?
@danielgerlag could you take a look with @angiurgiu 's help ? This is the current production sdk (not the one with WIP)
@salujamanish looking into it, will get back to you soon.
@salujamanish How did you create the communication users that you passed in the createChatThreadOptions parameter?
The readme sample has hard coded users for examples... did you use your own CommunicationUser instances?
Does this tutorial work for you?
https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-java
@salujamanish How did you create the communication users that you passed in the
createChatThreadOptionsparameter?
The readme sample has hard coded users for examples... did you use your ownCommunicationUserinstances?Does this tutorial work for you?
https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-java
@danielgerlag below is the snippet of my code, I just followed the given documentation.
CommunicationUser user1 = new CommunicationUser("d1ab-1d3a0d00012d");
CommunicationUser user2 = new CommunicationUser("a1ab-1d3a0d00012c");
List<ChatThreadMember> members = new ArrayList<ChatThreadMember>();
ChatThreadMember firstThreadMember = new ChatThreadMember()
.setUser(user1)
.setDisplayName(" Name 1");
ChatThreadMember secondThreadMember = new ChatThreadMember()
.setUser(user2)
.setDisplayName(" Name 2");
members.add(firstThreadMember);
members.add(secondThreadMember);
CreateChatThreadOptions createChatThreadOptions = new CreateChatThreadOptions()
.setTopic("Topic")
.setMembers(members);
@salujamanish could you provide a little more context that precedes that snippet?
When you create the ChatClient, are you using the token of user1 or the access token of your ACS resource in Azure?
How did you originally create user1 and user2 inside your ACS resource?
@salujamanish just following up, can you provide the additional details? or were you already able to resolve your issue?
@salujamanish just following up again.
I contacted @salujamanish directly and confirmed he was able to resolve his issue... this was not a bug.
@danielgerlag what is solution, since am also facing the same issue. @salujamanish can you post the fix the here ?
@skunchakuri the snippets were used out of context... please follow this tutorial for prerequisites and end to end instructions on setting up chat.
@danielgerlag @salujamanish i followed the same in provided resource. FYI we have tired in JAVA and React Js and Angular Js too. we blocked here, can anyone post the solution here.
@skunchakuri Did you create identities and access tokens for your chat users like this?
https://docs.microsoft.com/en-us/azure/communication-services/quickstarts/access-tokens?pivots=programming-language-java
for chat users (connection userid) i have created a token.
On Mon, Feb 8, 2021 at 9:10 PM Daniel Gerlag notifications@github.com
wrote:
@skunchakuri https://github.com/skunchakuri Did you create identities
and access tokens for your chat users like this?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Azure/azure-sdk-for-java/issues/17951#issuecomment-775237363,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AJEZMENYSTT33IDOUBC4NBLS6AAXVANCNFSM4ULTIEFA
.we were failing to get thread id, but we can create chat client.
What do you mean by connection userid?
Did you assign the chat scope to the token?
@skunchakuri , for your user access token what is the scope you are setting ? Be sure to set the scope to "chat"