Commit 4b8b5974e722c9f3ebaa81752ec124fbed144f85
1 parent
619e8b9c
Exists in
master
and in
1 other branch
Mudança da conexão para "Jakarta".
Showing
1 changed file
with
48 additions
and
5 deletions
Show diff stats
src/main/java/br/com/ases/model/utilities/Validate.java
1 | 1 | package br.com.ases.model.utilities; |
2 | 2 | |
3 | +import static br.com.checker.emag.core.Checker.from; | |
4 | +import groovy.time.BaseDuration.From; | |
5 | + | |
3 | 6 | import java.io.IOException; |
4 | 7 | import java.net.MalformedURLException; |
5 | 8 | import java.net.URL; |
... | ... | @@ -7,10 +10,18 @@ import java.net.URLConnection; |
7 | 10 | import java.util.regex.Matcher; |
8 | 11 | import java.util.regex.Pattern; |
9 | 12 | |
13 | +import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; | |
14 | +import org.apache.commons.httpclient.HttpClient; | |
15 | +import org.apache.commons.httpclient.HttpMethod; | |
16 | +import org.apache.commons.httpclient.methods.GetMethod; | |
17 | +import org.apache.commons.httpclient.params.HttpMethodParams; | |
18 | + | |
19 | +import br.com.ases.infra.WebChecker; | |
10 | 20 | import br.com.ases.model.entity.Contato; |
11 | 21 | import br.com.caelum.vraptor.Validator; |
12 | 22 | import br.com.caelum.vraptor.interceptor.multipart.UploadedFile; |
13 | 23 | import br.com.caelum.vraptor.validator.ValidationMessage; |
24 | +import br.com.checker.emag.core.Checker; | |
14 | 25 | |
15 | 26 | public class Validate { |
16 | 27 | |
... | ... | @@ -68,19 +79,51 @@ public class Validate { |
68 | 79 | public boolean url(String campo){ |
69 | 80 | |
70 | 81 | boolean isValido = true; |
82 | + int codResponse; | |
83 | + HttpMethod metodoRequisicaoGET = null; | |
84 | + HttpClient clienteHTTPJakartaCommons; | |
85 | + URL UrlConvertida; | |
86 | + | |
71 | 87 | if(campo == null || campo.length() <= 10 ){ |
72 | 88 | this.validator.add(new ValidationMessage("Não foi possível realizar a avaliação! Favor preencher o campo URL.", "warning")); |
73 | 89 | isValido = false; |
74 | 90 | }else{ |
75 | 91 | try { |
76 | - URL url = new URL(campo); | |
77 | - URLConnection conn = url.openConnection(); | |
78 | - conn.connect(); | |
92 | + //URL url = new URL(campo); | |
93 | + | |
94 | + //URLConnection conn = url.openConnection(); | |
95 | + // conn.connect(); | |
96 | + | |
97 | + UrlConvertida = new URL(campo); | |
98 | + | |
99 | + clienteHTTPJakartaCommons = new HttpClient(); | |
100 | + clienteHTTPJakartaCommons.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3,false)); | |
101 | + clienteHTTPJakartaCommons.getParams().setParameter("http.protocol.allow-circular-redirects", true); | |
102 | + | |
103 | + metodoRequisicaoGET = new GetMethod(UrlConvertida.toExternalForm()); | |
104 | + | |
105 | + metodoRequisicaoGET.setRequestHeader("http.agent", "Jakarta Commons-HttpClient/3.1"); | |
106 | + metodoRequisicaoGET.setFollowRedirects(true); | |
107 | + | |
108 | + codResponse = clienteHTTPJakartaCommons.executeMethod(metodoRequisicaoGET); | |
109 | + | |
110 | + if(codResponse != 200) | |
111 | + { | |
112 | + this.validator.add(new ValidationMessage("Não foi possível realizar a avaliação! URL "+campo+" é considerada inválida.", "warning")); | |
113 | + isValido = false; | |
114 | + } | |
115 | + else | |
116 | + { | |
117 | + isValido = true; | |
118 | + } | |
119 | + | |
79 | 120 | } catch (MalformedURLException e) { |
80 | - this.validator.add(new ValidationMessage("Não foi possível realizar a avaliação! URL "+campo+" considerada inválida.", "warning")); | |
121 | + e.printStackTrace(); | |
122 | + this.validator.add(new ValidationMessage("Não foi possível realizar a avaliação! URL "+campo+" é considerada inválida.", "warning")); | |
81 | 123 | isValido = false; |
82 | 124 | } catch (IOException e) { |
83 | - this.validator.add(new ValidationMessage("Não foi possível realizar a avaliação! URL "+campo+" considerada inválida.", "warning")); | |
125 | + e.printStackTrace(); | |
126 | + this.validator.add(new ValidationMessage("Não foi possível realizar a avaliação! URL "+campo+" é considerada inválida.", "warning")); | |
84 | 127 | isValido = false; |
85 | 128 | } |
86 | 129 | } | ... | ... |