Commit 4b1ededd authored by shangying's avatar shangying

sonar问题修改12

parent f349304a
......@@ -113,15 +113,18 @@ public class EnvUtil {
Set<Map.Entry<Object, Object>> propertySet = propertys.entrySet();
for (Map.Entry<Object, Object> property : propertySet) {
String propertyKey = property.getKey().toString();
String lowerCase=ciEnv.toLowerCase();
if(StringUtils.isBlank(lowerCase)){
if(StringUtils.isBlank(ciEnv.toLowerCase())){
return env;
}
}else {
String lowerCase=ciEnv.toLowerCase();
if (propertyKey.toLowerCase().contains(String.format("dubbo.%s.%s.",siteName.toLowerCase(),lowerCase))) {
// �������÷���
env = propertyKey.split("\\.")[2];
break;
}
}
}
}else {
return env;
......@@ -141,15 +144,18 @@ public class EnvUtil {
Set<Map.Entry<Object, Object>> propertySet = propertys.entrySet();
for (Map.Entry<Object, Object> property : propertySet) {
String propertyKey = property.getKey().toString();
String lowerCase=ciEnv.toLowerCase();
if(StringUtils.isBlank(lowerCase)){
if(StringUtils.isBlank(ciEnv.toLowerCase())){
return env;
}else {
String lowerCase=ciEnv.toLowerCase();
if (propertyKey.toLowerCase().contains(String.format("http.%s.%s.",siteName.toLowerCase(),lowerCase))) {
// �������÷���,�����ַ�������Сд
env = propertyKey.split("\\.")[2];
break;
}
}
if (propertyKey.toLowerCase().contains(String.format("http.%s.%s.",siteName.toLowerCase(),lowerCase))) {
// �������÷���,�����ַ�������Сд
env = propertyKey.split("\\.")[2];
break;
}
}
}else{
return env;
......
......@@ -138,49 +138,33 @@ public class HttpService {
|| !urlString.startsWith(httpUrl)) {// 如果urlString为null或者urlString为空,或urlString非http开头,返回src空值
return resultEntity;
}
CloseableHttpResponse response = null;
HttpGet httpGet = null;
urlString = urlString.trim();
try {
URL url = new URL(urlString);
//System.out.println(url.getProtocol());
//System.out.println(url.getAuthority());
//System.out.println(url.getPath());
//System.out.println(url.getQuery());
URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(),
url.getQuery(), null);
httpGet = new HttpGet(uri);
System.out.println("请求的uri是:" + uri);
if(headerInfo!=null && !Objects.isNull(httpGet)){
setHttpHeaderInfo(httpGet, headerInfo);
}
CookieStore cookieStore=new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
// 执行请求
try {
try {// 执行请求
if (urlString.startsWith(httpsUrl)) {
System.setProperty("jsse.enableSNIExtension", "false");
if (filePath == null){
response = createSSLClientDefault().execute(httpGet,localContext);
} else{
response = createSSLClient(filePath, pwd).execute(
httpGet,localContext);
}
} else {
response = httpService.getHttpClient().execute(httpGet,localContext);
}
} catch (Exception e) {
// e.printStackTrace();
log.info("异常信息e={}",e);
}
if(Objects.isNull(response)){
......@@ -188,25 +172,23 @@ public class HttpService {
return resultEntity;
}else {
result = doResponse(response, urlString);
resultEntity.setResponseString(result);
resultEntity.setCookies(cookieStore.getCookies());
// 得到响应状态码
if(!Objects.isNull(response.getStatusLine())) {
resultEntity.setStatusCode(response.getStatusLine().getStatusCode());
}else{
return resultEntity;
}
resultEntity.setResponseString(result);
resultEntity.setCookies(cookieStore.getCookies());
}
} catch (MalformedURLException e) {
// e.printStackTrace();
log.info("异常信息e={}",e);
} catch (URISyntaxException e) {
// e.printStackTrace();
log.info("异常信息e={}",e);
}catch (IOException e) {
// e.printStackTrace();
log.info("异常信息e={}",e);
} finally {
......@@ -215,14 +197,12 @@ public class HttpService {
response.close();
httpGet.abort();
} catch (IOException e) {
// e.printStackTrace();
log.info("异常信息e={}",e);
}
}
}
return resultEntity;
}
......@@ -290,12 +270,14 @@ public class HttpService {
return resultEntity;
}else {
result = doResponse(response, url);
resultEntity.setResponseString(result);
resultEntity.setCookies(cookieStore.getCookies());
if(!Objects.isNull(response.getStatusLine()) ) {
resultEntity.setStatusCode(response.getStatusLine().getStatusCode());
}else{
return resultEntity;
}
resultEntity.setResponseString(result);
resultEntity.setCookies(cookieStore.getCookies());
}
} catch (Exception ex) {
// ex.printStackTrace();
......@@ -357,21 +339,27 @@ public class HttpService {
log.info("异常信息e={}", e);
}
result = doResponse(response, url);
if(StringUtils.isNotEmpty(url)&& StringUtils.isNotEmpty(response.toString())){
if(response==null){
resultEntity.setCookies(cookieStore.getCookies());
if(StringUtils.isNotEmpty(url)){
if(StringUtils.isNotEmpty(response.toString())){
log.info("请求超时,最大超时时间:{},url:{}", CommonConstant.HTTPCLIENT_CONNECT_TIMEOUT, url);
return resultEntity;
}
// 得到响应状态码
int statuCode = response.getStatusLine().getStatusCode();
// 根据状态码进行逻辑处理
result=getReslut( statuCode, url, response);
System.out.println(">>>>>>>>>>>>>>>>>>>>>");
System.out.println("打印获取的result: "+result);
if(!Objects.isNull(response.getStatusLine())) {
// 根据状态码进行逻辑处理
int statuCode = response.getStatusLine().getStatusCode();
result=getReslut( statuCode, url, response);
System.out.println("打印获取的result: "+result);
resultEntity.setResponseString(result);
resultEntity.setStatusCode(response.getStatusLine().getStatusCode());
}else{
return resultEntity;
}
}
resultEntity.setResponseString(result);
resultEntity.setCookies(cookieStore.getCookies());
resultEntity.setStatusCode(response.getStatusLine().getStatusCode());
} catch (Exception ex) {
ex.printStackTrace();
}
......@@ -405,7 +393,8 @@ public class HttpService {
}
}
log.info("获取实体的文本buffer:{} ",buffer);
if ( StringUtils.isBlank(charset1) || "zh-cn".equalsIgnoreCase(charset1)) {
String ecodezc="zh-cn";
if ( StringUtils.isBlank(charset1) || ecodezc.equalsIgnoreCase(charset1)) {
System.out.println("charset1的值有问题: "+charset1);
charset1 = getCharsetFromMetaTag(buffer, url);
}else{
......
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