gerwinb500 Posted January 29, 2021 Share Posted January 29, 2021 Currently I'm working on a script that supports communication trough Pusher (websockets). For this I use the Pusher-websocket-java library. I've been trying to get some code working that connects to Pusher and subscribes to a Presence channel. Connecting to Pusher is no problem at all, but when I try to subscribe to the prescence channel I receive an error. After some trial and error, I decided to try and debug the script with intellij as explained here. This is how I found out that the code works whenever I start the OsBot client from intellij. I believe it has something to do with the this: Based on this I think the problem is that the Pusher library is not build the right way. But I don't get any missing library errors, and connecting to Pusher does work which uses the same library.... I added the Pusher library to the output root. I think this is the right way to use external libraries in OsBot? In short: The Pusher library only works whenever I use the debugger. Any suggestions on how to fix this? Quote Link to comment Share on other sites More sharing options...
Jarl Posted January 29, 2021 Share Posted January 29, 2021 Interestingly you mention an error many times but you don't show us what the error is... I think it's possible your problem is that your artifact does not have the dependencies in it. For example, if you're using maven for your pusher dependencies, you can't just build your artifact and expect the dependencies to come with it. You might need to configure maven to build an artifact with the dependencies. But then again, you need to show us your errors. Quote Link to comment Share on other sites More sharing options...
gerwinb500 Posted January 29, 2021 Author Share Posted January 29, 2021 Thank you for your reaction. You are right, I should've put the error in. Here it is: Authentication failure due to [Unable to parse response from Authorizer: {"auth":"315578f9acfb71d039d6:f0487dc4d6e28bfed9a556366afb2ff8ef660dc36de5864f6a426f696a028406","channel_data":"{\"user_id\":5,\"user_info\":{\"id\":5,\"name\":\"name\",\"email\":\"name@name.com\",\"type\":\"bot\",\"botpass\":\"pass\",\"server\":1,\"is_mule\":0,\"stage\":\"readybot\",\"is_online\":0,\"email_verified_at\":null,\"api_token\":\"{the correct api token}\",\"created_at\":\"2021-01-28T17:14:00.000000Z\",\"updated_at\":\"2021-01-28T17:14:00.000000Z\"}}"}], exception was [com.pusher.client.AuthorizationFailureException: Unable to parse response from Authorizer: {"auth":"315578f9acfb71d039d6:f0487dc4d6e28bfed9a556366afb2ff8ef660dc36de5864f6a426f696a028406","channel_data":"{\"user_id\":5,\"user_info\":{\"id\":5,\"name\":\"name\",\"email\":\"name@name.com\",\"type\":\"bot\",\"botpass\":\"pass\",\"server\":1,\"is_mule\":0,\"stage\":\"readybot\",\"is_online\":0,\"email_verified_at\":null,\"api_token\":\"{the correct api token}\",\"created_at\":\"2021-01-28T17:14:00.000000Z\",\"updated_at\":\"2021-01-28T17:14:00.000000Z\"}}"}] As you can see my local http server, which handles the authorization, responses with correct message. Only the message cannot be parsed for some reason. The Pusher-websocket-java library I downloaded comes with it's dependencies. I got it from here. Also I checked if the dependencies for the library it self where there, and they where. It contains both the GSON and Websocket dependency. I also tried to download and use the Pusher-websocket-java library without the dependencies, and added the dependencies manually, but I still got the same error. My artifacts tab looks tike this: I extracted the Pusher-websocket-java, and some other libraries, into the output root. Am I missing something? Quote Link to comment Share on other sites More sharing options...
Nbacon Posted January 30, 2021 Share Posted January 30, 2021 Does Authentication work when you run it out side, solo[by it self]? I was have problems with google Sheets API and clojue and might have the fix. 1 Quote Link to comment Share on other sites More sharing options...
Jarl Posted January 30, 2021 Share Posted January 30, 2021 7 hours ago, gerwinb500 said: Am I missing something? So, I've never used pusher but I did some quick googling. This could have happened due to two reasons: 1. Your json is not parsed as string 2. Someone mentioned having problems with async calls (unlikely to be the problem) Or maybe there's some other reason that I didn't find with my quick googling. Anyway, try logging the response/type of the response. Maybe for some reason your response is a null. Or maybe for some reason the gson library did not work. Just some quick troubleshooting. If this doesn't help, you're gonna have to wait for someone from here who has experience or ask on github. 1 Quote Link to comment Share on other sites More sharing options...
gerwinb500 Posted January 30, 2021 Author Share Posted January 30, 2021 Thank you both for your reaction. @Nbacon Yes, the authentication works when I run it outside of OsBot. Also, the authentication works in OsBot when running OsBot in debug mode as I mentioned above. Maybe I could try your possible fix if you still think it can help? @Jarl I probably should've mentioned this before, but the code has exited before it even makes a subscribe request to Pusher. If I check in the Pusher debug console, I can see the client has connected. But I don't see any subscription request/failure in the debug console or the error logs. So the script throws an exception before it even sends a subscribe request to Pusher. If the problems was one of those you mentioned, I probably should've seen it in the Pusher debug consolse/error logs. I think the problem has something to do with the GSON library. In the error below (also mentioned above) you can see that the server responded correctly. Otherwise the channel_data would not match the correct values. Authentication failure due to [Unable to parse response from Authorizer: {"auth":"315578f9acfb71d039d6:f0487dc4d6e28bfed9a556366afb2ff8ef660dc36de5864f6a426f696a028406","channel_data":"{\"user_id\":5,\"user_info\":{\"id\":5,\"name\":\"name\",\"email\":\"name@name.com\",\"type\":\"bot\",\"botpass\":\"pass\",\"server\":1,\"is_mule\":0,\"stage\":\"readybot\",\"is_online\":0,\"email_verified_at\":null,\"api_token\":\"{the correct api token}\",\"created_at\":\"2021-01-28T17:14:00.000000Z\",\"updated_at\":\"2021-01-28T17:14:00.000000Z\"}}"}], exception was [com.pusher.client.AuthorizationFailureException: Unable to parse response from Authorizer: {"auth":"315578f9acfb71d039d6:f0487dc4d6e28bfed9a556366afb2ff8ef660dc36de5864f6a426f696a028406","channel_data":"{\"user_id\":5,\"user_info\":{\"id\":5,\"name\":\"name\",\"email\":\"name@name.com\",\"type\":\"bot\",\"botpass\":\"pass\",\"server\":1,\"is_mule\":0,\"stage\":\"readybot\",\"is_online\":0,\"email_verified_at\":null,\"api_token\":\"{the correct api token}\",\"created_at\":\"2021-01-28T17:14:00.000000Z\",\"updated_at\":\"2021-01-28T17:14:00.000000Z\"}}"}] Logging the response from pusher is not possible because the code throws an exception before sending a subscribe request. Maybe someone can explain what the difference is between starting OsBot from intellij like I mentioned above, and starting OsBot the normal way? Quote Link to comment Share on other sites More sharing options...
Jarl Posted January 30, 2021 Share Posted January 30, 2021 2 hours ago, gerwinb500 said: Maybe someone can explain what the difference is between starting OsBot from intellij like I mentioned above, and starting OsBot the normal way? Maybe the permissions you get are different? Quote Link to comment Share on other sites More sharing options...
gerwinb500 Posted January 30, 2021 Author Share Posted January 30, 2021 46 minutes ago, Jarl said: Maybe the permissions you get are different? It seems that you are right. When I try to connect to a public channel where no authorization is required, I get the following exception: java.security.AccessControlException: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks") at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at org.osbot.LpT7.checkPermission(ns:156) at java.lang.reflect.AccessibleObject.setAccessible(Unknown Source) at com.google.gson.internal.reflect.PreJava9ReflectionAccessor.makeAccessible(PreJava9ReflectionAccessor.java:31) at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:103) at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:85) at com.google.gson.internal.bind.MapTypeAdapterFactory.create(MapTypeAdapterFactory.java:127) at com.google.gson.Gson.getAdapter(Gson.java:458) at com.google.gson.Gson.toJson(Gson.java:696) at com.google.gson.Gson.toJson(Gson.java:683) at com.google.gson.Gson.toJson(Gson.java:638) at com.google.gson.Gson.toJson(Gson.java:618) at com.pusher.client.channel.impl.ChannelImpl.toSubscribeMessage(ChannelImpl.java:132) at com.pusher.client.channel.impl.ChannelManager$1.run(ChannelManager.java:149) at com.pusher.client.util.Factory$1.run(Factory.java:119) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) This exception is thrown when this line of code is executed in the pusher-websocket-java library: GSON.toJson(jsonObject); This is probably also the reason why subscibing to a presence channel doesn't work. It seems that OsBot blocks some functionallity of the GSON library due to secuirity reasons. I don't know why tho. Does anybody know a way to solve this problem? Quote Link to comment Share on other sites More sharing options...
gerwinb500 Posted January 30, 2021 Author Share Posted January 30, 2021 Finaly managed to solve the problem. I needed to allow reflection in the OsBot client. Even tough I now get the following uncaught exception: java.lang.RuntimeException: Unable to invoke no-args constructor for class com.pusher.client.channel.impl.PresenceChannelImpl$Presence. Registering an InstanceCreator with Gson for this type may fix this problem. at com.google.gson.internal.ConstructorConstructor$14.construct(ConstructorConstructor.java:228) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:212) at com.google.gson.Gson.fromJson(Gson.java:927) at com.google.gson.Gson.fromJson(Gson.java:892) at com.google.gson.Gson.fromJson(Gson.java:841) at com.google.gson.Gson.fromJson(Gson.java:813) at com.pusher.client.channel.impl.PresenceChannelImpl.extractPresenceDataFrom(PresenceChannelImpl.java:162) at com.pusher.client.channel.impl.PresenceChannelImpl.handleSubscriptionSuccessfulMessage(PresenceChannelImpl.java:100) at com.pusher.client.channel.impl.PresenceChannelImpl.onMessage(PresenceChannelImpl.java:58) at com.pusher.client.channel.impl.ChannelManager.onMessage(ChannelManager.java:116) at com.pusher.client.connection.websocket.WebSocketConnection.handleEvent(WebSocketConnection.java:177) at com.pusher.client.connection.websocket.WebSocketConnection.access$600(WebSocketConnection.java:27) at com.pusher.client.connection.websocket.WebSocketConnection$6.run(WebSocketConnection.java:261) at com.pusher.client.util.Factory$1.run(Factory.java:119) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.UnsupportedOperationException: Cannot allocate class com.pusher.client.channel.impl.PresenceChannelImpl$Presence at com.google.gson.internal.UnsafeAllocator$4.newInstance(UnsafeAllocator.java:104) at com.google.gson.internal.ConstructorConstructor$14.construct(ConstructorConstructor.java:225) ... 16 more Everything seems to work fine. Would like to fix this tho. Quote Link to comment Share on other sites More sharing options...
Jarl Posted January 30, 2021 Share Posted January 30, 2021 33 minutes ago, gerwinb500 said: Finaly managed to solve the problem. I needed to allow reflection in the OsBot client. I think you may be better off using another library which doesn't use reflection. Also, I think you need to get used to reading the errors or trying to google the errors. Tbh, I had suspected the gson library might have been the problem because a while ago, someone else had problems with gson and osbot not allowing reflection. But anyway, read: java.lang.RuntimeException: Unable to invoke no-args constructor for class com.pusher.client.channel.impl.PresenceChannelImpl$Presence. Registering an InstanceCreator with Gson for this type may fix this problem. Maybe you need to make a no-args constructor. Or maybe something else went wrong but there's no way to tell as I cannot see your code. Quote Link to comment Share on other sites More sharing options...
Medusa Posted January 30, 2021 Share Posted January 30, 2021 Not here to help; Why not just build your own socket server? Using pusher is meh Quote Link to comment Share on other sites More sharing options...
gerwinb500 Posted January 30, 2021 Author Share Posted January 30, 2021 1 hour ago, Jarl said: I think you may be better off using another library which doesn't use reflection. Also, I think you need to get used to reading the errors or trying to google the errors. Tbh, I had suspected the gson library might have been the problem because a while ago, someone else had problems with gson and osbot not allowing reflection. But anyway, read: java.lang.RuntimeException: Unable to invoke no-args constructor for class com.pusher.client.channel.impl.PresenceChannelImpl$Presence. Registering an InstanceCreator with Gson for this type may fix this problem. Maybe you need to make a no-args constructor. Or maybe something else went wrong but there's no way to tell as I cannot see your code. As far as I can tell there are two other java-pusher libraries which both use the GSON library for JSON parsing. So these probably also use reflection. The source code is available on GitHub, so maybe I can do a few adjustments to get rid of the error. I will try your suggestion. Thank you for your help. Quote Link to comment Share on other sites More sharing options...
gerwinb500 Posted January 30, 2021 Author Share Posted January 30, 2021 24 minutes ago, Medusa said: Not here to help; Why not just build your own socket server? Using pusher is meh Pusher takes care of maintaning the connections, authentication etc. If I would use a socket server I would have to implement all this by myself. Quote Link to comment Share on other sites More sharing options...
Jarl Posted January 31, 2021 Share Posted January 31, 2021 9 hours ago, gerwinb500 said: As far as I can tell there are two other java-pusher libraries which both use the GSON library for JSON parsing. So these probably also use reflection. There are other json libraries you can use, it doesn't have to be related to pusher. 9 hours ago, gerwinb500 said: The source code is available on GitHub, so maybe I can do a few adjustments to get rid of the error. I will try your suggestion. No dude, I think you misunderstood. The problem is not with the pusher code. Google gson user guide and look at the instance creator section. Your problem is with how you use gson. Quote Link to comment Share on other sites More sharing options...