Commit 21b9c145 authored by renjie's avatar renjie

Merge branch 'dev-zrj' into 'staging'

Dev zrj

See merge request !93
parents 21eadd88 d4bdb93b
......@@ -34,10 +34,8 @@ public class AuthenticationFailureEventListener implements ApplicationListener<A
if (user != null) {
UserAttemptsLogin userAttempts = userAttemptsLoginRepository.findById(username).orElse(null);
if (userAttempts != null) {
log.error(userAttempts.getAttempts() + "!!!");
if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) {
int fails = userAttempts.getAttempts();
log.error("faile" + fails);
if (fails < 20)
saveUserAttemptsLogin(username, fails + 1);
else
......
......@@ -295,6 +295,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResource.setProxyUsername(ipResource.getAddr());
ipResource.setProxyPassword(genRandom(3, 12));
ipResource.setSpecialLine(true);
ipResource.setHealthLockTimestamp(Instant.now().minusSeconds(60*20).toEpochMilli());
}
ipResource.setRegionCn(ipResourceRequestDto.getRegionCn());
ipResource.setProtocol(protocol);
......
......@@ -229,7 +229,7 @@ public class BrowserTask {
QueryIpUrlList queryIpUrlList = queryIpUrlListRepository.findAll().get(0);
if (ipResource.isSpecialLine()) {
Trans trans = new Trans(ipResource.getProxyUsername(), ipResource.getProxyPassword());
String sp_result = trans.get(queryIpUrlList.getUrl(), true);
String sp_result = trans.get(queryIpUrlList.getUrl());
int failTime = 0;
while (!sp_result.contains(ipResource.getAddr())) {
if (failTime > 5) {
......@@ -239,12 +239,12 @@ public class BrowserTask {
}
failTime ++;
Thread.sleep(2000);
sp_result = trans.get(queryIpUrlList.getUrl(), true);
sp_result = trans.get(queryIpUrlList.getUrl());
}
}
String result;
Trans trans = new Trans(ipResource.getAddr(), Integer.valueOf(ipResource.getPort().size() > 1?ipResource.getPort().get(1):ipResource.getPort().get(0)), ipResource.getUsername(), ipResource.getPassword());
result = trans.get(queryIpUrlList.getUrl(), false);
result = trans.get(queryIpUrlList.getUrl());
if (!result.contains(ipResource.getAddr())) {
int failTime = 0;
while (!result.contains(ipResource.getAddr())) {
......@@ -255,7 +255,7 @@ public class BrowserTask {
}
failTime ++;
Thread.sleep(2000);
result = trans.get(queryIpUrlList.getUrl(), true);
result = trans.get(queryIpUrlList.getUrl());
}
}
} catch (Exception e) {
......
......@@ -62,9 +62,9 @@ public class NotifyUtils {
} catch (Exception e) {
}
if (!StringUtils.isEmpty(env) && !env.equalsIgnoreCase("prod")) {
return;
}
// if (!StringUtils.isEmpty(env) && !env.equalsIgnoreCase("prod")) {
// return;
// }
String envPrefix = "执行环境: " + env + "\n";
text.put("content", envPrefix + message.getContent());
json.put("text", text);
......
......@@ -6,10 +6,12 @@ import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRouteParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -48,28 +50,32 @@ public class Trans {
public static void main(String[] args) {
String url = "http://pv.sohu.com/cityjson";
Trans trans = new Trans("120.76.135.212", 20001, "fangguanlianbrowser", "2rbvtg9GQ1JraA1");
String result = trans.get(url, false);
}
public HttpClient getHttpClient() {
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(host, port),
new UsernamePasswordCredentials(username, password));
HttpHost proxy = new HttpHost(host,port);
httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
return httpClient;
}
/**
* 向指定URL发送GET方法的请求
*/
public String get(String url, boolean special) {
public String get(String url) {
StringBuffer sb = new StringBuffer();
//创建HttpClient实例
HttpClient client = this.getHttpClient();
//创建httpGet
HttpGet httpGet = new HttpGet("http://pv.sohu.com/cityjson");
HttpHost proxy = new HttpHost(host,port);
// 设置认证
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(username, password));
//创建httpClient实例
CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
//创建httpGet实例
HttpGet httpGet = new HttpGet(url);
//设置代理IP,设置连接超时时间 、 设置 请求读取数据的超时时间 、 设置从connect Manager获取Connection超时时间、
RequestConfig requestConfig = RequestConfig.custom()
.setProxy(proxy)
.setConnectTimeout(2000)
.setSocketTimeout(2000)
.setConnectionRequestTimeout(2000)
.build();
httpGet.setConfig(requestConfig);
//执行
try {
HttpResponse response = client.execute(httpGet);
......@@ -87,7 +93,7 @@ public class Trans {
}
br.close();
}
return sb.toString();
} catch (ClientProtocolException e) {
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
logger.error(e.getMessage(), e);
......@@ -96,7 +102,10 @@ public class Trans {
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
logger.error(e.getMessage(), e);
return "";
} finally {
httpGet.releaseConnection();
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理超时", NotifyUtils.MsgType.WEBHOOK);
}
return sb.toString();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment