slackapi / java-slack-sdk

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

slack bolt api proxy connection issue #1080

Closed WorkingAngel closed 1 year ago

WorkingAngel commented 1 year ago

I faced similar issues as this link: https://github.com/slackapi/java-slack-sdk/issues/927

I already setup my proxy server, but it still failed with network unreachable issue. [main] INFO org.eclipse.jetty.util.log - Logging initialized @537ms to org.eclipse.jetty.util.log.Slf4jLog [java.net.SocketException: Network is unreachable (connect failed), java.net.SocketException: Network is unreachable (connect failed)] [main] ERROR com.slack.api.methods.impl.TeamIdCache - Failed to call auth.test API (error: Network is unreachable (connect failed))

here is my snipped code of server start, may I know how can I setup in code to solve this issue?

AppConfig conf = new AppConfig();
conf.setSigningSecret(SLACK_SIGNING_SECRET);
conf.setSingleTeamBotToken(SLACK_BOT_TOKEN);

conf.getSlack().getConfig().setProxyUrl(System.getenv("http_proxy"));

System.out.println(conf.getSlack().getConfig().getProxyUrl());
System.out.println(conf.getSigningSecret());
System.out.println(conf.getSingleTeamBotToken());

App app = new App(conf);

app.command("/hello", (req, ctx) -> {
    return ctx.ack(":wave: Hello!");
});

SlackAppServer server = new SlackAppServer(app, 8888);
server.start(); // http://localhost:3000/slack/events
hello-ashleyintech commented 1 year ago

Hi, @WorkingAngel! 🙌 So sorry to hear you're running into trouble here and thanks for submitting your question!

At first glance, your code mirrors what is suggested in the linked issue you included in your question. Based on the nature of the error, java.net.SocketException: Network is unreachable (connect failed), I wonder if it could be an issue with the proxy URL you are providing. If it is an invalid URL, not pulling from your env variables correctly, or the proxy is not running or responding properly at the time of running the app, I could see the SlackAppServer having difficulty initializing a new server instance using the proxy on the specified port. Because of this, I suggest troubleshooting on the proxy side of things and seeing if you can confirm whether the proxy is running correctly and able to receive requests.

I hope this helps! If you run into any other questions, feel free to provide additional info and I'd be happy to help further.

WorkingAngel commented 1 year ago

Hi, I solved this issue finally. For proxy case, java users need to add JAVA_OPTS for proxy setting.

hello-ashleyintech commented 1 year ago

Thanks for the update, @WorkingAngel! 🎉 Glad to hear you figured it out. I will now close this issue, but if you run into any other issues or have any questions please feel free to submit another issue!