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 ...@@ -34,10 +34,8 @@ public class AuthenticationFailureEventListener implements ApplicationListener<A
if (user != null) { if (user != null) {
UserAttemptsLogin userAttempts = userAttemptsLoginRepository.findById(username).orElse(null); UserAttemptsLogin userAttempts = userAttemptsLoginRepository.findById(username).orElse(null);
if (userAttempts != null) { if (userAttempts != null) {
log.error(userAttempts.getAttempts() + "!!!");
if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) { if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) {
int fails = userAttempts.getAttempts(); int fails = userAttempts.getAttempts();
log.error("faile" + fails);
if (fails < 20) if (fails < 20)
saveUserAttemptsLogin(username, fails + 1); saveUserAttemptsLogin(username, fails + 1);
else else
......
...@@ -295,6 +295,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -295,6 +295,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResource.setProxyUsername(ipResource.getAddr()); ipResource.setProxyUsername(ipResource.getAddr());
ipResource.setProxyPassword(genRandom(3, 12)); ipResource.setProxyPassword(genRandom(3, 12));
ipResource.setSpecialLine(true); ipResource.setSpecialLine(true);
ipResource.setHealthLockTimestamp(Instant.now().minusSeconds(60*20).toEpochMilli());
} }
ipResource.setRegionCn(ipResourceRequestDto.getRegionCn()); ipResource.setRegionCn(ipResourceRequestDto.getRegionCn());
ipResource.setProtocol(protocol); ipResource.setProtocol(protocol);
......
...@@ -229,7 +229,7 @@ public class BrowserTask { ...@@ -229,7 +229,7 @@ public class BrowserTask {
QueryIpUrlList queryIpUrlList = queryIpUrlListRepository.findAll().get(0); QueryIpUrlList queryIpUrlList = queryIpUrlListRepository.findAll().get(0);
if (ipResource.isSpecialLine()) { if (ipResource.isSpecialLine()) {
Trans trans = new Trans(ipResource.getProxyUsername(), ipResource.getProxyPassword()); 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; int failTime = 0;
while (!sp_result.contains(ipResource.getAddr())) { while (!sp_result.contains(ipResource.getAddr())) {
if (failTime > 5) { if (failTime > 5) {
...@@ -239,12 +239,12 @@ public class BrowserTask { ...@@ -239,12 +239,12 @@ public class BrowserTask {
} }
failTime ++; failTime ++;
Thread.sleep(2000); Thread.sleep(2000);
sp_result = trans.get(queryIpUrlList.getUrl(), true); sp_result = trans.get(queryIpUrlList.getUrl());
} }
} }
String result; 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()); 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())) { if (!result.contains(ipResource.getAddr())) {
int failTime = 0; int failTime = 0;
while (!result.contains(ipResource.getAddr())) { while (!result.contains(ipResource.getAddr())) {
...@@ -255,7 +255,7 @@ public class BrowserTask { ...@@ -255,7 +255,7 @@ public class BrowserTask {
} }
failTime ++; failTime ++;
Thread.sleep(2000); Thread.sleep(2000);
result = trans.get(queryIpUrlList.getUrl(), true); result = trans.get(queryIpUrlList.getUrl());
} }
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -62,9 +62,9 @@ public class NotifyUtils { ...@@ -62,9 +62,9 @@ public class NotifyUtils {
} catch (Exception e) { } catch (Exception e) {
} }
if (!StringUtils.isEmpty(env) && !env.equalsIgnoreCase("prod")) { // if (!StringUtils.isEmpty(env) && !env.equalsIgnoreCase("prod")) {
return; // return;
} // }
String envPrefix = "执行环境: " + env + "\n"; String envPrefix = "执行环境: " + env + "\n";
text.put("content", envPrefix + message.getContent()); text.put("content", envPrefix + message.getContent());
json.put("text", text); json.put("text", text);
......
...@@ -6,10 +6,12 @@ import org.apache.http.HttpResponse; ...@@ -6,10 +6,12 @@ import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRouteParams; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -48,28 +50,32 @@ public class Trans { ...@@ -48,28 +50,32 @@ public class Trans {
public static void main(String[] args) { public static void main(String[] args) {
String url = "http://pv.sohu.com/cityjson"; String url = "http://pv.sohu.com/cityjson";
Trans trans = new Trans("120.76.135.212", 20001, "fangguanlianbrowser", "2rbvtg9GQ1JraA1"); 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方法的请求 * 向指定URL发送GET方法的请求
*/ */
public String get(String url, boolean special) { public String get(String url) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
//创建HttpClient实例 HttpHost proxy = new HttpHost(host,port);
HttpClient client = this.getHttpClient(); // 设置认证
//创建httpGet CredentialsProvider provider = new BasicCredentialsProvider();
HttpGet httpGet = new HttpGet("http://pv.sohu.com/cityjson");
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 { try {
HttpResponse response = client.execute(httpGet); HttpResponse response = client.execute(httpGet);
...@@ -87,7 +93,7 @@ public class Trans { ...@@ -87,7 +93,7 @@ public class Trans {
} }
br.close(); br.close();
} }
return sb.toString();
} catch (ClientProtocolException e) { } catch (ClientProtocolException e) {
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK); NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
...@@ -96,7 +102,10 @@ public class Trans { ...@@ -96,7 +102,10 @@ public class Trans {
NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK); NotifyUtils.sendMessage("防关联浏览器 ip " + host + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
return ""; 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