RFR: 7247: Alternate for Twitter4J to support twitter plug-in

Suchita Chaturvedi schaturvedi at openjdk.java.net
Wed Oct 20 20:51:06 UTC 2021


On Wed, 20 Oct 2021 20:38:02 GMT, Alex Macdonald <aptmac at openjdk.org> wrote:

>> This PR addresses the issue of using Twitter4J as third party library for JMC, which is not actively maintained by the owner of Twitter4J. The last release was 3 years back. We have tried contacting the owner for the next release dates but couldn't get a proper response. Hence, we would need to remove the dependency from JMC because we should not use any dependency which is not well maintained. 
>> 
>> JMC Console gives the functionality of setting up triggers for particular conditions which can be set in configuration. Twitter is used as one of the trigger methods to notify users (or tweeters in case of Twitter). I have removed the Twitter4J dependency completely and using all the twitter related APIs directly. There are mainly three parts of this PR (functionality for which Twitter4J was used).
>> 
>> 1. Authentication : The authentication of twitter users i.e. tweeters are done as part of preference settings. Twitter follows 3-legged OAuth authentication process for authenticating any user. So there are 3 steps which I have implemented in order to authenticate any user and save his details in preferences. Once the tweeter is verified the JMC application will use his details for verification before any action is triggered for that user. In order to use any user name we need to authorize his/her credentials in JMC preference.
>> 2. Send Direct Message : A verified user (tweeter) can send a direct message to another user (tweeter). The first user should be verified user i.e. it should be one of the users listed in preference. The second user need not be a part of authorized users list but before sending any message we are checking whether the user exists or not.
>> 3. Update Status : A JMC user can update the status of any verified user (tweeter) on Twitter which can be seen on twitter wall of that user.
>> 
>> I have used http classes of JDK 11 for making REST API calls, so this plugin will be dependent on JDK 11.
>> 
>> There is a scope of using a JSON library to make the code better but as of now I haven't used any third party library for this implementation may be we can modify the code in future if we have some JSON library dependency in future.
>> 
>> Please review the same and let me know your valuable comments (if any). Also, feel free to ping me if you want to test it and stuck somewhere. I can help with the steps to test it.
>
> Neat! I've tried giving this a try, but I've run into a problem when trying to send a tweet. I've set up my Twitter developer account, and managed to add my account into JMC. 
> 
> ![2021-10-20-162136_329x265_scrot](https://user-images.githubusercontent.com/10425301/138166776-34f41741-8189-47e6-9df9-53d1a4182e2e.png)
> 
> But when I set up Twitter as an action, nothing happens when the trigger criteria is met. 
> 
> ![2021-10-20-161950_357x467_scrot](https://user-images.githubusercontent.com/10425301/138166916-d59fa46b-a7ef-40a0-bcc4-b993df000f42.png)
> 
> Looking at the console, there looks to be an exception thrown. I'm assuming that the id number is specific to my account, so I've replaced it with "123456789", but here's the error below. It looks like there's a trailing comma that's causing the parsing of the number to crash. From a quick look at the logs, it looks like the sub-string parsing  in `TwitterPlugin` for the user id is off: https://github.com/openjdk/jmc/pull/323/files#diff-7462129c16153b6d0d6ac4d57c25d5cf1bc58793a688c87552752e3f0866475dR258
> 
> Oct. 20, 2021 4:14:18 P.M. org.openjdk.jmc.rjmx.triggers.internal.DefaultExceptionHandler handleException
> SEVERE: Could not invoke the action for the rule CPU Usage - JVM Process (Too High)
> java.lang.NumberFormatException: For input string: "123456789,"id_str":"
> 	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
> 	at java.base/java.lang.Long.parseLong(Long.java:692)
> 	at java.base/java.lang.Long.valueOf(Long.java:1144)
> 	at org.openjdk.jmc.console.twitter.TwitterPlugin.getUserId(TwitterPlugin.java:259)
> 	at org.openjdk.jmc.console.twitter.TwitterPlugin.sendDirectMessage(TwitterPlugin.java:381)
> 	at org.openjdk.jmc.console.twitter.SendMessage.send(SendMessage.java:64)
> 	at org.openjdk.jmc.console.twitter.SendMessage.handleNotificationEvent(SendMessage.java:59)
> 	at org.openjdk.jmc.rjmx.triggers.internal.NotificationTrigger.doTrigger(NotificationTrigger.java:329)
> 	at org.openjdk.jmc.rjmx.triggers.internal.NotificationTrigger.triggerOn(NotificationTrigger.java:264)
> 	at org.openjdk.jmc.rjmx.triggers.internal.NotificationRuleBag$1.valueChanged(NotificationRuleBag.java:106)
> 	at org.openjdk.jmc.rjmx.subscription.internal.AbstractAttributeSubscription.fireAttributeChange(AbstractAttributeSubscription.java:161)
> 	at org.openjdk.jmc.rjmx.subscription.internal.AbstractAttributeSubscription.storeAndFireEvent(AbstractAttributeSubscription.java:192)
> 	at org.openjdk.jmc.rjmx.subscription.internal.DefaultAttributeSubscriptionThread.dispatchEvents(DefaultAttributeSubscriptionThread.java:440)
> 	at org.openjdk.jmc.rjmx.subscription.internal.DefaultAttributeSubscriptionThread.retrieveAndDispatchNormalAttributes(DefaultAttributeSubscriptionThread.java:159)
> 	at org.openjdk.jmc.rjmx.subscription.internal.DefaultAttributeSubscriptionThread.retrieveAndDispatchValues(DefaultAttributeSubscriptionThread.java:150)
> 	at org.openjdk.jmc.rjmx.subscription.internal.DefaultAttributeSubscriptionThread.run(DefaultAttributeSubscriptionThread.java:117)
> 
> 
> Aside from that, when linking my Twitter account in the JMC preferences, the headers for Consumer Key and Consumer Secret have since been updated on the Twitter side to be "API Key" and "API Key Secret", the JMC preferences page should probably get updated as well.
> 
> ![2021-10-20-160205_664x751_scrot](https://user-images.githubusercontent.com/10425301/138167045-49072abe-00b0-4403-9491-ec951527ecb9.png)
> 
> I'll start poking around the code soon, but for the time being I wasn't able to send Tweets.
> 
>> This PR addresses the issue of using Twitter4J as third party library for JMC, which is not actively maintained by the owner of Twitter4J. The last release was 3 years back. We have tried contacting the owner for the next release dates but couldn't get a proper response. Hence, we would need to remove the dependency from JMC because we should not use any dependency which is not well maintained.
> 
> Out of curiosity, is there a specific time frame that dependencies should be updated for JMC? It looks like Twitter4J had a commit merged earlier this year, but you're right that it hasn't had major functionality updates in the last while. For comparison, the last Twitter4J release was 1,159 days ago, but in terms of dependencies we consume our jaf 1.2.1 is 1,059 days old, our Jemmy 2.0.0 is 867 days old, HdrHistogram 2.1.12 is 680 days old, etc.
> 
>> I have used http classes of JDK 11 for making REST API calls, so this plugin will be dependent on JDK 11.
> 
> That should be okay for now, after the Eclipse platform update last year we need to use JDK 11 as a minimum anyways.

@aptmac Thanks for taking out time for review. Can you please double check whether you have used your correct username while triggering the update status flow? I can see the underscore missing at the end. Please correct me if I am wrong.

-------------

PR: https://git.openjdk.java.net/jmc/pull/323


More information about the jmc-dev mailing list