Commit b9624b4bc93e22a9e3a0fb62c63f566b070688f3

Authored by Dancovich
2 parents b8e4061f 01a2be5a
Exists in master

Merge remote-tracking branch 'origin/2.4.0' into 2.4.0

Showing 28 changed files with 835 additions and 215 deletions   Show diff stats
documentation/reference/pt-BR/properties.xml
@@ -129,7 +129,7 @@ @@ -129,7 +129,7 @@
129 <entry>true</entry> 129 <entry>true</entry>
130 </row> 130 </row>
131 <row valign="top"> 131 <row valign="top">
132 - <entry>frameworkdemoiselle.&#8203;handle.&#8203;application.&#8203;exception</entry> 132 + <entry>frameworkdemoiselle.&#8203;exception.&#8203;application.&#8203;handle</entry>
133 <entry> 133 <entry>
134 <para> 134 <para>
135 Habilita o tratamento automático das exceções da aplicação anotadas com @ApplicationException. 135 Habilita o tratamento automático das exceções da aplicação anotadas com @ApplicationException.
@@ -138,7 +138,7 @@ @@ -138,7 +138,7 @@
138 <entry>true</entry> 138 <entry>true</entry>
139 </row> 139 </row>
140 <row valign="top"> 140 <row valign="top">
141 - <entry>frameworkdemoiselle.&#8203;handle.&#8203;application.&#8203;exception.&#8203;page</entry> 141 + <entry>frameworkdemoiselle.&#8203;exception.&#8203;default.&#8203;redirect.&#8203;page</entry>
142 <entry> 142 <entry>
143 <para> 143 <para>
144 Define o redirecionamento das exceções da aplicação anotadas com @ApplicationException ocorridas 144 Define o redirecionamento das exceções da aplicação anotadas com @ApplicationException ocorridas
@@ -276,28 +276,28 @@ @@ -276,28 +276,28 @@
276 </thead> 276 </thead>
277 <tbody> 277 <tbody>
278 <row valign="top"> 278 <row valign="top">
279 - <entry role="">frameworkdemoiselle.&#8203;management.&#8203;jmx.&#8203;mbean.&#8203;domain</entry> 279 + <entry role="">frameworkdemoiselle.&#8203;management.&#8203;mbean.&#8203;domain</entry>
280 <entry> 280 <entry>
281 <para>Define o domínio padrão onde classes anotadas com <emphasis>@ManagementController</emphasis> serão registradas no MBeanServer.</para> 281 <para>Define o domínio padrão onde classes anotadas com <emphasis>@ManagementController</emphasis> serão registradas no MBeanServer.</para>
282 <para>Na especificação JMX, um MBean é registrado no MBeanServer com um nome no formato <emphasis>domain:name=MBeanName</emphasis> 282 <para>Na especificação JMX, um MBean é registrado no MBeanServer com um nome no formato <emphasis>domain:name=MBeanName</emphasis>
283 - (ex: <emphasis>br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;jmx.&#8203;name=NotificationBroadcaster</emphasis>). Esse parâmetro controla a porção <emphasis>domain</emphasis> 283 + (ex: <emphasis>br.&#8203;gov.&#8203;frameworkdemoiselle:&#8203;name=NotificationBroadcaster</emphasis>). Esse parâmetro controla a porção <emphasis>domain</emphasis>
284 desse formato.</para> 284 desse formato.</para>
285 </entry> 285 </entry>
286 <entry>O pacote da classe anotada com <emphasis>@Management&#8203;Controller</emphasis></entry> 286 <entry>O pacote da classe anotada com <emphasis>@Management&#8203;Controller</emphasis></entry>
287 </row> 287 </row>
288 <row valign="top"> 288 <row valign="top">
289 - <entry colsep="1">frameworkdemoiselle.&#8203;management.&#8203;jmx.&#8203;notification.&#8203;domain</entry> 289 + <entry colsep="1">frameworkdemoiselle.&#8203;management.&#8203;notification.&#8203;domain</entry>
290 <entry colsep="1"> 290 <entry colsep="1">
291 - <para>O mesmo que <emphasis>frameworkdemoiselle.&#8203;management.&#8203;jmx.&#8203;mbean.&#8203;domain</emphasis>, mas apenas para o domínio do  
292 - MBean <emphasis role="bold">br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;jmx.&#8203;internal.&#8203;NotificationBroadcaster</emphasis>. Esse MBean é automaticamente 291 + <para>O mesmo que <emphasis>frameworkdemoiselle.&#8203;management.&#8203;mbean.&#8203;domain</emphasis>, mas apenas para o domínio do
  292 + MBean <emphasis role="bold">br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;internal.&#8203;NotificationBroadcaster</emphasis>. Esse MBean é automaticamente
293 registrado para receber notificações enviadas usando a classe <emphasis role="bold">br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;management.&#8203;NotificationManager</emphasis></para> 293 registrado para receber notificações enviadas usando a classe <emphasis role="bold">br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;management.&#8203;NotificationManager</emphasis></para>
294 </entry> 294 </entry>
295 <entry>br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;jmx</entry> 295 <entry>br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;jmx</entry>
296 </row> 296 </row>
297 <row valign="top"> 297 <row valign="top">
298 - <entry>frameworkdemoiselle.&#8203;management.&#8203;jmx.&#8203;notification.&#8203;name</entry> 298 + <entry>frameworkdemoiselle.&#8203;management.&#8203;notification.&#8203;name</entry>
299 <entry> 299 <entry>
300 - <para>O nome usado para registrar a classe <emphasis role="bold">br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;jmx.&#8203;internal.&#8203;NotificationBroadcaster</emphasis> como MBean.</para> 300 + <para>O nome usado para registrar a classe <emphasis role="bold">br.&#8203;gov.&#8203;frameworkdemoiselle.&#8203;internal.&#8203;NotificationBroadcaster</emphasis> como MBean.</para>
301 </entry> 301 </entry>
302 <entry>Notification&#8203;Broadcaster</entry> 302 <entry>Notification&#8203;Broadcaster</entry>
303 </row> 303 </row>
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationImpl.java
@@ -49,10 +49,17 @@ public class ConfigurationImpl implements Serializable { @@ -49,10 +49,17 @@ public class ConfigurationImpl implements Serializable {
49 private boolean loaded = false; 49 private boolean loaded = false;
50 50
51 @SuppressWarnings("unused") 51 @SuppressWarnings("unused")
52 - private synchronized void load(Object instance) { 52 + private synchronized void load(Object instance) throws Throwable {
53 if (!loaded) { 53 if (!loaded) {
54 - Beans.getReference(ConfigurationLoader.class).load(instance);  
55 loaded = true; 54 loaded = true;
  55 +
  56 + try {
  57 + Beans.getReference(ConfigurationLoader.class).load(instance);
  58 +
  59 + } catch (Throwable cause) {
  60 + loaded = false;
  61 + throw cause;
  62 + }
56 } 63 }
57 } 64 }
58 } 65 }
impl/core/src/test/java/configuration/field/beanvalidation/ConfigurationBeanValidationFieldTest.java
@@ -42,8 +42,6 @@ import static junit.framework.Assert.fail; @@ -42,8 +42,6 @@ import static junit.framework.Assert.fail;
42 import javax.inject.Inject; 42 import javax.inject.Inject;
43 import javax.validation.ConstraintViolationException; 43 import javax.validation.ConstraintViolationException;
44 44
45 -import junit.framework.Assert;  
46 -  
47 import org.jboss.arquillian.container.test.api.Deployment; 45 import org.jboss.arquillian.container.test.api.Deployment;
48 import org.jboss.arquillian.junit.Arquillian; 46 import org.jboss.arquillian.junit.Arquillian;
49 import org.jboss.shrinkwrap.api.spec.JavaArchive; 47 import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -107,14 +105,14 @@ public class ConfigurationBeanValidationFieldTest { @@ -107,14 +105,14 @@ public class ConfigurationBeanValidationFieldTest {
107 propertyBeanValidationWithEmptyNotNullFieldConfig.getIntAttributeNull(); 105 propertyBeanValidationWithEmptyNotNullFieldConfig.getIntAttributeNull();
108 fail(); 106 fail();
109 } catch (ConfigurationException cause) { 107 } catch (ConfigurationException cause) {
110 - Assert.assertEquals(ConstraintViolationException.class, cause.getCause().getClass()); 108 + assertEquals(ConstraintViolationException.class, cause.getCause().getClass());
111 } 109 }
112 110
113 try { 111 try {
114 xmlBeanValidationWithEmptyNotNullFieldConfig.getIntAttributeNull(); 112 xmlBeanValidationWithEmptyNotNullFieldConfig.getIntAttributeNull();
115 fail(); 113 fail();
116 } catch (ConfigurationException cause) { 114 } catch (ConfigurationException cause) {
117 - Assert.assertEquals(ConstraintViolationException.class, cause.getCause().getClass()); 115 + assertEquals(ConstraintViolationException.class, cause.getCause().getClass());
118 } 116 }
119 } 117 }
120 118
@@ -124,14 +122,14 @@ public class ConfigurationBeanValidationFieldTest { @@ -124,14 +122,14 @@ public class ConfigurationBeanValidationFieldTest {
124 propertyBeanValidationWithEmptyNotNullFieldConfig.getStringAttributeNull(); 122 propertyBeanValidationWithEmptyNotNullFieldConfig.getStringAttributeNull();
125 fail(); 123 fail();
126 } catch (ConfigurationException cause) { 124 } catch (ConfigurationException cause) {
127 - Assert.assertEquals(ConstraintViolationException.class, cause.getCause().getClass()); 125 + assertEquals(ConstraintViolationException.class, cause.getCause().getClass());
128 } 126 }
129 127
130 try { 128 try {
131 xmlBeanValidationWithEmptyNotNullFieldConfig.getStringAttributeNull(); 129 xmlBeanValidationWithEmptyNotNullFieldConfig.getStringAttributeNull();
132 fail(); 130 fail();
133 } catch (ConfigurationException cause) { 131 } catch (ConfigurationException cause) {
134 - Assert.assertEquals(ConstraintViolationException.class, cause.getCause().getClass()); 132 + assertEquals(ConstraintViolationException.class, cause.getCause().getClass());
135 } 133 }
136 } 134 }
137 135
@@ -141,7 +139,7 @@ public class ConfigurationBeanValidationFieldTest { @@ -141,7 +139,7 @@ public class ConfigurationBeanValidationFieldTest {
141 propertyWithTwoConstrainViolations.getAttributeWithTwoConstrainValidations(); 139 propertyWithTwoConstrainViolations.getAttributeWithTwoConstrainValidations();
142 fail(); 140 fail();
143 } catch (ConfigurationException cause) { 141 } catch (ConfigurationException cause) {
144 - Assert.assertEquals(ConstraintViolationException.class, cause.getCause().getClass()); 142 + assertEquals(ConstraintViolationException.class, cause.getCause().getClass());
145 } 143 }
146 } 144 }
147 } 145 }
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JMXConfig.java
@@ -65,7 +65,7 @@ import br.gov.frameworkdemoiselle.stereotype.ManagementController; @@ -65,7 +65,7 @@ import br.gov.frameworkdemoiselle.stereotype.ManagementController;
65 * @author serpro 65 * @author serpro
66 * 66 *
67 */ 67 */
68 -@Configuration(prefix = "frameworkdemoiselle.management.jmx") 68 +@Configuration(prefix = "frameworkdemoiselle.management")
69 public class JMXConfig { 69 public class JMXConfig {
70 70
71 @Name("mbean.domain") 71 @Name("mbean.domain")
impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java
@@ -105,7 +105,7 @@ public class DynamicMBeanProxyTest { @@ -105,7 +105,7 @@ public class DynamicMBeanProxyTest {
105 105
106 ObjectName name = null; 106 ObjectName name = null;
107 try { 107 try {
108 - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); 108 + name = new ObjectName("br.gov.frameworkdemoiselle.domain:name=ManagedTest");
109 } catch (MalformedObjectNameException e) { 109 } catch (MalformedObjectNameException e) {
110 Assert.fail(); 110 Assert.fail();
111 } 111 }
@@ -125,7 +125,7 @@ public class DynamicMBeanProxyTest { @@ -125,7 +125,7 @@ public class DynamicMBeanProxyTest {
125 125
126 ObjectName name = null; 126 ObjectName name = null;
127 try { 127 try {
128 - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); 128 + name = new ObjectName("br.gov.frameworkdemoiselle.domain:name=ManagedTest");
129 } catch (MalformedObjectNameException e) { 129 } catch (MalformedObjectNameException e) {
130 Assert.fail(); 130 Assert.fail();
131 } 131 }
@@ -149,7 +149,7 @@ public class DynamicMBeanProxyTest { @@ -149,7 +149,7 @@ public class DynamicMBeanProxyTest {
149 149
150 ObjectName name = null; 150 ObjectName name = null;
151 try { 151 try {
152 - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); 152 + name = new ObjectName("br.gov.frameworkdemoiselle.domain:name=ManagedTest");
153 } catch (MalformedObjectNameException e) { 153 } catch (MalformedObjectNameException e) {
154 Assert.fail(); 154 Assert.fail();
155 } 155 }
@@ -172,7 +172,7 @@ public class DynamicMBeanProxyTest { @@ -172,7 +172,7 @@ public class DynamicMBeanProxyTest {
172 172
173 ObjectName name = null; 173 ObjectName name = null;
174 try { 174 try {
175 - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); 175 + name = new ObjectName("br.gov.frameworkdemoiselle.domain:name=ManagedTest");
176 } catch (MalformedObjectNameException e) { 176 } catch (MalformedObjectNameException e) {
177 Assert.fail(); 177 Assert.fail();
178 } 178 }
impl/extension/jmx/src/test/resources/configuration/demoiselle.properties
1 -frameworkdemoiselle.management.jmx.mbean.domain=br.gov.frameworkdemoiselle.jmx.domain  
2 \ No newline at end of file 1 \ No newline at end of file
  2 +frameworkdemoiselle.management.mbean.domain=br.gov.frameworkdemoiselle.domain
3 \ No newline at end of file 3 \ No newline at end of file
impl/extension/jsf/pom.xml
@@ -81,6 +81,12 @@ @@ -81,6 +81,12 @@
81 <scope>test</scope> 81 <scope>test</scope>
82 </dependency> 82 </dependency>
83 <dependency> 83 <dependency>
  84 + <groupId>commons-httpclient</groupId>
  85 + <artifactId>commons-httpclient</artifactId>
  86 + <version>3.1</version>
  87 + <scope>test</scope>
  88 + </dependency>
  89 + <dependency>
84 <groupId>org.glassfish.web</groupId> 90 <groupId>org.glassfish.web</groupId>
85 <artifactId>el-impl</artifactId> 91 <artifactId>el-impl</artifactId>
86 <scope>provided</scope> 92 <scope>provided</scope>
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfig.java
@@ -41,22 +41,22 @@ import java.io.Serializable; @@ -41,22 +41,22 @@ import java.io.Serializable;
41 import br.gov.frameworkdemoiselle.annotation.Name; 41 import br.gov.frameworkdemoiselle.annotation.Name;
42 import br.gov.frameworkdemoiselle.configuration.Configuration; 42 import br.gov.frameworkdemoiselle.configuration.Configuration;
43 43
44 -@Configuration(prefix = "frameworkdemoiselle.handle.") 44 +@Configuration(prefix = "frameworkdemoiselle.exception")
45 public class ExceptionHandlerConfig implements Serializable { 45 public class ExceptionHandlerConfig implements Serializable {
46 46
47 private static final long serialVersionUID = 1L; 47 private static final long serialVersionUID = 1L;
48 48
49 - @Name("application.exception")  
50 - private boolean handleApplicationException = true; 49 + @Name("application.handle")
  50 + private boolean applicationExceptionHandle = true;
51 51
52 - @Name("application.exception.page")  
53 - private String exceptionPage = "/application_error"; 52 + @Name("default.redirect.page")
  53 + private String defaultRedirectExceptionPage = "/application_error";
54 54
55 - public String getExceptionPage() {  
56 - return exceptionPage; 55 + public boolean isApplicationExceptionHandle() {
  56 + return applicationExceptionHandle;
57 } 57 }
58 -  
59 - public boolean isHandleApplicationException() {  
60 - return handleApplicationException; 58 +
  59 + public String getDefaultRedirectExceptionPage() {
  60 + return defaultRedirectExceptionPage;
61 } 61 }
62 } 62 }
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfigCompatible.java 0 → 100644
@@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
  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.internal.configuration;
  38 +
  39 +import java.io.Serializable;
  40 +
  41 +import org.slf4j.Logger;
  42 +
  43 +import br.gov.frameworkdemoiselle.annotation.Name;
  44 +import br.gov.frameworkdemoiselle.configuration.Configuration;
  45 +import br.gov.frameworkdemoiselle.util.Beans;
  46 +
  47 +@Deprecated
  48 +@Configuration(prefix = "frameworkdemoiselle.handle")
  49 +public class ExceptionHandlerConfigCompatible implements Serializable {
  50 +
  51 + private static final long serialVersionUID = 1L;
  52 +
  53 + @Deprecated
  54 + @Name("application.exception")
  55 + private boolean handleApplicationException = true;
  56 +
  57 + @Deprecated
  58 + @Name("application.exception.page")
  59 + private String exceptionPage = "/application_error";
  60 +
  61 + @Deprecated
  62 + public boolean isHandleApplicationException() {
  63 + Logger logger = Beans.getReference(Logger.class);
  64 + logger.warn("A propriedade frameworkdemoiselle.handle.application.exception="
  65 + + handleApplicationException
  66 + + " não será suportada nas próximas versões do framework. Para evitar futuros problemas atualize a propriedade para frameworkdemoiselle.exception.application.handle="
  67 + + handleApplicationException);
  68 +
  69 + return handleApplicationException;
  70 + }
  71 +
  72 + @Deprecated
  73 + public String getExceptionPage() {
  74 + Logger logger = Beans.getReference(Logger.class);
  75 + logger.warn("A propriedade frameworkdemoiselle.handle.application.exception.page="
  76 + + exceptionPage
  77 + + " não será suportada nas próximas versões do framework. Para evitar futuros problemas atualize a propriedade para frameworkdemoiselle.exception.default.redirect.page="
  78 + + exceptionPage);
  79 +
  80 + return exceptionPage;
  81 + }
  82 +}
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ApplicationExceptionHandler.java
@@ -43,7 +43,10 @@ import javax.faces.context.ExceptionHandler; @@ -43,7 +43,10 @@ import javax.faces.context.ExceptionHandler;
43 import javax.faces.context.FacesContext; 43 import javax.faces.context.FacesContext;
44 import javax.faces.event.PhaseId; 44 import javax.faces.event.PhaseId;
45 45
  46 +import org.slf4j.Logger;
  47 +
46 import br.gov.frameworkdemoiselle.DemoiselleException; 48 import br.gov.frameworkdemoiselle.DemoiselleException;
  49 +import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible;
47 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; 50 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig;
48 import br.gov.frameworkdemoiselle.util.Beans; 51 import br.gov.frameworkdemoiselle.util.Beans;
49 import br.gov.frameworkdemoiselle.util.Exceptions; 52 import br.gov.frameworkdemoiselle.util.Exceptions;
@@ -58,19 +61,69 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { @@ -58,19 +61,69 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
58 } 61 }
59 62
60 protected boolean handleException(final Throwable cause, FacesContext facesContext) { 63 protected boolean handleException(final Throwable cause, FacesContext facesContext) {
  64 + // Apenas para manter compatibilidade entre 2.3.x e 2.4.0-RCx
  65 + ExceptionHandlerConfigCompatible compatibleConfig = Beans.getReference(ExceptionHandlerConfigCompatible.class);
  66 + // Usuário está utilizando pelo menos uma das propriedades com a forma depreciada de forma explícita
  67 + if (!(compatibleConfig.getExceptionPage().equals("/application_error") && compatibleConfig.isHandleApplicationException())) {
  68 + Logger logger = Beans.getReference(Logger.class);
  69 + logger.warn("As propriedades frameworkdemoiselle.handle.application.exception e"
  70 + + " frameworkdemoiselle.handle.application.exception.page"
  71 + + " não serão suportadas nas próximas versões do framework."
  72 + + " Para evitar futuros problemas atualize as propriedades para"
  73 + + " frameworkdemoiselle.exception.application.handle e"
  74 + + " frameworkdemoiselle.exception.default.redirect.page, respectivamente.");
  75 + return handleExceptionCompatibleConfiguration(compatibleConfig, cause, facesContext);
  76 + }
  77 +
  78 + boolean handled = false;
61 ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class); 79 ExceptionHandlerConfig config = Beans.getReference(ExceptionHandlerConfig.class);
  80 +
  81 + if (config.isApplicationExceptionHandle() && Exceptions.isApplicationException(cause)) {
  82 +
  83 + if (isRendering(facesContext)) {
  84 + handled = handlingDuringRenderResponse(cause, config);
  85 + } else {
  86 + Faces.addMessage(cause);
  87 + handled = true;
  88 + }
  89 + }
  90 +
  91 + return handled;
  92 + }
  93 +
  94 + @Deprecated
  95 + private boolean handleExceptionCompatibleConfiguration(ExceptionHandlerConfigCompatible config, final Throwable cause,
  96 + FacesContext facesContext) {
62 boolean handled = false; 97 boolean handled = false;
63 98
64 if (config.isHandleApplicationException() && Exceptions.isApplicationException(cause)) { 99 if (config.isHandleApplicationException() && Exceptions.isApplicationException(cause)) {
65 100
66 if (isRendering(facesContext)) { 101 if (isRendering(facesContext)) {
67 - handled = handlingDuringRenderResponse(cause, config); 102 + handled = handlingDuringRenderResponseCompatible(cause, config);
68 } else { 103 } else {
69 Faces.addMessage(cause); 104 Faces.addMessage(cause);
70 handled = true; 105 handled = true;
71 } 106 }
72 } 107 }
  108 + return handled;
  109 + }
73 110
  111 + @Deprecated
  112 + private boolean handlingDuringRenderResponseCompatible(final Throwable cause, final ExceptionHandlerConfigCompatible config) {
  113 + boolean handled = false;
  114 + try {
  115 + Map<String, Object> map = new HashMap<String, Object>();
  116 + map.put("exception", cause.getMessage());
  117 + Redirector.redirect(config.getExceptionPage(), map);
  118 + handled = true;
  119 + } catch (PageNotFoundException ex) {
  120 + // TODO Colocar a mensagem no bundle
  121 + throw new DemoiselleException(
  122 + "A tela de exibição de erros: \""
  123 + + ex.getViewId()
  124 + + "\" não foi encontrada. Caso o seu projeto possua outra, defina no arquivo de configuração a chave \""
  125 + + "frameworkdemoiselle.handle.application.exception.page" + "\"", ex);
  126 + }
74 return handled; 127 return handled;
75 } 128 }
76 129
@@ -82,7 +135,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { @@ -82,7 +135,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
82 * In render response phase an exception interrupt the renderization. So this method will redirect the renderingo to 135 * In render response phase an exception interrupt the renderization. So this method will redirect the renderingo to
83 * an page configured in demoiselle.properties 136 * an page configured in demoiselle.properties
84 * 137 *
85 - * @see ExceptionHandlerConfig 138 + * @see ExceptionHandlerConfigCompatible
86 * @param cause 139 * @param cause
87 * @param config 140 * @param config
88 * @return 141 * @return
@@ -92,7 +145,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler { @@ -92,7 +145,7 @@ public class ApplicationExceptionHandler extends AbstractExceptionHandler {
92 try { 145 try {
93 Map<String, Object> map = new HashMap<String, Object>(); 146 Map<String, Object> map = new HashMap<String, Object>();
94 map.put("exception", cause.getMessage()); 147 map.put("exception", cause.getMessage());
95 - Redirector.redirect(config.getExceptionPage(), map); 148 + Redirector.redirect(config.getDefaultRedirectExceptionPage(), map);
96 handled = true; 149 handled = true;
97 } catch (PageNotFoundException ex) { 150 } catch (PageNotFoundException ex) {
98 // TODO Colocar a mensagem no bundle 151 // TODO Colocar a mensagem no bundle
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/ExceptionHandlerConfigTest.java
@@ -16,12 +16,12 @@ public class ExceptionHandlerConfigTest { @@ -16,12 +16,12 @@ public class ExceptionHandlerConfigTest {
16 16
17 @Test 17 @Test
18 public void testGetExceptionPage() { 18 public void testGetExceptionPage() {
19 - assertEquals("/application_error", config.getExceptionPage()); 19 + assertEquals("/application_error", config.getDefaultRedirectExceptionPage());
20 } 20 }
21 21
22 @Test 22 @Test
23 public void testIsHandleApplicationException() { 23 public void testIsHandleApplicationException() {
24 - assertEquals(true, config.isHandleApplicationException()); 24 + assertEquals(true, config.isApplicationExceptionHandle());
25 } 25 }
26 26
27 } 27 }
impl/extension/jsf/src/test/java/proxy/FacesContextProxyServlet.java 0 → 100644
@@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
  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 proxy;
  38 +
  39 +import java.io.IOException;
  40 +
  41 +import javax.faces.context.FacesContext;
  42 +import javax.servlet.ServletException;
  43 +import javax.servlet.annotation.WebServlet;
  44 +import javax.servlet.http.HttpServlet;
  45 +import javax.servlet.http.HttpServletRequest;
  46 +import javax.servlet.http.HttpServletResponse;
  47 +
  48 +import org.apache.commons.httpclient.HttpStatus;
  49 +
  50 +import br.gov.frameworkdemoiselle.internal.proxy.FacesContextProxy;
  51 +import br.gov.frameworkdemoiselle.util.Beans;
  52 +
  53 +@WebServlet("/index")
  54 +public class FacesContextProxyServlet extends HttpServlet {
  55 +
  56 + private static final long serialVersionUID = 1L;
  57 +
  58 + private FacesContext facesContext;
  59 +
  60 + @Override
  61 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  62 + facesContext = Beans.getReference(FacesContext.class);
  63 + if (facesContext.getClass() == FacesContextProxy.class) {
  64 + response.setStatus(HttpStatus.SC_OK);
  65 + } else {
  66 + response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
  67 + }
  68 + }
  69 +}
impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java 0 → 100644
@@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
  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 proxy;
  38 +
  39 +import static org.junit.Assert.assertEquals;
  40 +
  41 +import java.io.IOException;
  42 +import java.net.URL;
  43 +
  44 +import org.apache.commons.httpclient.HttpClient;
  45 +import org.apache.commons.httpclient.HttpException;
  46 +import org.apache.commons.httpclient.HttpStatus;
  47 +import org.apache.commons.httpclient.methods.GetMethod;
  48 +import org.jboss.arquillian.container.test.api.Deployment;
  49 +import org.jboss.arquillian.junit.Arquillian;
  50 +import org.jboss.arquillian.test.api.ArquillianResource;
  51 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  52 +import org.junit.Test;
  53 +import org.junit.runner.RunWith;
  54 +
  55 +import test.Tests;
  56 +
  57 +@RunWith(Arquillian.class)
  58 +public class FacesContextProxyTest {
  59 +
  60 + @ArquillianResource
  61 + private URL deploymentUrl;
  62 +
  63 + private static final String PATH = "src/test/resources/proxy";
  64 +
  65 + @Deployment(testable = false)
  66 + public static WebArchive createDeployment() {
  67 + return Tests.createDeployment().addClass(FacesContextProxyServlet.class)
  68 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  69 + }
  70 +
  71 + @Test
  72 + public void facesContextProxy() {
  73 + HttpClient client = new HttpClient();
  74 + GetMethod method = new GetMethod(deploymentUrl + "/index");
  75 +
  76 + try {
  77 + int status = client.executeMethod(method);
  78 + assertEquals( HttpStatus.SC_OK, status);
  79 + } catch (HttpException e) {
  80 + e.printStackTrace();
  81 + } catch (IOException e) {
  82 + e.printStackTrace();
  83 + }
  84 + }
  85 +}
impl/extension/jsf/src/test/java/test/Tests.java
@@ -48,6 +48,7 @@ import br.gov.frameworkdemoiselle.annotation.NextView; @@ -48,6 +48,7 @@ import br.gov.frameworkdemoiselle.annotation.NextView;
48 import br.gov.frameworkdemoiselle.annotation.PreviousView; 48 import br.gov.frameworkdemoiselle.annotation.PreviousView;
49 import br.gov.frameworkdemoiselle.annotation.Redirect; 49 import br.gov.frameworkdemoiselle.annotation.Redirect;
50 import br.gov.frameworkdemoiselle.internal.bootstrap.JsfBootstrap; 50 import br.gov.frameworkdemoiselle.internal.bootstrap.JsfBootstrap;
  51 +import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible;
51 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; 52 import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig;
52 import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; 53 import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig;
53 import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; 54 import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl;
@@ -102,6 +103,7 @@ public final class Tests { @@ -102,6 +103,7 @@ public final class Tests {
102 .addClass(Redirector.class) 103 .addClass(Redirector.class)
103 .addClass(FileRenderer.class) 104 .addClass(FileRenderer.class)
104 .addClass(JsfSecurityConfig.class) 105 .addClass(JsfSecurityConfig.class)
  106 + .addClass(ExceptionHandlerConfigCompatible.class)
105 .addClass(ExceptionHandlerConfig.class) 107 .addClass(ExceptionHandlerConfig.class)
106 .addClass(FacesViewContextImpl.class) 108 .addClass(FacesViewContextImpl.class)
107 .addClass(AuthorizationExceptionHandlerFactory.class) 109 .addClass(AuthorizationExceptionHandlerFactory.class)
impl/extension/jsf/src/test/java/xxxx/XTest.java
1 package xxxx; 1 package xxxx;
2 2
3 -import java.net.URL; 3 +//import java.net.URL;
4 4
5 -import org.jboss.arquillian.container.test.api.Deployment;  
6 -import org.jboss.arquillian.drone.api.annotation.Drone;  
7 -import org.jboss.arquillian.junit.Arquillian;  
8 -import org.jboss.arquillian.test.api.ArquillianResource;  
9 -import org.jboss.shrinkwrap.api.spec.WebArchive;  
10 -import org.junit.Test;  
11 -import org.junit.runner.RunWith; 5 +//import org.jboss.arquillian.container.test.api.Deployment;
  6 +//import org.jboss.arquillian.drone.api.annotation.Drone;
  7 +//import org.jboss.arquillian.junit.Arquillian;
  8 +//import org.jboss.arquillian.test.api.ArquillianResource;
  9 +//import org.jboss.shrinkwrap.api.spec.WebArchive;
  10 +//import org.junit.Test;
  11 +//import org.junit.runner.RunWith;
12 12
13 -import test.Tests; 13 +//import test.Tests;
14 14
15 -import com.thoughtworks.selenium.DefaultSelenium; 15 +//import com.thoughtworks.selenium.DefaultSelenium;
16 16
17 -@RunWith(Arquillian.class) 17 +//@RunWith(Arquillian.class)
18 public class XTest { 18 public class XTest {
19 19
20 - private static final String PATH = "src/test/resources/xxx";  
21 -  
22 - @Drone  
23 - private DefaultSelenium browser;  
24 -  
25 - @ArquillianResource  
26 - private URL deploymentUrl;  
27 -  
28 - @Deployment(testable = false)  
29 - public static WebArchive createDeployment() {  
30 - return Tests.createDeployment().addClass(XServlet.class)  
31 - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");  
32 - }  
33 -  
34 - @Test  
35 - public void xxxx() {  
36 - browser.open(deploymentUrl + "/login"); 20 +// private static final String PATH = "src/test/resources/xxx";
  21 +//
  22 +// @Drone
  23 +// private DefaultSelenium browser;
  24 +//
  25 +// @ArquillianResource
  26 +// private URL deploymentUrl;
  27 +//
  28 +// @Deployment(testable = false)
  29 +// public static WebArchive createDeployment() {
  30 +// return Tests.createDeployment().addClass(XServlet.class)
  31 +// .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  32 +// }
  33 +//
  34 +// @Test
  35 +// public void xxxx() {
  36 +// browser.open(deploymentUrl + "/login");
37 37
38 // browser.type("id=xxx-input", "demo"); 38 // browser.type("id=xxx-input", "demo");
39 // browser.waitForPageToLoad("15000"); 39 // browser.waitForPageToLoad("15000");
@@ -42,5 +42,5 @@ public class XTest { @@ -42,5 +42,5 @@ public class XTest {
42 // browser.isElementPresent("xpath=//li[contains(text(), 'Welcome')]")); 42 // browser.isElementPresent("xpath=//li[contains(text(), 'Welcome')]"));
43 // assertTrue("Username should be shown!", 43 // assertTrue("Username should be shown!",
44 // browser.isElementPresent("xpath=//p[contains(text(), 'You are signed in as demo.')]")); 44 // browser.isElementPresent("xpath=//p[contains(text(), 'You are signed in as demo.')]"));
45 - } 45 +// }
46 } 46 }
impl/extension/jsf/src/test/resources/.arquillian-drone.profile
impl/extension/jsf/src/test/resources/proxy/web.xml 0 → 100644
@@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
  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 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  39 +
  40 + <listener>
  41 + <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class>
  42 + </listener>
  43 + <filter>
  44 + <filter-name>Demoiselle Servlet Filter</filter-name>
  45 + <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class>
  46 + </filter>
  47 + <filter-mapping>
  48 + <filter-name>Demoiselle Servlet Filter</filter-name>
  49 + <url-pattern>/*</url-pattern>
  50 + </filter-mapping>
  51 +
  52 + <servlet>
  53 + <servlet-name>Servlet Class</servlet-name>
  54 + <servlet-class>proxy.FacesContextProxyServlet</servlet-class>
  55 + <!-- <load-on-startup>1</load-on-startup> -->
  56 + </servlet>
  57 +
  58 + <servlet-mapping>
  59 + <servlet-name>Servlet Class</servlet-name>
  60 + <url-pattern>/index</url-pattern>
  61 + </servlet-mapping>
  62 +
  63 +</web-app>
0 \ No newline at end of file 64 \ No newline at end of file
impl/extension/servlet/src/test/java/producer/HttpServletRequestProducerTest.java 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +package producer;
  2 +
  3 +import static org.junit.Assert.assertEquals;
  4 +import static org.junit.Assert.assertTrue;
  5 +import static org.junit.Assert.fail;
  6 +
  7 +import java.net.URL;
  8 +
  9 +import javax.inject.Inject;
  10 +
  11 +import org.apache.commons.httpclient.HttpClient;
  12 +import org.apache.commons.httpclient.HttpStatus;
  13 +import org.apache.commons.httpclient.methods.GetMethod;
  14 +import org.jboss.arquillian.container.test.api.Deployment;
  15 +import org.jboss.arquillian.junit.Arquillian;
  16 +import org.jboss.arquillian.test.api.ArquillianResource;
  17 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  18 +import org.junit.Test;
  19 +import org.junit.runner.RunWith;
  20 +
  21 +import test.Tests;
  22 +import br.gov.frameworkdemoiselle.context.RequestContext;
  23 +
  24 +@RunWith(Arquillian.class)
  25 +public class HttpServletRequestProducerTest {
  26 +
  27 + private static final String PATH = "src/test/resources/producer";
  28 +
  29 + @ArquillianResource
  30 + private URL deploymentUrl;
  31 +
  32 + @Deployment(testable = false)
  33 + public static WebArchive createDeployment() {
  34 + return Tests.createDeployment().addClass(RequestServlet.class)
  35 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  36 + }
  37 +
  38 + @Test
  39 + public void createR() {
  40 + HttpClient client = new HttpClient();
  41 + GetMethod method = new GetMethod(deploymentUrl + "/requestproducer");
  42 + try {
  43 + int status = client.executeMethod(method);
  44 + assertEquals(HttpStatus.SC_OK, status);
  45 + } catch (Exception e) {
  46 + fail();
  47 + }
  48 + }
  49 +
  50 +}
impl/extension/servlet/src/test/java/producer/HttpServletResponseProducerTest.java 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +package producer;
  2 +
  3 +import static org.junit.Assert.assertEquals;
  4 +import static org.junit.Assert.assertTrue;
  5 +import static org.junit.Assert.fail;
  6 +
  7 +import java.net.URL;
  8 +
  9 +import javax.inject.Inject;
  10 +
  11 +import org.apache.commons.httpclient.HttpClient;
  12 +import org.apache.commons.httpclient.HttpStatus;
  13 +import org.apache.commons.httpclient.methods.GetMethod;
  14 +import org.jboss.arquillian.container.test.api.Deployment;
  15 +import org.jboss.arquillian.junit.Arquillian;
  16 +import org.jboss.arquillian.test.api.ArquillianResource;
  17 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  18 +import org.junit.Test;
  19 +import org.junit.runner.RunWith;
  20 +
  21 +import test.Tests;
  22 +import br.gov.frameworkdemoiselle.context.RequestContext;
  23 +
  24 +@RunWith(Arquillian.class)
  25 +public class HttpServletResponseProducerTest {
  26 +
  27 + private static final String PATH = "src/test/resources/producer";
  28 +
  29 + @ArquillianResource
  30 + private URL deploymentUrl;
  31 +
  32 + @Deployment(testable = false)
  33 + public static WebArchive createDeployment() {
  34 + return Tests.createDeployment().addClass(RequestServlet.class)
  35 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  36 + }
  37 +
  38 + @Test
  39 + public void createResponse() {
  40 + HttpClient client = new HttpClient();
  41 + GetMethod method = new GetMethod(deploymentUrl + "/responseproducer");
  42 + try {
  43 + int status = client.executeMethod(method);
  44 + assertEquals(HttpStatus.SC_OK, status);
  45 + } catch (Exception e) {
  46 + fail();
  47 + }
  48 + }
  49 +
  50 +}
impl/extension/servlet/src/test/java/producer/RequestServlet.java 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +package producer;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import javax.servlet.ServletException;
  6 +import javax.servlet.http.HttpServlet;
  7 +import javax.servlet.http.HttpServletRequest;
  8 +import javax.servlet.http.HttpServletResponse;
  9 +
  10 +import org.apache.http.HttpStatus;
  11 +
  12 +import br.gov.frameworkdemoiselle.util.Beans;
  13 +
  14 +public class RequestServlet extends HttpServlet {
  15 +
  16 + private static final long serialVersionUID = 1L;
  17 +
  18 + @Override
  19 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  20 +
  21 + HttpServletRequest httpRequest = Beans.getReference(HttpServletRequest.class);
  22 +
  23 + if (httpRequest != null) {
  24 + response.setStatus(HttpStatus.SC_OK);
  25 + } else {
  26 + response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
  27 + }
  28 + }
  29 +
  30 +}
impl/extension/servlet/src/test/java/producer/ResponseServlet.java 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +package producer;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import javax.servlet.ServletException;
  6 +import javax.servlet.http.HttpServlet;
  7 +import javax.servlet.http.HttpServletRequest;
  8 +import javax.servlet.http.HttpServletResponse;
  9 +
  10 +import org.apache.http.HttpStatus;
  11 +
  12 +import br.gov.frameworkdemoiselle.util.Beans;
  13 +
  14 +public class ResponseServlet extends HttpServlet {
  15 +
  16 + private static final long serialVersionUID = 1L;
  17 +
  18 + @Override
  19 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  20 +
  21 + HttpServletResponse httpResponse = Beans.getReference(HttpServletResponse.class);
  22 +
  23 + if (httpResponse != null) {
  24 + response.setStatus(HttpStatus.SC_OK);
  25 + } else {
  26 + response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
  27 + }
  28 + }
  29 +
  30 +}
impl/extension/servlet/src/test/java/security/SecurityServlet.java 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +package security;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import javax.inject.Inject;
  6 +import javax.servlet.ServletException;
  7 +import javax.servlet.annotation.WebServlet;
  8 +import javax.servlet.http.HttpServlet;
  9 +import javax.servlet.http.HttpServletRequest;
  10 +import javax.servlet.http.HttpServletResponse;
  11 +
  12 +import org.apache.http.HttpStatus;
  13 +
  14 +import br.gov.frameworkdemoiselle.security.Credentials;
  15 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  16 +
  17 +@WebServlet("/login")
  18 +public class SecurityServlet extends HttpServlet {
  19 +
  20 + private static final long serialVersionUID = 1L;
  21 +
  22 + @Inject
  23 + private SecurityContext securityContext;
  24 +
  25 + @Inject
  26 + private Credentials credentials;
  27 +
  28 + @Override
  29 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  30 + super.doGet(request, response);
  31 +
  32 + credentials.setUsername("users");
  33 + credentials.setPassword("users");
  34 + securityContext.login();
  35 + response.setStatus(HttpStatus.SC_OK);
  36 + }
  37 +}
impl/extension/servlet/src/test/java/security/SecurityTest.java 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +package security;
  2 +
  3 +import static org.junit.Assert.assertEquals;
  4 +import static org.junit.Assert.fail;
  5 +
  6 +import java.io.IOException;
  7 +import java.net.URL;
  8 +
  9 +import org.apache.commons.httpclient.HttpClient;
  10 +import org.apache.commons.httpclient.HttpException;
  11 +import org.apache.commons.httpclient.HttpStatus;
  12 +import org.apache.commons.httpclient.methods.GetMethod;
  13 +import org.jboss.arquillian.container.test.api.Deployment;
  14 +import org.jboss.arquillian.junit.Arquillian;
  15 +import org.jboss.arquillian.test.api.ArquillianResource;
  16 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  17 +import org.junit.Test;
  18 +import org.junit.runner.RunWith;
  19 +
  20 +import test.Tests;
  21 +
  22 +@RunWith(Arquillian.class)
  23 +public class SecurityTest {
  24 +
  25 + private static final String PATH = "src/test/resources/security";
  26 +
  27 + @ArquillianResource
  28 + private URL deploymentUrl;
  29 +
  30 + @Deployment(testable = false)
  31 + public static WebArchive createDeployment() {
  32 + return Tests.createDeployment().addClass(SecurityServlet.class)
  33 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  34 + }
  35 +
  36 + @Test
  37 + public void login() {
  38 + HttpClient client = new HttpClient();
  39 + GetMethod method = new GetMethod(deploymentUrl + "/login");
  40 + try {
  41 + int status = client.executeMethod(method);
  42 + assertEquals(HttpStatus.SC_OK, status);
  43 + } catch (HttpException e) {
  44 + fail();
  45 + } catch (IOException e) {
  46 + e.printStackTrace();
  47 + }
  48 + }
  49 +
  50 +}
impl/extension/servlet/src/test/java/xxxx/XServlet.java
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -package xxxx;  
2 -  
3 -import java.io.IOException;  
4 -  
5 -import javax.inject.Inject;  
6 -import javax.servlet.ServletException;  
7 -import javax.servlet.annotation.WebServlet;  
8 -import javax.servlet.http.HttpServlet;  
9 -import javax.servlet.http.HttpServletRequest;  
10 -import javax.servlet.http.HttpServletResponse;  
11 -  
12 -import br.gov.frameworkdemoiselle.security.Credentials;  
13 -import br.gov.frameworkdemoiselle.security.SecurityContext;  
14 -  
15 -@WebServlet("/login")  
16 -public class XServlet extends HttpServlet {  
17 -  
18 - private static final long serialVersionUID = 1L;  
19 -  
20 - @Inject  
21 - private SecurityContext securityContext;  
22 -  
23 - @Inject  
24 - private Credentials credentials;  
25 -  
26 - @Override  
27 - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
28 - super.doGet(request, response);  
29 -  
30 - System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");  
31 -  
32 - credentials.setUsername("admin");  
33 - credentials.setPassword("changeit");  
34 -  
35 - securityContext.login();  
36 - }  
37 -}  
impl/extension/servlet/src/test/java/xxxx/XTest.java
@@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
1 -package xxxx;  
2 -  
3 -import java.io.IOException;  
4 -import java.net.URL;  
5 -  
6 -import org.apache.commons.httpclient.HttpClient;  
7 -import org.apache.commons.httpclient.HttpException;  
8 -import org.apache.commons.httpclient.methods.GetMethod;  
9 -import org.jboss.arquillian.container.test.api.Deployment;  
10 -import org.jboss.arquillian.junit.Arquillian;  
11 -import org.jboss.arquillian.test.api.ArquillianResource;  
12 -import org.jboss.shrinkwrap.api.spec.WebArchive;  
13 -import org.junit.Test;  
14 -import org.junit.runner.RunWith;  
15 -  
16 -import test.Tests;  
17 -  
18 -@RunWith(Arquillian.class)  
19 -public class XTest {  
20 -  
21 - private static final String PATH = "src/test/resources/xxx";  
22 -  
23 - @ArquillianResource  
24 - private URL deploymentUrl;  
25 -  
26 - @Deployment(testable = false)  
27 - public static WebArchive createDeployment() {  
28 - return Tests.createDeployment().addClass(XServlet.class)  
29 - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");  
30 - }  
31 -  
32 - @Test  
33 - public void xxxx() {  
34 - HttpClient client = new HttpClient();  
35 - GetMethod method = new GetMethod(deploymentUrl + "/login");  
36 -  
37 - try {  
38 - int status = client.executeMethod(method);  
39 - System.out.println(status);  
40 -  
41 - } catch (HttpException e) {  
42 - e.printStackTrace();  
43 -  
44 - } catch (IOException e) {  
45 - e.printStackTrace();  
46 - }  
47 -  
48 - // browser.open(deploymentUrl + "login");  
49 -  
50 - // browser.type("id=xxx-input", "demo");  
51 - // browser.waitForPageToLoad("15000");  
52 -  
53 - // assertTrue("User should be logged in!",  
54 - // browser.isElementPresent("xpath=//li[contains(text(), 'Welcome')]"));  
55 - // assertTrue("Username should be shown!",  
56 - // browser.isElementPresent("xpath=//p[contains(text(), 'You are signed in as demo.')]"));  
57 - }  
58 -}  
impl/extension/servlet/src/test/resources/producer/web.xml 0 → 100644
@@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
  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 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  39 +
  40 + <listener>
  41 + <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class>
  42 + </listener>
  43 +
  44 + <filter>
  45 + <filter-name>Demoiselle Servlet Filter</filter-name>
  46 + <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class>
  47 + </filter>
  48 + <filter-mapping>
  49 + <filter-name>Demoiselle Servlet Filter</filter-name>
  50 + <url-pattern>/*</url-pattern>
  51 + </filter-mapping>
  52 +
  53 + <servlet>
  54 + <servlet-name>Request Class</servlet-name>
  55 + <servlet-class>producer.RequestServlet</servlet-class>
  56 + </servlet>
  57 +
  58 + <servlet-mapping>
  59 + <servlet-name>Request Class</servlet-name>
  60 + <url-pattern>/requestproducer</url-pattern>
  61 + </servlet-mapping>
  62 +
  63 + <servlet>
  64 + <servlet-name>Response xClass</servlet-name>
  65 + <servlet-class>producer.ResponseServlet</servlet-class>
  66 + </servlet>
  67 +
  68 + <servlet-mapping>
  69 + <servlet-name>Response xClass</servlet-name>
  70 + <url-pattern>/responseproducer</url-pattern>
  71 + </servlet-mapping>
  72 +</web-app>
0 \ No newline at end of file 73 \ No newline at end of file
impl/extension/servlet/src/test/resources/security/web.xml 0 → 100644
@@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
  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 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  39 +
  40 + <listener>
  41 + <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class>
  42 + </listener>
  43 +
  44 + <filter>
  45 + <filter-name>Demoiselle Servlet Filter</filter-name>
  46 + <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class>
  47 + </filter>
  48 + <filter-mapping>
  49 + <filter-name>Demoiselle Servlet Filter</filter-name>
  50 + <url-pattern>/*</url-pattern>
  51 + </filter-mapping>
  52 +
  53 +
  54 + <security-constraint>
  55 + <web-resource-collection>
  56 + <web-resource-name>myapp</web-resource-name>
  57 + <url-pattern>/\*</url-pattern>
  58 + <http-method>GET</http-method>
  59 + </web-resource-collection>
  60 + <auth-constraint>
  61 + <role-name>users</role-name>
  62 + </auth-constraint>
  63 + </security-constraint>
  64 + <login-config>
  65 + <auth-method>BASIC</auth-method>
  66 + <realm-name>default</realm-name>
  67 + </login-config>
  68 + <security-role>
  69 + <role-name>users</role-name>
  70 + </security-role>
  71 +
  72 + <servlet>
  73 + <servlet-name>Security Class</servlet-name>
  74 + <servlet-class>security.SecurityServlet</servlet-class>
  75 + </servlet>
  76 +
  77 + <servlet-mapping>
  78 + <servlet-name>Security Class</servlet-name>
  79 + <url-pattern>/login</url-pattern>
  80 + </servlet-mapping>
  81 +
  82 +
  83 +</web-app>
0 \ No newline at end of file 84 \ No newline at end of file
impl/extension/servlet/src/test/resources/xxx/web.xml
@@ -1,52 +0,0 @@ @@ -1,52 +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 -<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
38 - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">  
39 -  
40 - <listener>  
41 - <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class>  
42 - </listener>  
43 - <filter>  
44 - <filter-name>Demoiselle Servlet Filter</filter-name>  
45 - <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class>  
46 - </filter>  
47 - <filter-mapping>  
48 - <filter-name>Demoiselle Servlet Filter</filter-name>  
49 - <url-pattern>/*</url-pattern>  
50 - </filter-mapping>  
51 -  
52 -</web-app>  
53 \ No newline at end of file 0 \ No newline at end of file