Updated Branches: refs/heads/master 776bfcff0 -> b1fe60612
First version of the new Servlet module Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/377fc6ee Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/377fc6ee Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/377fc6ee Branch: refs/heads/master Commit: 377fc6ee67086509d6986a5b30fa7f57e6505523 Parents: 776bfcf Author: Christian Kaltepoth <christ...@kaltepoth.de> Authored: Wed May 22 07:05:52 2013 +0200 Committer: Christian Kaltepoth <christ...@kaltepoth.de> Committed: Thu Jun 13 06:53:28 2013 +0200 ---------------------------------------------------------------------- deltaspike/modules/pom.xml | 1 + deltaspike/modules/servlet/api/pom.xml | 49 +++++++++ .../deltaspike/servlet/api/Destroyed.java | 43 ++++++++ .../deltaspike/servlet/api/Initialized.java | 43 ++++++++ .../org/apache/deltaspike/servlet/api/Web.java | 43 ++++++++ .../servlet/api/literal/DestroyedLiteral.java | 35 ++++++ .../servlet/api/literal/InitializedLiteral.java | 35 ++++++ .../servlet/api/literal/WebLiteral.java | 35 ++++++ deltaspike/modules/servlet/impl/pom.xml | 66 +++++++++++ .../servlet/impl/ServletEventBridgeFilter.java | 83 ++++++++++++++ .../impl/src/main/resources/META-INF/beans.xml | 4 + .../main/resources/META-INF/web-fragment.xml | 24 ++++ .../test/servlet/impl/Deployments.java | 76 +++++++++++++ .../impl/event/RequestResponseEventsTest.java | 110 +++++++++++++++++++ .../impl/event/ServletEventObserver.java | 73 ++++++++++++ deltaspike/modules/servlet/pom.xml | 53 +++++++++ deltaspike/parent/pom.xml | 14 +++ 17 files changed, 787 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/pom.xml b/deltaspike/modules/pom.xml index 63f038c..ad3f446 100644 --- a/deltaspike/modules/pom.xml +++ b/deltaspike/modules/pom.xml @@ -37,6 +37,7 @@ <modules> <module>security</module> <module>jpa</module> + <module>servlet</module> <module>jsf</module> <module>partial-bean</module> <module>beanval</module> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/pom.xml b/deltaspike/modules/servlet/api/pom.xml new file mode 100644 index 0000000..6f37996 --- /dev/null +++ b/deltaspike/modules/servlet/api/pom.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>servlet-module-project</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + </parent> + + <artifactId>deltaspike-servlet-module-api</artifactId> + + <name>Apache DeltaSpike Servlet-Module API</name> + + <dependencies> + + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_2.5_spec</artifactId> + <scope>provided</scope> + </dependency> + + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Destroyed.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Destroyed.java b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Destroyed.java new file mode 100644 index 0000000..1f55133 --- /dev/null +++ b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Destroyed.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * @author Christian Kaltepoth + */ +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RUNTIME) +@Documented +public @interface Destroyed +{ + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Initialized.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Initialized.java b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Initialized.java new file mode 100644 index 0000000..2c487ce --- /dev/null +++ b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Initialized.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * @author Christian Kaltepoth + */ +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RUNTIME) +@Documented +public @interface Initialized +{ + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Web.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Web.java b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Web.java new file mode 100644 index 0000000..a8f51c7 --- /dev/null +++ b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/Web.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * @author Christian Kaltepoth + */ +@Qualifier +@Target({ TYPE, METHOD, PARAMETER, FIELD }) +@Retention(RUNTIME) +@Documented +public @interface Web +{ + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/DestroyedLiteral.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/DestroyedLiteral.java b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/DestroyedLiteral.java new file mode 100644 index 0000000..dc8dd01 --- /dev/null +++ b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/DestroyedLiteral.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.api.literal; + +import javax.enterprise.util.AnnotationLiteral; + +import org.apache.deltaspike.servlet.api.Destroyed; + +/** + * @author Christian Kaltepoth + */ +public class DestroyedLiteral extends AnnotationLiteral<Destroyed> implements Destroyed +{ + + public static final Destroyed INSTANCE = new DestroyedLiteral(); + + private static final long serialVersionUID = 8310730593030223981L; + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/InitializedLiteral.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/InitializedLiteral.java b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/InitializedLiteral.java new file mode 100644 index 0000000..a1fb5c2 --- /dev/null +++ b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/InitializedLiteral.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.api.literal; + +import javax.enterprise.util.AnnotationLiteral; + +import org.apache.deltaspike.servlet.api.Initialized; + +/** + * @author Christian Kaltepoth + */ +public class InitializedLiteral extends AnnotationLiteral<Initialized> implements Initialized +{ + + public static final Initialized INSTANCE = new InitializedLiteral(); + + private static final long serialVersionUID = 2392444150652655120L; + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/WebLiteral.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/WebLiteral.java b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/WebLiteral.java new file mode 100644 index 0000000..ab7d763 --- /dev/null +++ b/deltaspike/modules/servlet/api/src/main/java/org/apache/deltaspike/servlet/api/literal/WebLiteral.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.api.literal; + +import javax.enterprise.util.AnnotationLiteral; + +import org.apache.deltaspike.servlet.api.Web; + +/** + * @author Christian Kaltepoth + */ +public class WebLiteral extends AnnotationLiteral<Web> implements Web +{ + + public static final Web INSTANCE = new WebLiteral(); + + private static final long serialVersionUID = -3432965578489930193L; + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/pom.xml b/deltaspike/modules/servlet/impl/pom.xml new file mode 100644 index 0000000..03ac17c --- /dev/null +++ b/deltaspike/modules/servlet/impl/pom.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>servlet-module-project</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + </parent> + + <artifactId>deltaspike-servlet-module-impl</artifactId> + + <name>Apache DeltaSpike Servlet-Module Impl</name> + + <dependencies> + + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-impl</artifactId> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-servlet-module-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_2.5_spec</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.2.5</version> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/ServletEventBridgeFilter.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/ServletEventBridgeFilter.java b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/ServletEventBridgeFilter.java new file mode 100644 index 0000000..f0763dc --- /dev/null +++ b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/ServletEventBridgeFilter.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.servlet.impl; + +import java.io.IOException; +import java.lang.annotation.Annotation; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.apache.deltaspike.core.api.provider.BeanManagerProvider; +import org.apache.deltaspike.servlet.api.literal.DestroyedLiteral; +import org.apache.deltaspike.servlet.api.literal.InitializedLiteral; +import org.apache.deltaspike.servlet.api.literal.WebLiteral; + +/** + * @author Christian Kaltepoth + */ +public class ServletEventBridgeFilter implements Filter +{ + + @Override + public void init(FilterConfig config) throws ServletException + { + // nothing yet + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, + ServletException + { + + fireEvent(request, WebLiteral.INSTANCE, InitializedLiteral.INSTANCE); + fireEvent(response, WebLiteral.INSTANCE, InitializedLiteral.INSTANCE); + + try + { + chain.doFilter(request, response); + } + finally + { + fireEvent(request, WebLiteral.INSTANCE, DestroyedLiteral.INSTANCE); + fireEvent(response, WebLiteral.INSTANCE, DestroyedLiteral.INSTANCE); + } + + } + + @Override + public void destroy() + { + // nothing yet + } + + protected void fireEvent(Object event, Annotation... qualifier) + { + /* + * No need to cache the BeanManager reference because the providers already does this on a context class loader + * level. + */ + BeanManagerProvider.getInstance().getBeanManager().fireEvent(event, qualifier); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/src/main/resources/META-INF/beans.xml b/deltaspike/modules/servlet/impl/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..0ca3a64 --- /dev/null +++ b/deltaspike/modules/servlet/impl/src/main/resources/META-INF/beans.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd"> +</beans> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/src/main/resources/META-INF/web-fragment.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/src/main/resources/META-INF/web-fragment.xml b/deltaspike/modules/servlet/impl/src/main/resources/META-INF/web-fragment.xml new file mode 100644 index 0000000..255ae66 --- /dev/null +++ b/deltaspike/modules/servlet/impl/src/main/resources/META-INF/web-fragment.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-fragment version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"> + + <distributable /> + + <ordering> + <before> + <others /> + </before> + </ordering> + + <filter> + <display-name>ServletEventBridgeFilter</display-name> + <filter-name>ServletEventBridgeFilter</filter-name> + <filter-class>org.apache.deltaspike.servlet.impl.ServletEventBridgeFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>ServletEventBridgeFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + +</web-fragment> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/Deployments.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/Deployments.java b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/Deployments.java new file mode 100644 index 0000000..a059588 --- /dev/null +++ b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/Deployments.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.test.servlet.impl; + +import java.util.Arrays; +import java.util.Collection; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.importer.ExplodedImporter; +import org.jboss.shrinkwrap.api.spec.JavaArchive; + +public class Deployments +{ + + public static Collection<JavaArchive> getDeltaSpikeCoreArchives() + { + + JavaArchive coreApiArchive = ShrinkWrap.create(JavaArchive.class) + .as(ExplodedImporter.class) + .importDirectory("../../../core/api/target/classes") + .as(JavaArchive.class); + + JavaArchive coreImplArchive = ShrinkWrap.create(JavaArchive.class) + .as(ExplodedImporter.class) + .importDirectory("../../../core/impl/target/classes") + .as(JavaArchive.class); + + return Arrays.asList(coreApiArchive, coreImplArchive); + + } + + public static Collection<JavaArchive> getDeltaSpikeServletArchives() + { + + JavaArchive servletApiArchive = ShrinkWrap.create(JavaArchive.class) + .as(ExplodedImporter.class) + .importDirectory("../api/target/classes") + .as(JavaArchive.class); + + JavaArchive servletImplArchive = ShrinkWrap.create(JavaArchive.class) + .as(ExplodedImporter.class) + .importDirectory("../impl/target/classes") + .as(JavaArchive.class); + + return Arrays.asList(servletApiArchive, servletImplArchive); + + } + + /** + * @return + */ + public static JavaArchive getTestSupportArchives() + { + return ShrinkWrap.create(JavaArchive.class, "utils.jar") + .addPackages(true, "org.apache.http") + .addPackages(true, "org.apache.deltaspike.test") + ; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java new file mode 100644 index 0000000..2f6e347 --- /dev/null +++ b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/RequestResponseEventsTest.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.test.servlet.impl.event; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.net.URL; + +import javax.inject.Inject; + +import org.apache.deltaspike.test.category.WebProfileCategory; +import org.apache.deltaspike.test.servlet.impl.Deployments; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +/** + * @author Christian Kaltepoth + */ +@RunWith(Arquillian.class) +@Category(WebProfileCategory.class) +public class RequestResponseEventsTest +{ + + @Deployment + public static WebArchive getDeployment() + { + return ShrinkWrap.create(WebArchive.class, "test.war") + .addAsLibraries(Deployments.getDeltaSpikeCoreArchives()) + .addAsLibraries(Deployments.getDeltaSpikeServletArchives()) + .addAsLibraries(Deployments.getTestSupportArchives()) + .addClass(ServletEventObserver.class) + .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml") + .addAsWebResource(new StringAsset("foobar"), "foobar.txt"); + } + + @Inject + private ServletEventObserver observer; + + @Test + @RunAsClient + @InSequence(2) + public void sendRequest(@ArquillianResource URL contextPath) throws Exception + { + String url = new URL(contextPath, "foobar.txt").toString(); + HttpResponse response = new DefaultHttpClient().execute(new HttpGet(url)); + assertEquals(200, response.getStatusLine().getStatusCode()); + } + + @Test + @InSequence(3) + public void shouldReceiveRequestInitializedEvent() + { + assertTrue("Didn't receive expected event", + observer.getEventLog().contains("Initialized HttpServletRequest: /test/foobar.txt")); + } + + @Test + @InSequence(3) + public void shouldReceiveResponseInitializedEvent() + { + assertTrue("Didn't receive expected event", + observer.getEventLog().contains("Initialized HttpServletResponse")); + } + + @Test + @InSequence(3) + public void shouldReceiveRequestDestroyedEvent() + { + assertTrue("Didn't receive expected event", + observer.getEventLog().contains("Destroyed HttpServletRequest: /test/foobar.txt")); + } + + @Test + @InSequence(3) + public void shouldReceiveResponseDestroyedEvent() + { + assertTrue("Didn't receive expected event", + observer.getEventLog().contains("Destroyed HttpServletResponse")); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java new file mode 100644 index 0000000..3f8b502 --- /dev/null +++ b/deltaspike/modules/servlet/impl/src/test/java/org/apache/deltaspike/test/servlet/impl/event/ServletEventObserver.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.test.servlet.impl.event; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.deltaspike.servlet.api.Destroyed; +import org.apache.deltaspike.servlet.api.Initialized; +import org.apache.deltaspike.servlet.api.Web; + +/** + * @author Christian Kaltepoth + */ +@ApplicationScoped +public class ServletEventObserver +{ + + private final List<String> eventLog = new ArrayList<String>(); + + public void requestInitialized(@Observes @Web @Initialized HttpServletRequest request) + { + eventLog.add("Initialized HttpServletRequest: " + request.getRequestURI()); + } + + public void responseInitialized(@Observes @Web @Initialized HttpServletResponse response) + { + eventLog.add("Initialized HttpServletResponse"); + } + + public void requestDestroyed(@Observes @Web @Destroyed HttpServletRequest request) + { + eventLog.add("Destroyed HttpServletRequest: " + request.getRequestURI()); + } + + public void responseDestroyed(@Observes @Web @Destroyed HttpServletResponse response) + { + eventLog.add("Destroyed HttpServletResponse"); + } + + public int getEventCount() + { + return eventLog.size(); + } + + public List<String> getEventLog() + { + return Collections.unmodifiableList(eventLog); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/modules/servlet/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/servlet/pom.xml b/deltaspike/modules/servlet/pom.xml new file mode 100644 index 0000000..88a9c2e --- /dev/null +++ b/deltaspike/modules/servlet/pom.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>modules-project</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + </parent> + + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>servlet-module-project</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>Apache DeltaSpike Servlet-Module</name> + + <modules> + <module>api</module> + <module>impl</module> + </modules> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_2.5_spec</artifactId> + <version>1.2</version> + <scope>provided</scope> + </dependency> + </dependencies> + </dependencyManagement> + +</project> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/377fc6ee/deltaspike/parent/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/parent/pom.xml b/deltaspike/parent/pom.xml index fa04d09..9ac1d66 100644 --- a/deltaspike/parent/pom.xml +++ b/deltaspike/parent/pom.xml @@ -497,6 +497,20 @@ <dependency> <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-servlet-module-api</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-servlet-module-impl</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> <artifactId>deltaspike-jsf-module-api</artifactId> <version>${project.version}</version> <scope>compile</scope>