Commit 682d965e8ec1c9b582c13e136e4d350e8496397e
1 parent
b89db02e
Exists in
master
Correção do método de conexão e encoder das Url's
Showing
2 changed files
with
24 additions
and
14 deletions
Show diff stats
src/main/java/br/com/checker/emag/core/ContentEvaluation.java
... | ... | @@ -509,10 +509,10 @@ public class ContentEvaluation extends Evaluation { |
509 | 509 | * "Jakarta Commons-HttpClient/3.1"); |
510 | 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 | 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 | 516 | if (codResponse == -1) { |
517 | 517 | return "aviso"; |
518 | 518 | } |
... | ... | @@ -557,6 +557,8 @@ public class ContentEvaluation extends Evaluation { |
557 | 557 | HttpMethod metodoRequisicaoGET = null; |
558 | 558 | HttpClient clienteHTTPJakartaCommons; |
559 | 559 | URL UrlConvertida; |
560 | + int codResponse = -1; | |
561 | + | |
560 | 562 | try { |
561 | 563 | |
562 | 564 | String[] test = href.split("\\../"); |
... | ... | @@ -580,9 +582,9 @@ public class ContentEvaluation extends Evaluation { |
580 | 582 | // "UTF-8")); |
581 | 583 | |
582 | 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 | 589 | } catch (MalformedURLException e) { |
588 | 590 | e.printStackTrace(); |
... | ... | @@ -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 | 1 | package br.com.checker.emag.core; |
2 | 2 | |
3 | 3 | |
4 | +import java.net.URL; | |
5 | +import java.net.URLEncoder; | |
4 | 6 | import java.util.ArrayList; |
5 | 7 | import java.util.Arrays; |
6 | 8 | import java.util.Collections; |
... | ... | @@ -14,10 +16,6 @@ import net.htmlparser.jericho.Element; |
14 | 16 | import net.htmlparser.jericho.Source; |
15 | 17 | |
16 | 18 | import org.apache.commons.lang3.StringUtils; |
17 | -import org.w3c.dom.Document; | |
18 | - | |
19 | - | |
20 | - | |
21 | 19 | |
22 | 20 | import br.com.checker.emag.Occurrence; |
23 | 21 | import br.com.checker.emag.OccurrenceClassification; |
... | ... | @@ -39,6 +37,7 @@ public class MarkEvaluation extends Evaluation { |
39 | 37 | } |
40 | 38 | |
41 | 39 | private MarkEvaluation(Source document, String url) { |
40 | + | |
42 | 41 | super(document, url); |
43 | 42 | } |
44 | 43 | |
... | ... | @@ -164,15 +163,15 @@ public class MarkEvaluation extends Evaluation { |
164 | 163 | |
165 | 164 | String url = getUrl(); |
166 | 165 | if (url != null) { |
167 | - | |
166 | + | |
168 | 167 | int[] errosWarningsCss = getErrorCount(true, url); |
169 | 168 | int[] errosWarningsHtml = getErrorCount(false, url); |
170 | 169 | int avisoHtml = 0; |
171 | 170 | int errosHtml = 0; |
172 | 171 | int avisoCss = 0; |
173 | 172 | int errosCss = 0; |
174 | - | |
175 | - | |
173 | + | |
174 | + | |
176 | 175 | avisoHtml = errosWarningsHtml[1]; |
177 | 176 | |
178 | 177 | if (avisoHtml > 0) |
... | ... | @@ -1057,13 +1056,21 @@ public class MarkEvaluation extends Evaluation { |
1057 | 1056 | OccurrenceClassification.MARK, criterio); |
1058 | 1057 | } |
1059 | 1058 | |
1059 | + | |
1060 | + | |
1060 | 1061 | public int[] getErrorCount(boolean isCss, String url) { |
1061 | 1062 | int errors = 0; |
1062 | 1063 | int warnings = 0; |
1064 | + URL UrlConvertida; | |
1065 | + | |
1063 | 1066 | |
1064 | 1067 | try { |
1068 | + UrlConvertida = new URL(url); | |
1069 | + | |
1070 | + | |
1065 | 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 | 1075 | Matcher m = Pattern.compile("<m:errorcount>(\\d)*</m:errorcount>",Pattern.MULTILINE).matcher(content); |
1069 | 1076 | if (m.find()) |
... | ... | @@ -1076,7 +1083,7 @@ public class MarkEvaluation extends Evaluation { |
1076 | 1083 | |
1077 | 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 | 1087 | Gson g = new GsonBuilder().create(); |
1081 | 1088 | HtmlValidation a = g.fromJson(content, HtmlValidation.class); |
1082 | 1089 | int[] errorsWarnings = a.getQtdWarningsErros(); | ... | ... |