Archived
0

add proxy settings

This commit is contained in:
iMoHax
2015-07-20 10:42:56 +03:00
parent 0ab1490d1c
commit 4c593eb1f0
2 changed files with 21 additions and 11 deletions

View File

@@ -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){

View File

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