proxy to the separate branch

This commit is contained in:
schors 2016-03-21 13:38:12 +03:00
parent 593bc199a4
commit 5bc595edc6
4 changed files with 0 additions and 98 deletions

View File

@ -15,7 +15,6 @@ import org.apache.http.util.EntityUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.telegram.telegrambots.api.Constants; import org.telegram.telegrambots.api.Constants;
import org.telegram.telegrambots.api.TelegramApiConfiguration;
import org.telegram.telegrambots.api.methods.SetWebhook; import org.telegram.telegrambots.api.methods.SetWebhook;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.bots.TelegramWebhookBot; 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 * @param botToken
@ -150,13 +139,6 @@ public class TelegramBotsApi {
String url = Constants.BASEURL + botToken + "/" + SetWebhook.PATH; String url = Constants.BASEURL + botToken + "/" + SetWebhook.PATH;
HttpPost httppost = new HttpPost(url); 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(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SetWebhook.URL_FIELD, webHookURL); builder.addTextBody(SetWebhook.URL_FIELD, webHookURL);
if (publicCertificatePath != null) { if (publicCertificatePath != null) {

View File

@ -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();
}
}

View File

@ -19,7 +19,6 @@ import org.apache.http.util.EntityUtils;
import org.json.JSONObject; import org.json.JSONObject;
import org.telegram.telegrambots.TelegramApiException; import org.telegram.telegrambots.TelegramApiException;
import org.telegram.telegrambots.api.Constants; import org.telegram.telegrambots.api.Constants;
import org.telegram.telegrambots.api.TelegramApiConfiguration;
import org.telegram.telegrambots.api.methods.*; import org.telegram.telegrambots.api.methods.*;
import org.telegram.telegrambots.api.objects.File; import org.telegram.telegrambots.api.objects.File;
import org.telegram.telegrambots.api.objects.Message; import org.telegram.telegrambots.api.objects.Message;
@ -187,13 +186,6 @@ public abstract class AbsSender {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
String url = getBaseUrl() + SendDocument.PATH; String url = getBaseUrl() + SendDocument.PATH;
HttpPost httppost = new HttpPost(url); 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()) { if (sendDocument.isNewDocument()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId()); builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId());
@ -241,13 +233,6 @@ public abstract class AbsSender {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
String url = getBaseUrl() + SendPhoto.PATH; String url = getBaseUrl() + SendPhoto.PATH;
HttpPost httppost = new HttpPost(url); 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()) { if (sendPhoto.isNewPhoto()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId()); builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId());
@ -301,13 +286,6 @@ public abstract class AbsSender {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
String url = getBaseUrl() + SendVideo.PATH; String url = getBaseUrl() + SendVideo.PATH;
HttpPost httppost = new HttpPost(url); 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()) { if (sendVideo.isNewVideo()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId()); builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId());
@ -368,13 +346,6 @@ public abstract class AbsSender {
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
String url = getBaseUrl() + SendSticker.PATH; String url = getBaseUrl() + SendSticker.PATH;
HttpPost httppost = new HttpPost(url); 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()) { if (sendSticker.isNewSticker()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId()); builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId());
@ -422,12 +393,6 @@ public abstract class AbsSender {
CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
String url = getBaseUrl() + method.getPath(); String url = getBaseUrl() + method.getPath();
HttpPost httppost = new HttpPost(url); 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.addHeader("charset", "UTF-8");
httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
CloseableHttpResponse response = httpclient.execute(httppost); CloseableHttpResponse response = httpclient.execute(httppost);
@ -452,12 +417,6 @@ public abstract class AbsSender {
CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
String url = getBaseUrl() + method.getPath(); String url = getBaseUrl() + method.getPath();
HttpPost httppost = new HttpPost(url); 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.addHeader("charset", "UTF-8");
httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
CloseableHttpResponse response = httpclient.execute(httppost); CloseableHttpResponse response = httpclient.execute(httppost);

View File

@ -16,7 +16,6 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.telegram.telegrambots.api.Constants; import org.telegram.telegrambots.api.Constants;
import org.telegram.telegrambots.api.TelegramApiConfiguration;
import org.telegram.telegrambots.api.methods.GetUpdates; import org.telegram.telegrambots.api.methods.GetUpdates;
import org.telegram.telegrambots.api.objects.Update; import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.ITelegramLongPollingBot; 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(); CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(20, TimeUnit.SECONDS).build();
String url = Constants.BASEURL + token + "/" + GetUpdates.PATH; String url = Constants.BASEURL + token + "/" + GetUpdates.PATH;
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
if (TelegramApiConfiguration.getInstance().getProxy() != null) {
RequestConfig requestConfig = RequestConfig.custom()
.setProxy(TelegramApiConfiguration.getInstance().getProxy())
.build();
httpPost.setConfig(requestConfig);
}
try { try {
httpPost.addHeader("charset", "UTF-8"); httpPost.addHeader("charset", "UTF-8");
httpPost.setEntity(new StringEntity(request.toJson().toString(), ContentType.APPLICATION_JSON)); httpPost.setEntity(new StringEntity(request.toJson().toString(), ContentType.APPLICATION_JSON));