diff --git a/utils/src/main/java/ru/trader/edce/EDSession.java b/utils/src/main/java/ru/trader/edce/EDSession.java index fa9d581..36b46f1 100644 --- a/utils/src/main/java/ru/trader/edce/EDSession.java +++ b/utils/src/main/java/ru/trader/edce/EDSession.java @@ -1,16 +1,14 @@ package ru.trader.edce; import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.CookieStore; import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.RequestBuilder; import org.apache.http.cookie.Cookie; -import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.client.LaxRedirectStrategy; +import org.apache.http.impl.client.*; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,18 +35,29 @@ public class EDSession { private ED_SESSION_STATUS lastStatus; public EDSession() throws IOException, ClassNotFoundException { - this.lastStatus = ED_SESSION_STATUS.LOGIN_REQUIRED; - initClient(); + this(null); } - private void initClient() throws IOException, ClassNotFoundException { + public EDSession(String proxyServer, int port) throws IOException, ClassNotFoundException { + this(new HttpHost(proxyServer,port)); + } + + public EDSession(HttpHost proxy) throws IOException, ClassNotFoundException { + this.lastStatus = ED_SESSION_STATUS.LOGIN_REQUIRED; + initClient(proxy); + } + + private void initClient(HttpHost proxy) throws IOException, ClassNotFoundException { cookieStore = readCookieStore(); checkCookie(); - httpClient = HttpClients.custom() + HttpClientBuilder builder = HttpClients.custom() .setDefaultCookieStore(cookieStore) .setUserAgent(USER_AGENT) - .setRedirectStrategy(new LaxRedirectStrategy()) - .build(); + .setRedirectStrategy(new LaxRedirectStrategy()); + if (proxy != null){ + builder.setProxy(proxy); + } + httpClient = builder.build(); } public void login(String login, String password){ diff --git a/utils/src/test/java/ru/trader/edce/EDSessionDemo.java b/utils/src/test/java/ru/trader/edce/EDSessionDemo.java index 8ba5e0d..ecf1c82 100644 --- a/utils/src/test/java/ru/trader/edce/EDSessionDemo.java +++ b/utils/src/test/java/ru/trader/edce/EDSessionDemo.java @@ -22,7 +22,8 @@ public class EDSessionDemo { public static void main(String args[]) throws Exception { LOG.info("Test ED Companion connect"); - EDSession edSession = new EDSession(); + EDSession edSession = new EDSession("192.168.32.90",3128); + //EDSession edSession = new EDSession(); if (edSession.getLastStatus() == ED_SESSION_STATUS.OK){ LOG.info("Check get profile"); edSession.readProfile(s ->{});