Commit 682d965e8ec1c9b582c13e136e4d350e8496397e

Authored by mp-96409975520
1 parent b89db02e
Exists in master

Correção do método de conexão e encoder das Url's

src/main/java/br/com/checker/emag/core/ContentEvaluation.java
@@ -509,10 +509,10 @@ public class ContentEvaluation extends Evaluation { @@ -509,10 +509,10 @@ public class ContentEvaluation extends Evaluation {
509 * "Jakarta Commons-HttpClient/3.1"); 509 * "Jakarta Commons-HttpClient/3.1");
510 * metodoRequisicaoGET.setFollowRedirects(true); 510 * metodoRequisicaoGET.setFollowRedirects(true);
511 */ 511 */
512 -  
513 - codResponse = verificarConexao(href, "user-agent","NewUseAgent/1.0"); 512 +
  513 + codResponse = verificarConexao(href, "http.agent", "Jakarta Commons-HttpClient/3.1");
514 if (codResponse != 200) { 514 if (codResponse != 200) {
515 - codResponse = verificarConexao(href, "http.agent", "Jakarta Commons-HttpClient/3.1"); 515 + codResponse = verificarConexao(href, "user-agent","NewUseAgent/1.0");
516 if (codResponse == -1) { 516 if (codResponse == -1) {
517 return "aviso"; 517 return "aviso";
518 } 518 }
@@ -557,6 +557,8 @@ public class ContentEvaluation extends Evaluation { @@ -557,6 +557,8 @@ public class ContentEvaluation extends Evaluation {
557 HttpMethod metodoRequisicaoGET = null; 557 HttpMethod metodoRequisicaoGET = null;
558 HttpClient clienteHTTPJakartaCommons; 558 HttpClient clienteHTTPJakartaCommons;
559 URL UrlConvertida; 559 URL UrlConvertida;
  560 + int codResponse = -1;
  561 +
560 try { 562 try {
561 563
562 String[] test = href.split("\\../"); 564 String[] test = href.split("\\../");
@@ -580,9 +582,9 @@ public class ContentEvaluation extends Evaluation { @@ -580,9 +582,9 @@ public class ContentEvaluation extends Evaluation {
580 // "UTF-8")); 582 // "UTF-8"));
581 583
582 metodoRequisicaoGET.setRequestHeader(usuario, agente); 584 metodoRequisicaoGET.setRequestHeader(usuario, agente);
583 - metodoRequisicaoGET.setFollowRedirects(true); 585 + //metodoRequisicaoGET.setFollowRedirects(true);
584 586
585 - return clienteHTTPJakartaCommons.executeMethod(metodoRequisicaoGET); 587 + codResponse = clienteHTTPJakartaCommons.executeMethod(metodoRequisicaoGET);
586 588
587 } catch (MalformedURLException e) { 589 } catch (MalformedURLException e) {
588 e.printStackTrace(); 590 e.printStackTrace();
@@ -603,6 +605,7 @@ public class ContentEvaluation extends Evaluation { @@ -603,6 +605,7 @@ public class ContentEvaluation extends Evaluation {
603 } 605 }
604 606
605 } 607 }
  608 + return codResponse;
606 609
607 } 610 }
608 611
src/main/java/br/com/checker/emag/core/MarkEvaluation.java
1 package br.com.checker.emag.core; 1 package br.com.checker.emag.core;
2 2
3 3
  4 +import java.net.URL;
  5 +import java.net.URLEncoder;
4 import java.util.ArrayList; 6 import java.util.ArrayList;
5 import java.util.Arrays; 7 import java.util.Arrays;
6 import java.util.Collections; 8 import java.util.Collections;
@@ -14,10 +16,6 @@ import net.htmlparser.jericho.Element; @@ -14,10 +16,6 @@ import net.htmlparser.jericho.Element;
14 import net.htmlparser.jericho.Source; 16 import net.htmlparser.jericho.Source;
15 17
16 import org.apache.commons.lang3.StringUtils; 18 import org.apache.commons.lang3.StringUtils;
17 -import org.w3c.dom.Document;  
18 -  
19 -  
20 -  
21 19
22 import br.com.checker.emag.Occurrence; 20 import br.com.checker.emag.Occurrence;
23 import br.com.checker.emag.OccurrenceClassification; 21 import br.com.checker.emag.OccurrenceClassification;
@@ -39,6 +37,7 @@ public class MarkEvaluation extends Evaluation { @@ -39,6 +37,7 @@ public class MarkEvaluation extends Evaluation {
39 } 37 }
40 38
41 private MarkEvaluation(Source document, String url) { 39 private MarkEvaluation(Source document, String url) {
  40 +
42 super(document, url); 41 super(document, url);
43 } 42 }
44 43
@@ -164,15 +163,15 @@ public class MarkEvaluation extends Evaluation { @@ -164,15 +163,15 @@ public class MarkEvaluation extends Evaluation {
164 163
165 String url = getUrl(); 164 String url = getUrl();
166 if (url != null) { 165 if (url != null) {
167 - 166 +
168 int[] errosWarningsCss = getErrorCount(true, url); 167 int[] errosWarningsCss = getErrorCount(true, url);
169 int[] errosWarningsHtml = getErrorCount(false, url); 168 int[] errosWarningsHtml = getErrorCount(false, url);
170 int avisoHtml = 0; 169 int avisoHtml = 0;
171 int errosHtml = 0; 170 int errosHtml = 0;
172 int avisoCss = 0; 171 int avisoCss = 0;
173 int errosCss = 0; 172 int errosCss = 0;
174 -  
175 - 173 +
  174 +
176 avisoHtml = errosWarningsHtml[1]; 175 avisoHtml = errosWarningsHtml[1];
177 176
178 if (avisoHtml > 0) 177 if (avisoHtml > 0)
@@ -1057,13 +1056,21 @@ public class MarkEvaluation extends Evaluation { @@ -1057,13 +1056,21 @@ public class MarkEvaluation extends Evaluation {
1057 OccurrenceClassification.MARK, criterio); 1056 OccurrenceClassification.MARK, criterio);
1058 } 1057 }
1059 1058
  1059 +
  1060 +
1060 public int[] getErrorCount(boolean isCss, String url) { 1061 public int[] getErrorCount(boolean isCss, String url) {
1061 int errors = 0; 1062 int errors = 0;
1062 int warnings = 0; 1063 int warnings = 0;
  1064 + URL UrlConvertida;
  1065 +
1063 1066
1064 try { 1067 try {
  1068 + UrlConvertida = new URL(url);
  1069 +
  1070 +
1065 if (isCss) { 1071 if (isCss) {
1066 - String content = WebAgent.from(CSS_VALIDATOR_URL.replace("#{url}", url)).withGetRequest().execute().getContent(); 1072 +
  1073 + String content = WebAgent.from(CSS_VALIDATOR_URL.replace("#{url}", URLEncoder.encode(UrlConvertida.toExternalForm(), "UTF-8"))).withGetRequest().execute().getContent();
1067 1074
1068 Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>",Pattern.MULTILINE).matcher(content); 1075 Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>",Pattern.MULTILINE).matcher(content);
1069 if (m.find()) 1076 if (m.find())
@@ -1076,7 +1083,7 @@ public class MarkEvaluation extends Evaluation { @@ -1076,7 +1083,7 @@ public class MarkEvaluation extends Evaluation {
1076 1083
1077 } else { 1084 } else {
1078 1085
1079 - String content = WebAgent.from(HTML_VALIDATOR_URL.replace("#{url}", url)).withGetRequest().execute().getContent(); 1086 + String content = WebAgent.from(HTML_VALIDATOR_URL.replace("#{url}", URLEncoder.encode(UrlConvertida.toExternalForm(), "UTF-8"))).withGetRequest().execute().getContent();
1080 Gson g = new GsonBuilder().create(); 1087 Gson g = new GsonBuilder().create();
1081 HtmlValidation a = g.fromJson(content, HtmlValidation.class); 1088 HtmlValidation a = g.fromJson(content, HtmlValidation.class);
1082 int[] errorsWarnings = a.getQtdWarningsErros(); 1089 int[] errorsWarnings = a.getQtdWarningsErros();