-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7247: Alternate for Twitter4J to support twitter plug-in #323
Conversation
👋 Welcome back schaturvedi! A progress list of the required criteria for merging this PR into |
Webrevs
|
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. But when I set up Twitter as an action, nothing happens when the trigger criteria is met. (EDIT: the screenshot below makes it look like I'm using an incorrect username, but the underscore is getting hidden by the bottom of the textbox, the text really is "aptmac_" even though it looks like it's missing the underscore) 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
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. I'll start poking around the code soon, but for the time being I wasn't able to send Tweets.
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.
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. |
Yeah, my Twitter username is "aptmac_", and the app authenticated okay with JMC. |
But the update status screenshot doesn't show underscore at the end. Also, the screenshot shared is of Update Status and the logs which you shared is of Send Direct Message flow. The update status flow will need only one username which should be "aptmac_" in your case and for send direct message there should be two usernames. From should be "aptmac_" and to should be some other valid user name. I have tested by giving my username in both from and to. |
I typed it in there, but the underscore gets hidden by the bottom of the textbox, the screenshot is a bit misleading but the text in there is "aptmac_"
Yeah, I tried both ways, but the exception was thrown when I first tried to Direct Message, and there I was trying to send a DM from myself to myself (I can in the Twitter UI, so thought maybe I could do the same here). Then I went to try to broadcast a message there wasn't anything happening. |
Ok I understood the issue. Even I am not able to send message from my twitter to yours. I will fix the issue and raise it for review again. |
Nice! It's working much better now, I verified the status and messaging functionality: Something I did notice is that it would be nice if an error dialog could show up in the event that a Tweet cannot be sent. For example, I set up my keys and account but had my Twitter application defaulted to read-only. JMC was rightfully getting a 401 trying to POST, but there wasn't indication of anything not working in the JMC ui, so it took me a bit of time to debug. I also found out that it's not enough to just set the Twitter application settings to write+message, I had to re-attach my keys in JMC before it was able to send a 200 response properly. |
...openjdk.jmc.console.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterPlugin.java
Outdated
Show resolved
Hide resolved
...openjdk.jmc.console.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterPlugin.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good! I added a couple comments mentioning that it'd be nice to include the error code along with the dialog.
Also, there are quite a few strings that could be externalized, it would be nice to pull them into a Messages class
HttpResponse<String> response = getHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); | ||
if (response.statusCode() != 200) { | ||
JOptionPane.showMessageDialog(null, | ||
" Some error occured while sending direct message. Please verify your twitter app settings. "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are trailing spaces at the beginning and end of this string. It would also be nice to have the error status included with this string, so the user has a better idea of where an issue might have happened if it occurs. The string in the dialog might be something like:
"An error occured while __________. Please verify your Twitter app settings. (Error code: XXX)"
HttpResponse<String> response = getHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); | ||
if (response.statusCode() != 200) { | ||
JOptionPane.showMessageDialog(null, | ||
" Some error occured while updating Twitter status. Please verify your twitter app settings. "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the string usage below, it'd be nice to include the error code along with this message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated error message looks great, thanks.
I've commented on a handful of lines that could also be externalized.
|
||
return oauth_token; | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, "Unable to get request token", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
|
||
return accessToken; | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, "Unable to authenticate.", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
} | ||
} catch (URISyntaxException e) { | ||
// Should never happen... | ||
LOGGER.log(Level.SEVERE, "Failed to parse URI", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
SecretKey secretKey = null; | ||
|
||
byte[] keyBytes = keyString.getBytes(); | ||
secretKey = new SecretKeySpec(keyBytes, "HmacSHA1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the "HmacSHA1" could be a global variable instead of a quoted string here (as it's used again below)?
mac = Mac.getInstance(HMAC_SHA1); | ||
mac.init(key); | ||
} catch (NoSuchAlgorithmException | InvalidKeyException e) { | ||
LOGGER.log(Level.SEVERE, "Failed to encrypt.", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
try { | ||
encoded = Encode.forUriComponent(value); | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, "Failed to encode the URL.", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
} | ||
} catch (URISyntaxException e) { | ||
// Should never happen... | ||
LOGGER.log(Level.SEVERE, "Failed to parse URI", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
} | ||
storeAndSavePrefs(); | ||
} else { | ||
DialogToolkit.showError(null, "Invalid User", "The authorized user is invalid."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string could be placed in Messages.java
@Suchitainf This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 12 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Since we are removing the dependency on Twitter4J, we should also remove it from https://github.com/openjdk/jmc/blob/master/license/THIRDPARTYREADME.txt#L265. |
...onsole.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterOAuthAunthenticator.java
Outdated
Show resolved
Hide resolved
...onsole.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterOAuthAunthenticator.java
Outdated
Show resolved
Hide resolved
...onsole.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterOAuthAunthenticator.java
Outdated
Show resolved
Hide resolved
...onsole.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterOAuthAunthenticator.java
Outdated
Show resolved
Hide resolved
...nsole.twitter/src/main/java/org/openjdk/jmc/console/twitter/TwitterOAuthHeaderGenerator.java
Outdated
Show resolved
Hide resolved
/reviewers 2 |
@thegreystone |
/integrate |
Going to push as commit 4d1c087.
Your commit was automatically rebased without conflicts. |
@Suchitainf Pushed as commit 4d1c087. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
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).
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.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jmc pull/323/head:pull/323
$ git checkout pull/323
Update a local copy of the PR:
$ git checkout pull/323
$ git pull https://git.openjdk.java.net/jmc pull/323/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 323
View PR using the GUI difftool:
$ git pr show -t 323
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jmc/pull/323.diff