rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

Setting webhook behind SOCKS5 proxy causes error. #557

Open krivochenko opened 5 years ago

krivochenko commented 5 years ago

Hi, everyone!

If I launch webhook-bot behind SOCKS5-proxy, I get following error:

Exception in thread "main" java.lang.NullPointerException
  at org.telegram.telegrambots.facilities.proxysocketfactorys.SocksSSLConnectionSocketFactory.createSocket(SocksSSLConnectionSocketFactory.java:25)
  at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:119)
  at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
  at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
  at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
  at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
  at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
  at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
  at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
  at org.telegram.telegrambots.util.WebhookUtils.setWebhook(WebhookUtils.java:56)
  at org.telegram.telegrambots.bots.TelegramWebhookBot.setWebhook(TelegramWebhookBot.java:26)
  at org.telegram.telegrambots.meta.TelegramBotsApi.registerBot(TelegramBotsApi.java:136)
  at ru.krivochenko.Main.main(Main.java:40)

I guess it happens because WebhookUtils executes request without passing httpContext:

CloseableHttpResponse response = httpclient.execute(httppost);

So new context is created without properties socketAddress and socksVersion.

P.S. If I set webhook manually by third-party http-client, bot receives updates and can answer on it.

rubenlagus commented 5 years ago

Fixed with https://github.com/rubenlagus/TelegramBots/commit/293d903083bd74894e2a255214e83159071a1dd0