Commit f524cb57ed4696cb27d951b457d1c063926352d7

Authored by Cleverson Sacramento
1 parent b0d8ad71
Exists in master

Movendo o validador de payload para a extensão rest

archetype/html-rest/src/main/resources/archetype-resources/src/main/java/entity/Bookmark.java
@@ -26,7 +26,7 @@ public class Bookmark implements Serializable { @@ -26,7 +26,7 @@ public class Bookmark implements Serializable {
26 private String description; 26 private String description;
27 27
28 @NotNull 28 @NotNull
29 - @Pattern(regexp = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$", message = "formato inválido") 29 + @Pattern(regexp = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$", message = "{invalid.url}")
30 private String link; 30 private String link;
31 31
32 public Bookmark() { 32 public Bookmark() {
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/rest/BookmarkREST.java
@@ -21,7 +21,7 @@ import ${package}.entity.Bookmark; @@ -21,7 +21,7 @@ import ${package}.entity.Bookmark;
21 import br.gov.frameworkdemoiselle.BadRequestException; 21 import br.gov.frameworkdemoiselle.BadRequestException;
22 import br.gov.frameworkdemoiselle.NotFoundException; 22 import br.gov.frameworkdemoiselle.NotFoundException;
23 import br.gov.frameworkdemoiselle.transaction.Transactional; 23 import br.gov.frameworkdemoiselle.transaction.Transactional;
24 -import br.gov.frameworkdemoiselle.validation.Validate; 24 +import br.gov.frameworkdemoiselle.util.ValidatePayload;
25 25
26 @Path("bookmark") 26 @Path("bookmark")
27 public class BookmarkREST { 27 public class BookmarkREST {
@@ -49,8 +49,8 @@ public class BookmarkREST { @@ -49,8 +49,8 @@ public class BookmarkREST {
49 } 49 }
50 50
51 @POST 51 @POST
52 - @Validate  
53 @Transactional 52 @Transactional
  53 + @ValidatePayload
54 @Produces("text/plain") 54 @Produces("text/plain")
55 @Consumes("application/json") 55 @Consumes("application/json")
56 public Response insert(Bookmark entity, @Context UriInfo uriInfo) { 56 public Response insert(Bookmark entity, @Context UriInfo uriInfo) {
@@ -63,9 +63,9 @@ public class BookmarkREST { @@ -63,9 +63,9 @@ public class BookmarkREST {
63 } 63 }
64 64
65 @PUT 65 @PUT
66 - @Validate  
67 @Path("{id}") 66 @Path("{id}")
68 @Transactional 67 @Transactional
  68 + @ValidatePayload
69 @Produces("application/json") 69 @Produces("application/json")
70 @Consumes("application/json") 70 @Consumes("application/json")
71 public void update(@PathParam("id") Long id, Bookmark entity) { 71 public void update(@PathParam("id") Long id, Bookmark entity) {
archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/ValidationMessages.properties
1 -br.gov.frameworkdemoiselle.pispasep=Informe um PIS/PASEP v\u00E1lido.  
2 -br.gov.frameworkdemoiselle.inscricaoestadual=Informe uma Inscri\u00E7\u00E3o Estadual v\u00E1lida.  
3 -br.gov.frameworkdemoiselle.cpf=Informe um CPF v\u00E1lido.  
4 -br.gov.frameworkdemoiselle.cnpj=Informe um CNPJ v\u00E1lido.  
5 -br.gov.frameworkdemoiselle.cep=Informe um CEP v\u00E1lido.  
6 -  
7 -javax.validation.constraints.AssertFalse.message=Este campo deve conter o valor falso.  
8 -javax.validation.constraints.AssertTrue.message=Este campo deve conter o valor verdadeiro.  
9 -javax.validation.constraints.DecimalMax.message=O valor deve ser menor ou igual a {value}.  
10 -javax.validation.constraints.DecimalMin.message=O valor deve ser maior ou igual a {value}.  
11 -javax.validation.constraints.Digits.message=Valor num\u00E9rico incorreto. (<{integer} d\u00EDgitos>.<{fraction} d\u00EDgitos> esperado).  
12 -javax.validation.constraints.Future.message=Deve ser uma data no futuro.  
13 -javax.validation.constraints.Max.message=O valor deve ser menor ou igual a {value}.  
14 -javax.validation.constraints.Min.message=O valor deve ser maior ou igual a {value}.  
15 -javax.validation.constraints.NotNull.message=N\u00E3o pode ser nulo.  
16 -javax.validation.constraints.Null.message=Deve ser nulo.  
17 -javax.validation.constraints.Past.message=Deve ser uma data no passado.  
18 -javax.validation.constraints.Pattern.message=O valor deve seguir o padr\u00E3o "{regexp}".  
19 -javax.validation.constraints.Size.message=O tamanho deve ser entre {min} e {max}.  
20 -  
21 -org.hibernate.validator.constraints.Email.message=E-mail inv\u00E1lido.  
22 -org.hibernate.validator.constraints.Length.message=O tamanho deve ser entre {min} e {max}.  
23 -org.hibernate.validator.constraints.NotBlank.message=N\u00E3o pode ser vazio.  
24 -org.hibernate.validator.constraints.NotEmpty.message=N\u00E3o pode ser vazio.  
25 -org.hibernate.validator.constraints.Range.message=Deve ser um valor entre {min} e {max}.  
26 -org.hibernate.validator.constraints.URL.message=Endere\u00E7o de Internet inv\u00E1lido.  
27 -org.hibernate.validator.constraints.CreditCardNumber.message=N\u00FAmero de cart\u00E3o de cr\u00E9dito inv\u00E1lido.  
28 -org.hibernate.validator.constraints.ScriptAssert.message=Express\u00E3o de script "{script}" n\u00E3o avaliada como verdadeira. 1 +invalid.url=formato inv\u00E1lido
archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties 100755 → 100644
1 -# Enables JPA transaction strategy, automatically detected if demoiselle-jpa component is detected. Use only if you need to overwrite the default behaviour  
2 -#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction  
3 -  
4 -# Enables JTA transaction strategy, automatically detected if demoiselle-jta component is detected. Use only if you need to overwrite the default behaviour  
5 -#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction 1 +# See http://demoiselle.sourceforge.net/docs/framework/reference/2.4.0/html_single/#propriedades
archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages.properties
@@ -1,45 +0,0 @@ @@ -1,45 +0,0 @@
1 -menu.bookmark=Bookmarks  
2 -bookmark.label=Bookmark  
3 -  
4 -bookmark-delete-ok=Bookmark exclu\u00EDdo\: {0}  
5 -bookmark-insert-ok=Bookmark inserido: {0}  
6 -bookmark-update-ok=Bookmark atualizado: {0}  
7 -  
8 -bookmark.list.table.title=Lista de Links  
9 -  
10 -bookmark.label.id=ID  
11 -bookmark.label.link=Link  
12 -bookmark.label.description=Descri\u00E7\u00E3o  
13 -  
14 -bookmark.alt.id=ID  
15 -bookmark.alt.link=Link  
16 -bookmark.alt.description=Descri\u00E7\u00E3o  
17 -  
18 -button.add.new=Incluir Novo  
19 -button.back=Voltar  
20 -button.delete=Excluir  
21 -button.dialog.no=N\u00E3o, desculpe\!  
22 -button.dialog.yes=Sim, claro!  
23 -button.edit=Editar  
24 -button.new=Novo  
25 -button.save=Salvar  
26 -  
27 -label.action=A\u00E7\u00E3o  
28 -label.dialog.alert=Alerta  
29 -label.dialog.delete=Excluir  
30 -label.confirm.delete=Confirma?  
31 -label.date.pattern=dd/MM/yyyy  
32 -  
33 -main.app.title=Bookmarks  
34 -main.app.welcome=Bem-vindo \u00E0 aplica\u00E7\u00E3o de exemplo Bookmark. Este \u00E9 o seu ponto de partida, portanto sinta-se \u00E0 vontade para modificar esta aplica\u00E7\u00E3o.  
35 -main.change.skin=Mudar Pele  
36 -main.skin=Pele  
37 -main.footer.text=Aplica\u00E7\u00E3o de exemplo do Demoiselle ${parent.version}  
38 -  
39 -menu.language=Idioma  
40 -menu.menuitem.language-portuguese=Portugu\u00EAs  
41 -menu.menuitem.language-english=Ingl\u00EAs  
42 -menu.menuitem.contents=Conte\u00FAdo  
43 -menu.menuitem.list=Listar  
44 -menu.menuitem.new=Novo  
45 -menu.menuitem.quit=Sair  
archetype/html-rest/src/main/resources/archetype-resources/src/main/resources/messages_en.properties
@@ -1,45 +0,0 @@ @@ -1,45 +0,0 @@
1 -menu.bookmark=Bookmarks  
2 -bookmark.label=Bookmark  
3 -  
4 -bookmark-delete-ok=Bookmark removed\: {0}  
5 -bookmark-insert-ok=Bookmark inserted\: {0}  
6 -bookmark-update-ok=Bookmark updated\: {0}  
7 -  
8 -bookmark.list.table.title=All Links  
9 -  
10 -bookmark.label.id=ID  
11 -bookmark.label.link=Link  
12 -bookmark.label.description=Description  
13 -  
14 -bookmark.alt.id=ID  
15 -bookmark.alt.link=Link  
16 -bookmark.alt.description=Description  
17 -  
18 -button.add.new=Insert New  
19 -button.back=Back  
20 -button.delete=Remove  
21 -button.dialog.no=No, sorry\!  
22 -button.dialog.yes=Yes, sure\!  
23 -button.edit=Edit  
24 -button.new=New  
25 -button.save=Save  
26 -  
27 -label.action=Action  
28 -label.dialog.alert=Alert  
29 -label.dialog.delete=Remove  
30 -label.confirm.delete=Confirm?  
31 -label.date.pattern=MM/dd/yyyy  
32 -  
33 -main.app.title=Bookmarks  
34 -main.app.welcome=Welcome to the example application Bookmark. This is your starting point, feel free to change this application.  
35 -main.change.skin=Change Skin  
36 -main.skin=Skin  
37 -main.footer.text=Example Application for Demoiselle ${parent.version}  
38 -  
39 -menu.language=Language  
40 -menu.menuitem.language-portuguese=Portuguese  
41 -menu.menuitem.language-english=English  
42 -menu.menuitem.contents=Content  
43 -menu.menuitem.list=List  
44 -menu.menuitem.new=New  
45 -menu.menuitem.quit=Quit  
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/beans.xml
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <class>br.gov.frameworkdemoiselle.security.LoggedInInterceptor</class> 5 <class>br.gov.frameworkdemoiselle.security.LoggedInInterceptor</class>
6 <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> 6 <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class>
7 <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> 7 <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class>
8 - <class>br.gov.frameworkdemoiselle.validation.ValidateInterceptor</class> 8 + <class>br.gov.frameworkdemoiselle.util.ValidateInterceptor</class>
9 <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> 9 <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class>
10 <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> 10 <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class>
11 </interceptors> 11 </interceptors>
impl/core/src/main/java/br/gov/frameworkdemoiselle/validation/Validate.java
@@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.validation;  
38 -  
39 -import static java.lang.annotation.ElementType.METHOD;  
40 -import static java.lang.annotation.ElementType.TYPE;  
41 -import static java.lang.annotation.RetentionPolicy.RUNTIME;  
42 -  
43 -import java.lang.annotation.Inherited;  
44 -import java.lang.annotation.Retention;  
45 -import java.lang.annotation.Target;  
46 -  
47 -import javax.interceptor.InterceptorBinding;  
48 -  
49 -@Inherited  
50 -@InterceptorBinding  
51 -@Target({ METHOD, TYPE })  
52 -@Retention(RUNTIME)  
53 -public @interface Validate {  
54 -  
55 -}  
impl/core/src/main/java/br/gov/frameworkdemoiselle/validation/ValidateInterceptor.java
@@ -1,80 +0,0 @@ @@ -1,80 +0,0 @@
1 -/*  
2 - * Demoiselle Framework  
3 - * Copyright (C) 2010 SERPRO  
4 - * ----------------------------------------------------------------------------  
5 - * This file is part of Demoiselle Framework.  
6 - *  
7 - * Demoiselle Framework is free software; you can redistribute it and/or  
8 - * modify it under the terms of the GNU Lesser General Public License version 3  
9 - * as published by the Free Software Foundation.  
10 - *  
11 - * This program is distributed in the hope that it will be useful,  
12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
14 - * GNU General Public License for more details.  
15 - *  
16 - * You should have received a copy of the GNU Lesser General Public License version 3  
17 - * along with this program; if not, see <http://www.gnu.org/licenses/>  
18 - * or write to the Free Software Foundation, Inc., 51 Franklin Street,  
19 - * Fifth Floor, Boston, MA 02110-1301, USA.  
20 - * ----------------------------------------------------------------------------  
21 - * Este arquivo é parte do Framework Demoiselle.  
22 - *  
23 - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou  
24 - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação  
25 - * do Software Livre (FSF).  
26 - *  
27 - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA  
28 - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou  
29 - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português  
30 - * para maiores detalhes.  
31 - *  
32 - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título  
33 - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>  
34 - * ou escreva para a Fundação do Software Livre (FSF) Inc.,  
35 - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.  
36 - */  
37 -package br.gov.frameworkdemoiselle.validation;  
38 -  
39 -import java.io.Serializable;  
40 -import java.util.HashSet;  
41 -import java.util.Set;  
42 -  
43 -import javax.interceptor.AroundInvoke;  
44 -import javax.interceptor.Interceptor;  
45 -import javax.interceptor.InvocationContext;  
46 -import javax.validation.ConstraintViolation;  
47 -import javax.validation.ConstraintViolationException;  
48 -import javax.validation.Validation;  
49 -import javax.validation.Validator;  
50 -import javax.validation.ValidatorFactory;  
51 -  
52 -/**  
53 - * Intercepts calls with {@code @Validate} annotations.  
54 - *  
55 - * @author SERPRO  
56 - */  
57 -@Validate  
58 -@Interceptor  
59 -public class ValidateInterceptor implements Serializable {  
60 -  
61 - private static final long serialVersionUID = 1L;  
62 -  
63 - @AroundInvoke  
64 - public Object manage(final InvocationContext ic) throws Exception {  
65 - Set<ConstraintViolation<?>> violations = new HashSet<ConstraintViolation<?>>();  
66 -  
67 - for (Object params : ic.getParameters()) {  
68 - ValidatorFactory dfv = Validation.buildDefaultValidatorFactory();  
69 - Validator validator = dfv.getValidator();  
70 -  
71 - violations.addAll(validator.validate(params));  
72 - }  
73 -  
74 - if (!violations.isEmpty()) {  
75 - throw new ConstraintViolationException(violations);  
76 - }  
77 -  
78 - return ic.proceed();  
79 - }  
80 -}  
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayload.java 0 → 100644
@@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.util;
  38 +
  39 +import static java.lang.annotation.ElementType.METHOD;
  40 +import static java.lang.annotation.ElementType.TYPE;
  41 +import static java.lang.annotation.RetentionPolicy.RUNTIME;
  42 +
  43 +import java.lang.annotation.Inherited;
  44 +import java.lang.annotation.Retention;
  45 +import java.lang.annotation.Target;
  46 +
  47 +import javax.interceptor.InterceptorBinding;
  48 +
  49 +@Inherited
  50 +@InterceptorBinding
  51 +@Target({ METHOD, TYPE })
  52 +@Retention(RUNTIME)
  53 +public @interface ValidatePayload {
  54 +
  55 +}
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/util/ValidatePayloadInterceptor.java 0 → 100644
@@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package br.gov.frameworkdemoiselle.util;
  38 +
  39 +import java.io.Serializable;
  40 +import java.util.HashSet;
  41 +import java.util.Set;
  42 +
  43 +import javax.interceptor.AroundInvoke;
  44 +import javax.interceptor.Interceptor;
  45 +import javax.interceptor.InvocationContext;
  46 +import javax.validation.ConstraintViolation;
  47 +import javax.validation.ConstraintViolationException;
  48 +import javax.validation.Validation;
  49 +import javax.validation.Validator;
  50 +import javax.validation.ValidatorFactory;
  51 +
  52 +/**
  53 + * Intercepts calls with {@code @ValidatePayload} annotations.
  54 + *
  55 + * @author SERPRO
  56 + */
  57 +@ValidatePayload
  58 +@Interceptor
  59 +public class ValidatePayloadInterceptor implements Serializable {
  60 +
  61 + private static final long serialVersionUID = 1L;
  62 +
  63 + @AroundInvoke
  64 + public Object manage(final InvocationContext ic) throws Exception {
  65 + Set<ConstraintViolation<?>> violations = new HashSet<ConstraintViolation<?>>();
  66 +
  67 + for (Object params : ic.getParameters()) {
  68 + if (params != null) {
  69 + ValidatorFactory dfv = Validation.buildDefaultValidatorFactory();
  70 + Validator validator = dfv.getValidator();
  71 + violations.addAll(validator.validate(params));
  72 + }
  73 + }
  74 +
  75 + if (!violations.isEmpty()) {
  76 + throw new ConstraintViolationException(violations);
  77 + }
  78 +
  79 + return ic.proceed();
  80 + }
  81 +}
impl/extension/rest/src/main/resources/META-INF/beans.xml 0 → 100644
@@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  39 +
  40 +</beans>
0 \ No newline at end of file 41 \ No newline at end of file