From 5bc595edc6c4190f36446635c7421d405b35994b Mon Sep 17 00:00:00 2001 From: schors Date: Mon, 21 Mar 2016 13:38:12 +0300 Subject: [PATCH] proxy to the separate branch --- .../telegrambots/TelegramBotsApi.java | 18 -------- .../api/TelegramApiConfiguration.java | 32 --------------- .../telegram/telegrambots/bots/AbsSender.java | 41 ------------------- .../updatesreceivers/UpdatesThread.java | 7 ---- 4 files changed, 98 deletions(-) delete mode 100644 src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java diff --git a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java index e1b101ce..f9569ec4 100644 --- a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java +++ b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java @@ -15,7 +15,6 @@ import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; import org.telegram.telegrambots.api.Constants; -import org.telegram.telegrambots.api.TelegramApiConfiguration; import org.telegram.telegrambots.api.methods.SetWebhook; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramWebhookBot; @@ -103,16 +102,6 @@ public class TelegramBotsApi { } } - /** - * - * @param host - * @param port - * @param scheme - */ - public void setProxy(String host, int port, String scheme) { - TelegramApiConfiguration.getInstance().setProxy(host, port, scheme); - } - /** * * @param botToken @@ -150,13 +139,6 @@ public class TelegramBotsApi { String url = Constants.BASEURL + botToken + "/" + SetWebhook.PATH; HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } - MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SetWebhook.URL_FIELD, webHookURL); if (publicCertificatePath != null) { diff --git a/src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java b/src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java deleted file mode 100644 index 51ddcd33..00000000 --- a/src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.telegram.telegrambots.api; - -import org.apache.http.HttpHost; - -/** - * Created by Sergey Skoptsov (flicus@gmail.com) on 11.03.2016. - */ - -public class TelegramApiConfiguration { - - private HttpHost proxy = null; - - public static TelegramApiConfiguration getInstance() { - return Singleton.instance; - } - - public HttpHost getProxy() { - return proxy; - } - - public void setProxy(HttpHost proxy) { - this.proxy = proxy; - } - - public void setProxy(String host, int port, String scheme) { - this.proxy = new HttpHost(host, port, scheme); - } - - private static class Singleton { - public static TelegramApiConfiguration instance = new TelegramApiConfiguration(); - } -} diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 55a07947..b6b4c9fc 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -19,7 +19,6 @@ import org.apache.http.util.EntityUtils; import org.json.JSONObject; import org.telegram.telegrambots.TelegramApiException; import org.telegram.telegrambots.api.Constants; -import org.telegram.telegrambots.api.TelegramApiConfiguration; import org.telegram.telegrambots.api.methods.*; import org.telegram.telegrambots.api.objects.File; import org.telegram.telegrambots.api.objects.Message; @@ -187,13 +186,6 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendDocument.PATH; HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } - if (sendDocument.isNewDocument()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId()); @@ -241,13 +233,6 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendPhoto.PATH; HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } - if (sendPhoto.isNewPhoto()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId()); @@ -301,13 +286,6 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendVideo.PATH; HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } - if (sendVideo.isNewVideo()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId()); @@ -368,13 +346,6 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendSticker.PATH; HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } - if (sendSticker.isNewSticker()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId()); @@ -422,12 +393,6 @@ public abstract class AbsSender { CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); String url = getBaseUrl() + method.getPath(); HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } httppost.addHeader("charset", "UTF-8"); httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpclient.execute(httppost); @@ -452,12 +417,6 @@ public abstract class AbsSender { CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); String url = getBaseUrl() + method.getPath(); HttpPost httppost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httppost.setConfig(requestConfig); - } httppost.addHeader("charset", "UTF-8"); httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpclient.execute(httppost); diff --git a/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java b/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java index cd5ef184..f82fdd6c 100644 --- a/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java +++ b/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java @@ -16,7 +16,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.telegram.telegrambots.api.Constants; -import org.telegram.telegrambots.api.TelegramApiConfiguration; import org.telegram.telegrambots.api.methods.GetUpdates; import org.telegram.telegrambots.api.objects.Update; import org.telegram.telegrambots.bots.ITelegramLongPollingBot; @@ -61,12 +60,6 @@ public class UpdatesThread { CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(20, TimeUnit.SECONDS).build(); String url = Constants.BASEURL + token + "/" + GetUpdates.PATH; HttpPost httpPost = new HttpPost(url); - if (TelegramApiConfiguration.getInstance().getProxy() != null) { - RequestConfig requestConfig = RequestConfig.custom() - .setProxy(TelegramApiConfiguration.getInstance().getProxy()) - .build(); - httpPost.setConfig(requestConfig); - } try { httpPost.addHeader("charset", "UTF-8"); httpPost.setEntity(new StringEntity(request.toJson().toString(), ContentType.APPLICATION_JSON));