slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://slack.dev/java-slack-sdk/
MIT License
571 stars 212 forks source link

Add Jakarta EE compatible Socket Mode client ref: #919 #1352

Closed seratch closed 3 weeks ago

seratch commented 3 weeks ago

This pull request adds two new optional modules:

The currently available Socket Mode client's default implementation uses tyrus-standalone-client 1.x, which is compatible with javax.websocket-api APIs. The Jakarta EE version of this interface is the jakarta.websocket-client-api APIs, and tyrus-standalone-client 2.x is compatible with it. Since it's not feasible to have both tyrus-standalone-client 1.x and 2.x in the same module's dependencies, I have added a new module named slack-jakarta-socket-mode-client. See https://github.com/slackapi/java-slack-sdk/issues/919 for more details.

Developers can initialize the Jakarta-compatible SocketModeClient this way:

import com.slack.api.Slack;
import com.slack.api.jakarta_socket_mode.JakartaSocketModeClientFactory;

public class Example {
  public static void main(String[] args) throws Exception {
    var appToken = System.getenv("SLACK_APP_TOKEN");
    var slack = Slack.getInstance();
    // Java EE compatible Socket Mode client
    slack.socketMode(appToken).connect();
    // Jakarta EE compatible Socket Mode client
    JakartaSocketModeClientFactory.create(slack, appToken).connect();
  }
}

In the same way, I’ve added a new Jakarta-compatible module, which is equivalent to bolt-socket-mode. Here is the demo code. As you can see, just replace the dependency and imports in the code:

import com.slack.api.bolt.App;
import com.slack.api.bolt.jakarta_socket_mode.SocketModeApp;

public class Example {
  public static void main(String[] args) throws Exception {
    var app = new App();
    app.command("/hi", (req, ctx) -> {
      ctx.say("Hi there!");
      return ctx.ack();
    });
    var appToken = System.getenv("SLACK_APP_TOKEN");
    // Switch from com.slack.api.bolt.socket_mode to com.slack.api.bolt.jakarta_socket_mode
    new SocketModeApp(appToken, app).start();
  }
}

The reason behind this enhancement is that many Java-focused companies are planning to eliminate the legacy javax.* dependencies from their project settings. I don't think the short-term risk of having a javax.websocket dependency is significant, but it seems it's about time to provide an option for migration on the developers' side.

Category (place an x in each of the [ ])

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you agree to those rules.

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 68.43854% with 95 lines in your changes missing coverage. Please review.

Project coverage is 74.82%. Comparing base (e542f29) to head (a76768d). Report is 1 commits behind head on main.

Files Patch % Lines
...et_mode/impl/JakartaSocketModeClientTyrusImpl.java 71.09% 39 Missing and 11 partials :warning:
...ck/api/bolt/jakarta_socket_mode/SocketModeApp.java 62.50% 28 Missing and 5 partials :warning:
...ta_socket_mode/JakartaSocketModeClientFactory.java 25.00% 11 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1352 +/- ## ============================================ - Coverage 74.99% 74.82% -0.18% - Complexity 4203 4274 +71 ============================================ Files 453 457 +4 Lines 12975 13276 +301 Branches 1342 1369 +27 ============================================ + Hits 9731 9934 +203 - Misses 2462 2544 +82 - Partials 782 798 +16 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.