├── .gitignore
├── api
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── jboss
│ │ └── seam
│ │ └── servlet
│ │ ├── ServerInfo.java
│ │ ├── ServletRequestContext.java
│ │ ├── WebApplication.java
│ │ ├── WebRequest.java
│ │ ├── event
│ │ ├── Destroyed.java
│ │ ├── DidActivate.java
│ │ ├── HttpMethod.java
│ │ ├── Initialized.java
│ │ ├── Path.java
│ │ ├── Started.java
│ │ ├── WillPassivate.java
│ │ └── literal
│ │ │ ├── DestroyedLiteral.java
│ │ │ ├── DidActivateLiteral.java
│ │ │ ├── HttpMethodLiteral.java
│ │ │ ├── InitializedLiteral.java
│ │ │ ├── PathLiteral.java
│ │ │ ├── StartedLiteral.java
│ │ │ └── WillPassivateLiteral.java
│ │ ├── exception
│ │ └── handler
│ │ │ ├── SendErrorPage.java
│ │ │ └── SendHttpError.java
│ │ ├── http
│ │ ├── ContextPath.java
│ │ ├── CookieParam.java
│ │ ├── DefaultValue.java
│ │ ├── HeaderParam.java
│ │ ├── HttpServletRequestContext.java
│ │ ├── HttpSessionStatus.java
│ │ ├── RedirectBuilder.java
│ │ ├── RequestParam.java
│ │ └── literal
│ │ │ ├── CookieParamLiteral.java
│ │ │ ├── HeaderParamLiteral.java
│ │ │ └── RequestParamLiteral.java
│ │ └── literal
│ │ └── WebRequestLiteral.java
│ └── resources
│ └── META-INF
│ └── beans.xml
├── building.txt
├── dist
├── pom.xml
└── src
│ └── main
│ └── assembly
│ ├── assembly.xml
│ ├── license.txt
│ ├── notice.txt
│ └── readme.txt
├── docs
├── pom.xml
├── readme.md
└── src
│ └── main
│ ├── assembly
│ └── assembly.xml
│ └── docbook
│ └── en-US
│ ├── author_group.xml
│ ├── book_info.xml
│ ├── master.xml
│ ├── servlet-beanmanager.xml
│ ├── servlet-events.xml
│ ├── servlet-exception_handling.xml
│ ├── servlet-injectable_refs.xml
│ ├── servlet-installation.xml
│ └── servlet-introduction.xml
├── impl
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── jboss
│ │ │ └── seam
│ │ │ └── servlet
│ │ │ ├── ImplicitServletObjectsProducer.java
│ │ │ ├── ServletExtension.java
│ │ │ ├── beanManager
│ │ │ └── ServletContextAttributeProvider.java
│ │ │ ├── config
│ │ │ └── CharacterEncodingConfig.java
│ │ │ ├── event
│ │ │ ├── AbstractServletEventBridge.java
│ │ │ ├── ImplicitServletObjectsHolder.java
│ │ │ ├── ServletEventBridgeFilter.java
│ │ │ ├── ServletEventBridgeListener.java
│ │ │ └── ServletEventBridgeServlet.java
│ │ │ ├── exception
│ │ │ ├── CatchExceptionFilter.java
│ │ │ └── handler
│ │ │ │ ├── ExceptionResponseServiceHandler.java
│ │ │ │ └── ExceptionResponses.java
│ │ │ ├── http
│ │ │ ├── CookieParamProducer.java
│ │ │ ├── HeaderParamProducer.java
│ │ │ ├── ImplicitHttpServletObjectsProducer.java
│ │ │ ├── RedirectBuilderImpl.java
│ │ │ ├── RequestParamProducer.java
│ │ │ ├── TemporalConverters.java
│ │ │ └── TypedParamValue.java
│ │ │ ├── logging
│ │ │ ├── TypedMessageBundle.java
│ │ │ ├── TypedMessageBundleAndLoggerExtension.java
│ │ │ ├── TypedMessageBundleAndLoggerProducers.java
│ │ │ └── TypedMessageLogger.java
│ │ │ └── support
│ │ │ ├── ServletLogger.java
│ │ │ └── ServletMessages.java
│ └── resources
│ │ └── META-INF
│ │ ├── beans.xml
│ │ ├── services
│ │ ├── javax.enterprise.inject.spi.Extension
│ │ └── org.jboss.weld.extensions.beanManager.BeanManagerProvider
│ │ └── web-fragment.xml
│ └── test
│ ├── java
│ └── org
│ │ └── jboss
│ │ └── seam
│ │ └── servlet
│ │ └── test
│ │ ├── beanManager
│ │ └── ServletContextAttributeProviderTest.java
│ │ ├── event
│ │ ├── ServletEventBridgeTest.java
│ │ └── ServletEventBridgeTestHelper.java
│ │ ├── http
│ │ ├── RequestParamProducerTest.java
│ │ └── Suit.java
│ │ └── util
│ │ └── Deployments.java
│ └── resources
│ └── arquillian.xml
├── pom.xml
├── readme.md
└── settings.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | .classpath
3 | .project
4 | .settings
5 | *.iml
6 | *.ipr
7 | *.iws
8 | *.sw?
9 | transaction.log
10 |
--------------------------------------------------------------------------------
/api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 | 4.0.0
20 |
21 |
22 | org.jboss.seam.servlet
23 | seam-servlet-parent
24 | 3.1.0-SNAPSHOT
25 | ../pom.xml
26 |
27 |
28 | seam-servlet-api
29 |
30 | jar
31 | Seam Servlet API
32 |
33 | ${project.parent.url}
34 |
35 |
36 |
37 | org.jboss.seam.solder
38 | seam-solder-api
39 | provided
40 |
41 |
42 |
43 | org.jboss.spec.javax.servlet
44 | jboss-servlet-api_3.0_spec
45 | provided
46 |
47 |
48 | javax.enterprise
49 | cdi-api
50 | provided
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | maven-surefire-plugin
59 |
60 | true
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/ServerInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.METHOD;
27 | import static java.lang.annotation.ElementType.PARAMETER;
28 | import static java.lang.annotation.ElementType.TYPE;
29 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
30 |
31 | /**
32 | * Qualifies the server info string.
33 | *
34 | * @author Dan Allen
35 | */
36 | @Qualifier
37 | @Target({TYPE, METHOD, PARAMETER, FIELD})
38 | @Retention(RUNTIME)
39 | @Documented
40 | public @interface ServerInfo {
41 | }
42 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/ServletRequestContext.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.ServletRequest;
5 | import javax.servlet.ServletResponse;
6 | import javax.servlet.http.HttpServletRequest;
7 |
8 | import org.jboss.seam.solder.core.Veto;
9 |
10 | /**
11 | * Encapsulates the {@link ServletRequest} and {@link ServletResponse} for the current request and dually provides access to the
12 | * {@link ServletContext}, which is accessed from the {@link HttpServletRequest} object.
13 | *
14 | * @author Dan Allen
15 | */
16 | @Veto
17 | public class ServletRequestContext {
18 | private ServletRequest request;
19 |
20 | private ServletResponse response;
21 |
22 | // required for scoped producer
23 | public ServletRequestContext() {
24 | }
25 |
26 | public ServletRequestContext(ServletRequest request, ServletResponse response) {
27 | this.request = request;
28 | this.response = response;
29 | }
30 |
31 | public ServletRequestContext(ServletRequest request) {
32 | this(request, null);
33 | }
34 |
35 | public ServletContext getServletContext() {
36 | return request.getServletContext();
37 | }
38 |
39 | public ServletRequest getRequest() {
40 | return request;
41 | }
42 |
43 | public ServletResponse getResponse() {
44 | return response;
45 | }
46 |
47 | @Override
48 | public int hashCode() {
49 | final int prime = 31;
50 | int result = 1;
51 | result = prime * result + ((request == null) ? 0 : request.hashCode());
52 | result = prime * result + ((response == null) ? 0 : response.hashCode());
53 | return result;
54 | }
55 |
56 | /**
57 | * If the request and response on both objects map to the same Java identity, respectively, then consider these two objects
58 | * to be equivalent.
59 | */
60 | @Override
61 | public boolean equals(Object obj) {
62 | if (this == obj) {
63 | return true;
64 | }
65 |
66 | if (!(obj instanceof ServletRequestContext)) {
67 | return false;
68 | }
69 |
70 | ServletRequestContext other = (ServletRequestContext) obj;
71 | if (request != other.request) {
72 | return false;
73 | }
74 |
75 | if (response != other.response) {
76 | return false;
77 | }
78 |
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/WebApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet;
18 |
19 | import javax.servlet.ServletContext;
20 |
21 | /**
22 | * Information about the current web application. This object can be used to observe the startup and shutdown events without
23 | * tying to the servlet API.
24 | *
25 | * @author Dan Allen
26 | */
27 | public class WebApplication {
28 | private final String name;
29 | private final String contextPath;
30 | private final String serverInfo;
31 | private final long startTime;
32 |
33 | public WebApplication(ServletContext ctx) {
34 | this(ctx.getServletContextName(), ctx.getContextPath(), ctx.getServerInfo());
35 | }
36 |
37 | public WebApplication(String name, String contextPath, String serverInfo) {
38 | this.name = name;
39 | this.contextPath = contextPath;
40 | this.serverInfo = serverInfo;
41 | this.startTime = System.currentTimeMillis();
42 | }
43 |
44 | public String getName() {
45 | return name;
46 | }
47 |
48 | public String getContextPath() {
49 | return contextPath;
50 | }
51 |
52 | public String getServerInfo() {
53 | return serverInfo;
54 | }
55 |
56 | public long getStartTime() {
57 | return startTime;
58 | }
59 |
60 | public long getRunningTime() {
61 | return System.currentTimeMillis() - startTime;
62 | }
63 |
64 | @Override
65 | public int hashCode() {
66 | final int prime = 31;
67 | int result = 1;
68 | result = prime * result + ((contextPath == null) ? 0 : contextPath.hashCode());
69 | result = prime * result + ((name == null) ? 0 : name.hashCode());
70 | result = prime * result + ((serverInfo == null) ? 0 : serverInfo.hashCode());
71 | return result;
72 | }
73 |
74 | @Override
75 | public boolean equals(Object obj) {
76 | if (this == obj) {
77 | return true;
78 | }
79 |
80 | if (!(obj instanceof WebApplication)) {
81 | return false;
82 | }
83 |
84 | WebApplication other = (WebApplication) obj;
85 | if (contextPath == null) {
86 | if (other.contextPath != null) {
87 | return false;
88 | }
89 | } else if (!contextPath.equals(other.contextPath)) {
90 | return false;
91 | }
92 |
93 | if (name == null) {
94 | if (other.name != null) {
95 | return false;
96 | }
97 | } else if (!name.equals(other.name)) {
98 | return false;
99 | }
100 |
101 | if (serverInfo == null) {
102 | if (other.serverInfo != null) {
103 | return false;
104 | }
105 | } else if (!serverInfo.equals(other.serverInfo)) {
106 | return false;
107 | }
108 |
109 | return true;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/WebRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.METHOD;
27 | import static java.lang.annotation.ElementType.PARAMETER;
28 | import static java.lang.annotation.ElementType.TYPE;
29 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
30 |
31 | /**
32 | * A qualifier used to distinguish resources (such as exception handlers) that are appropriate for an HTTP request not handled
33 | * by a more specific Servlet (such as JAX-RS or JSF).
34 | *
35 | * @author Dan Allen
36 | */
37 | @Qualifier
38 | @Target({TYPE, METHOD, PARAMETER, FIELD})
39 | @Retention(RUNTIME)
40 | @Documented
41 | public @interface WebRequest {
42 | }
43 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/Destroyed.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.PARAMETER;
27 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
28 |
29 | /**
30 | * Qualifies observer method parameters to select events that fire when HTTP artifacts are being destroyed.
31 | *
32 | * The event parameter can be a {@link javax.servlet.ServletContext}, {@link javax.servlet.ServletRequest} or a
33 | * {@link javax.servlet.http.HttpSession}.
34 | *
35 | * @author Nicklas Karlsson
36 | */
37 | @Qualifier
38 | @Target({FIELD, PARAMETER})
39 | @Retention(RUNTIME)
40 | @Documented
41 | public @interface Destroyed {
42 | }
43 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/DidActivate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.PARAMETER;
27 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
28 |
29 | /**
30 | * Qualifies observer method parameters to select events that fire when HTTP sessions are activated.
31 | *
32 | * The event parameter is an {@link javax.servlet.http.HttpSession}
33 | *
34 | * @author Nicklas Karlsson
35 | */
36 | @Qualifier
37 | @Target({FIELD, PARAMETER})
38 | @Retention(RUNTIME)
39 | @Documented
40 | public @interface DidActivate {
41 | }
42 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/HttpMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.PARAMETER;
27 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
28 |
29 | /**
30 | * Qualifies observer methods to select HTTP lifecycle events for a particular HTTP method.
31 | *
32 | * @author Dan Allen
33 | */
34 | @Qualifier
35 | @Target({PARAMETER, FIELD})
36 | @Retention(RUNTIME)
37 | @Documented
38 | public @interface HttpMethod {
39 | String value();
40 | }
41 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/Initialized.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 | import javax.servlet.ServletContextEvent;
25 | import javax.servlet.ServletRequestEvent;
26 |
27 | import static java.lang.annotation.ElementType.FIELD;
28 | import static java.lang.annotation.ElementType.PARAMETER;
29 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
30 |
31 | /**
32 | * Qualifies observer method parameters to select events that fire when HTTP artifacts are being initialized.
33 | *
34 | * The event parameter can be a {@link ServletContextEvent} or a {@link ServletRequestEvent}.
35 | *
36 | * @author Nicklas Karlsson
37 | */
38 | @Qualifier
39 | @Target({FIELD, PARAMETER})
40 | @Retention(RUNTIME)
41 | @Documented
42 | public @interface Initialized {
43 | }
44 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/Path.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.event;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.Target;
6 |
7 | import javax.inject.Qualifier;
8 |
9 | import static java.lang.annotation.ElementType.FIELD;
10 | import static java.lang.annotation.ElementType.PARAMETER;
11 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
12 |
13 | /**
14 | * Qualifies observer methods to select HTTP lifecycle events for a particular Servlet path. A leading '/' should not be used in
15 | * the value as base URIs are treated as if they ended in '/'.
16 | *
17 | * @author Dan Allen
18 | */
19 | @Qualifier
20 | @Target({PARAMETER, FIELD})
21 | @Retention(RUNTIME)
22 | @Documented
23 | public @interface Path {
24 | String value();
25 | }
26 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/Started.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import org.jboss.seam.servlet.WebApplication;
26 |
27 | import static java.lang.annotation.ElementType.FIELD;
28 | import static java.lang.annotation.ElementType.PARAMETER;
29 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
30 |
31 | /**
32 | * Qualifies observer method parameters to select the event fired when the web application has started.
33 | *
34 | * Intented to be used with the event parameter {@link WebApplication}
35 | *
36 | * @author Dan Allen
37 | */
38 | @Qualifier
39 | @Target({FIELD, PARAMETER})
40 | @Retention(RUNTIME)
41 | @Documented
42 | public @interface Started {
43 | }
44 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/WillPassivate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.PARAMETER;
27 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
28 |
29 | /**
30 | * Qualifies observer method parameters to select events that fire when HTTP sessions are passivated.
31 | *
32 | * The event parameter is an {@link javax.servlet.http.HttpSession}
33 | *
34 | * @author Nicklas Karlsson
35 | */
36 | @Qualifier
37 | @Target({FIELD, PARAMETER})
38 | @Retention(RUNTIME)
39 | @Documented
40 | public @interface WillPassivate {
41 | }
42 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/DestroyedLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.event.Destroyed;
22 |
23 | /**
24 | * @author Nicklas Karlsson
25 | */
26 | public class DestroyedLiteral extends AnnotationLiteral implements Destroyed {
27 | private static final long serialVersionUID = -6004283843896030539L;
28 | public static final Destroyed INSTANCE = new DestroyedLiteral();
29 | }
30 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/DidActivateLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.event.DidActivate;
22 |
23 | /**
24 | * @author Nicklas Karlsson
25 | */
26 | public class DidActivateLiteral extends AnnotationLiteral implements DidActivate {
27 | private static final long serialVersionUID = -7542956885080035383L;
28 | public static final DidActivate INSTANCE = new DidActivateLiteral();
29 | }
30 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/HttpMethodLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | *
4 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
5 | * by the @authors tag. See the copyright.txt in the distribution for a
6 | * full listing of individual contributors.
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package org.jboss.seam.servlet.event.literal;
21 |
22 | import javax.enterprise.util.AnnotationLiteral;
23 |
24 | import org.jboss.seam.servlet.event.HttpMethod;
25 |
26 | /**
27 | * @author Dan Allen
28 | */
29 | public class HttpMethodLiteral extends AnnotationLiteral implements HttpMethod {
30 | private final String value;
31 |
32 | public HttpMethodLiteral(String value) {
33 | if (value == null || value.length() == 0) {
34 | this.value = "GET";
35 | } else {
36 | this.value = value;
37 | }
38 | }
39 |
40 | public String value() {
41 | return value;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/InitializedLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.event.Initialized;
22 |
23 | /**
24 | * @author Nicklas Karlsson
25 | */
26 | public class InitializedLiteral extends AnnotationLiteral implements Initialized {
27 | private static final long serialVersionUID = 3140645410138297667L;
28 | public static final Initialized INSTANCE = new InitializedLiteral();
29 | }
30 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/PathLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.event.Path;
22 |
23 | /**
24 | * @author Dan Allen
25 | */
26 | public class PathLiteral extends AnnotationLiteral implements Path {
27 | private static final long serialVersionUID = -6004283842766030539L;
28 | private final String value;
29 |
30 | public String value() {
31 | return value;
32 | }
33 |
34 | public PathLiteral(final String value) {
35 | if (value != null) {
36 | this.value = (value.indexOf('/') == 0 ? value.substring(1) : value);
37 | } else {
38 | this.value = "";
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/StartedLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.event.Started;
22 |
23 | /**
24 | * @author Dan Allen
25 | */
26 | public class StartedLiteral extends AnnotationLiteral implements Started {
27 | private static final long serialVersionUID = 3140645410138322634L;
28 | public static final Started INSTANCE = new StartedLiteral();
29 | }
30 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/event/literal/WillPassivateLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.event.WillPassivate;
22 |
23 | /**
24 | * @author Nicklas Karlsson
25 | */
26 | public class WillPassivateLiteral extends AnnotationLiteral implements WillPassivate {
27 | private static final long serialVersionUID = 1008760745325853191L;
28 | public static final WillPassivate INSTANCE = new WillPassivateLiteral();
29 | }
30 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/exception/handler/SendErrorPage.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.exception.handler;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.METHOD)
10 | public @interface SendErrorPage {
11 | String value();
12 |
13 | boolean redirect() default false;
14 | }
15 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/exception/handler/SendHttpError.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.exception.handler;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | @Retention(RetentionPolicy.RUNTIME)
11 | @Target(ElementType.METHOD)
12 | public @interface SendHttpError {
13 | int status() default HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
14 |
15 | String message() default "";
16 |
17 | boolean useExceptionMessageAsDefault() default true;
18 | }
19 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/ContextPath.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.METHOD;
27 | import static java.lang.annotation.ElementType.PARAMETER;
28 | import static java.lang.annotation.ElementType.TYPE;
29 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
30 |
31 | /**
32 | * Qualifies the context path string.
33 | *
34 | * @author Dan Allen
35 | */
36 | @Qualifier
37 | @Target({TYPE, METHOD, PARAMETER, FIELD})
38 | @Retention(RUNTIME)
39 | @Documented
40 | public @interface ContextPath {
41 | }
42 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/CookieParam.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.enterprise.util.Nonbinding;
24 | import javax.inject.Qualifier;
25 |
26 | import static java.lang.annotation.ElementType.FIELD;
27 | import static java.lang.annotation.ElementType.METHOD;
28 | import static java.lang.annotation.ElementType.PARAMETER;
29 | import static java.lang.annotation.ElementType.TYPE;
30 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
31 |
32 | /**
33 | * Qualifies injection points that should have their values fetched from a corresponding Cookie.
34 | *
35 | *
57 | * Because the bean produced is dependent-scoped, use of this annotation on class fields and bean properties is only safe for
58 | * request-scoped beans. Beans with longer scopes should wrap this bean in a provider and retrieve the value on demand.
59 | *
69 | *
70 | * @author Dan Allen
71 | */
72 | @Qualifier
73 | @Target({TYPE, METHOD, PARAMETER, FIELD})
74 | @Retention(RUNTIME)
75 | @Documented
76 | public @interface CookieParam {
77 | @Nonbinding
78 | public String value() default "";
79 | }
80 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/DefaultValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import static java.lang.annotation.ElementType.FIELD;
24 | import static java.lang.annotation.ElementType.METHOD;
25 | import static java.lang.annotation.ElementType.PARAMETER;
26 | import static java.lang.annotation.ElementType.TYPE;
27 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
28 |
29 | /**
30 | * Sets the default value for an injected HTTP request, cookie, or header parameter.
31 | *
32 | * @author Nicklas Karlsson
33 | */
34 | @Target({TYPE, METHOD, PARAMETER, FIELD})
35 | @Retention(RUNTIME)
36 | @Documented
37 | public @interface DefaultValue {
38 | public String value();
39 | }
40 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/HeaderParam.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.enterprise.util.Nonbinding;
24 | import javax.inject.Qualifier;
25 |
26 | import static java.lang.annotation.ElementType.FIELD;
27 | import static java.lang.annotation.ElementType.METHOD;
28 | import static java.lang.annotation.ElementType.PARAMETER;
29 | import static java.lang.annotation.ElementType.TYPE;
30 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
31 |
32 | /**
33 | * Qualifies injection points that should have their values fetched from a corresponding HTTP header.
34 | *
35 | *
57 | * Because the bean produced is dependent-scoped, use of this annotation on class fields and bean properties is only safe for
58 | * request-scoped beans. Beans with longer scopes should wrap this bean in a provider and retrieve the value on demand.
59 | *
69 | *
70 | * @author Dan Allen
71 | */
72 | @Qualifier
73 | @Target({TYPE, METHOD, PARAMETER, FIELD})
74 | @Retention(RUNTIME)
75 | @Documented
76 | public @interface HeaderParam {
77 | @Nonbinding
78 | public String value() default "";
79 | }
80 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/HttpServletRequestContext.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.http;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.ServletRequest;
5 | import javax.servlet.ServletResponse;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import javax.servlet.http.HttpSession;
9 |
10 | import org.jboss.seam.servlet.ServletRequestContext;
11 | import org.jboss.seam.solder.core.Veto;
12 |
13 | /**
14 | * Encapsulates the {@link HttpServletRequest} and {@link HttpServletResponse} for the current request and dually provides
15 | * access to the {@link ServletContext} and {@link HttpSession}, which are accessed from the {@link HttpServletRequest} object.
16 | *
17 | * @author Dan Allen
18 | */
19 | @Veto
20 | public class HttpServletRequestContext extends ServletRequestContext {
21 | // required for scoped producer
22 | public HttpServletRequestContext() {
23 | }
24 |
25 | public HttpServletRequestContext(ServletRequest request, ServletResponse response) {
26 | super(enforceType(request, HttpServletRequest.class), enforceType(response, HttpServletResponse.class));
27 | }
28 |
29 | public HttpServletRequestContext(ServletRequest request) {
30 | super(enforceType(request, HttpServletRequest.class), null);
31 | }
32 |
33 | public HttpServletRequestContext(HttpServletRequest request, HttpServletResponse response) {
34 | super(request, response);
35 | }
36 |
37 | public HttpServletRequestContext(HttpServletRequest request) {
38 | super(request, null);
39 | }
40 |
41 | @Override
42 | public HttpServletRequest getRequest() {
43 | return (HttpServletRequest) super.getRequest();
44 | }
45 |
46 | @Override
47 | public HttpServletResponse getResponse() {
48 | return (HttpServletResponse) super.getResponse();
49 | }
50 |
51 | public HttpSession getHttpSession() {
52 | return getRequest().getSession();
53 | }
54 |
55 | public String getContextPath() {
56 | return getRequest().getContextPath();
57 | }
58 |
59 | private static T enforceType(Object arg, Class expectedType) {
60 | if (!expectedType.isAssignableFrom(arg.getClass())) {
61 | throw new IllegalArgumentException("Type " + expectedType.getSimpleName() + " expected, but got " + arg);
62 | }
63 | return expectedType.cast(arg);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/HttpSessionStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import javax.enterprise.context.RequestScoped;
20 | import javax.inject.Inject;
21 | import javax.servlet.http.HttpServletRequest;
22 | import javax.servlet.http.HttpSession;
23 |
24 | /**
25 | * A helper bean that can be injected to check the status of the HttpSession and acquiring it
26 | *
27 | * @author Nicklas Karlsson
28 | * @author Dan Allen
29 | */
30 | @RequestScoped
31 | public class HttpSessionStatus {
32 | @Inject
33 | private HttpServletRequest request;
34 |
35 | /**
36 | * Checks whether there is an active HttpSession associated with the current request.
37 | *
38 | * @return Whether a valid session is associated with this request
39 | */
40 | public boolean isActive() {
41 | if (!request.isRequestedSessionIdValid()) {
42 | return false;
43 | }
44 |
45 | return request.getSession(false) != null;
46 | }
47 |
48 | /**
49 | * Returns the current HttpSession associated with this request. If a session is not associated with the current request, a
50 | * new session is first initialized.
51 | *
52 | * @return HttpSession The existing session, or a new session if one has not yet been created
53 | */
54 | public HttpSession get() {
55 | return request.getSession();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/RedirectBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import javax.servlet.http.Cookie;
20 |
21 | /**
22 | * A builder, similar in style to the ResponseBuilder from JAX-RS, that simplifies the task of sending a redirect URL to the
23 | * client.
24 | *
25 | * This is a proposed API and is subject to change
26 | *
27 | * @author Dan Allen
28 | */
29 | public interface RedirectBuilder {
30 | void send();
31 |
32 | RedirectBuilder redirect();
33 |
34 | RedirectBuilder redirect(String path);
35 |
36 | RedirectBuilder temporaryRedirect(String path);
37 |
38 | RedirectBuilder seeOther(String path);
39 |
40 | RedirectBuilder cookie(Cookie... cookies);
41 |
42 | RedirectBuilder param(String name, Object... values);
43 |
44 | RedirectBuilder param(boolean replace, String name, Object... values);
45 |
46 | RedirectBuilder header(String name, Object... values);
47 |
48 | RedirectBuilder header(boolean replace, String name, Object... values);
49 |
50 | RedirectBuilder fragment(String fragment);
51 |
52 | RedirectBuilder mirror();
53 |
54 | RedirectBuilder encodeSessionId();
55 | }
56 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/RequestParam.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.enterprise.util.Nonbinding;
24 | import javax.inject.Qualifier;
25 |
26 | import static java.lang.annotation.ElementType.FIELD;
27 | import static java.lang.annotation.ElementType.METHOD;
28 | import static java.lang.annotation.ElementType.PARAMETER;
29 | import static java.lang.annotation.ElementType.TYPE;
30 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
31 |
32 | /**
33 | * Qualifies injection points that should have their values fetched from a corresponding HTTP request parameter (i.e., query
34 | * string or form parameter).
35 | *
36 | *
37 | * Example explicit usage, assuming a servlet path /book.jsf?id=3
38 | *
68 | * Because the bean produced is dependent-scoped, use of this annotation on class fields and bean properties is only safe for
69 | * request-scoped beans. Beans with longer scopes should wrap this bean in a provider and retrieve the value on demand.
70 | *
80 | *
81 | * @author Nicklas Karlsson
82 | * @author Dan Allen
83 | */
84 | @Qualifier
85 | @Target({TYPE, METHOD, PARAMETER, FIELD})
86 | @Retention(RUNTIME)
87 | @Documented
88 | public @interface RequestParam {
89 | @Nonbinding
90 | public String value() default "";
91 | }
92 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/literal/CookieParamLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | *
4 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
5 | * by the @authors tag. See the copyright.txt in the distribution for a
6 | * full listing of individual contributors.
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package org.jboss.seam.servlet.http.literal;
21 |
22 | import javax.enterprise.util.AnnotationLiteral;
23 |
24 | import org.jboss.seam.servlet.http.CookieParam;
25 |
26 | /**
27 | * @author Dan Allen
28 | */
29 | public class CookieParamLiteral extends AnnotationLiteral implements CookieParam {
30 | private final String value;
31 |
32 | public CookieParamLiteral() {
33 | this("");
34 | }
35 |
36 | public CookieParamLiteral(String value) {
37 | this.value = value;
38 | }
39 |
40 | public String value() {
41 | return value;
42 | }
43 |
44 | public static final CookieParamLiteral INSTANCE = new CookieParamLiteral();
45 | }
46 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/literal/HeaderParamLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | *
4 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
5 | * by the @authors tag. See the copyright.txt in the distribution for a
6 | * full listing of individual contributors.
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package org.jboss.seam.servlet.http.literal;
21 |
22 | import javax.enterprise.util.AnnotationLiteral;
23 |
24 | import org.jboss.seam.servlet.http.HeaderParam;
25 |
26 | /**
27 | * @author Dan Allen
28 | */
29 | public class HeaderParamLiteral extends AnnotationLiteral implements HeaderParam {
30 | private final String value;
31 |
32 | public HeaderParamLiteral() {
33 | this("");
34 | }
35 |
36 | public HeaderParamLiteral(String value) {
37 | this.value = value;
38 | }
39 |
40 | public String value() {
41 | return value;
42 | }
43 |
44 | public static final HeaderParamLiteral INSTANCE = new HeaderParamLiteral();
45 | }
46 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/http/literal/RequestParamLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | *
4 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
5 | * by the @authors tag. See the copyright.txt in the distribution for a
6 | * full listing of individual contributors.
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 | package org.jboss.seam.servlet.http.literal;
21 |
22 | import javax.enterprise.util.AnnotationLiteral;
23 |
24 | import org.jboss.seam.servlet.http.RequestParam;
25 |
26 | /**
27 | * @author Dan Allen
28 | */
29 | public class RequestParamLiteral extends AnnotationLiteral implements RequestParam {
30 | private final String value;
31 |
32 | public RequestParamLiteral() {
33 | this("");
34 | }
35 |
36 | public RequestParamLiteral(String value) {
37 | this.value = value;
38 | }
39 |
40 | public String value() {
41 | return value;
42 | }
43 |
44 | public static final RequestParamLiteral INSTANCE = new RequestParamLiteral();
45 | }
46 |
--------------------------------------------------------------------------------
/api/src/main/java/org/jboss/seam/servlet/literal/WebRequestLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.literal;
18 |
19 | import javax.enterprise.util.AnnotationLiteral;
20 |
21 | import org.jboss.seam.servlet.WebRequest;
22 |
23 | /**
24 | * @author Dan Allen
25 | */
26 | public class WebRequestLiteral extends AnnotationLiteral implements WebRequest {
27 | private static final long serialVersionUID = -6004283843896130532L;
28 | public static final WebRequest INSTANCE = new WebRequestLiteral();
29 | }
30 |
--------------------------------------------------------------------------------
/api/src/main/resources/META-INF/beans.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
22 |
23 |
--------------------------------------------------------------------------------
/building.txt:
--------------------------------------------------------------------------------
1 | Building this project
2 | =====================
3 |
4 | This project requires Apache Maven (available from http://maven.apache.org/)
5 | Version 3.0.3 or later to build. It also requires that the JBoss Public Maven
6 | Repository is configured - this can be done in one of two ways:
7 |
8 | 1) Configure your settings.xml (usually found in the .m2 directory within your
9 | home directory) to include the JBoss repository - see the instructions on the
10 | following page to learn how to do this: http://community.jboss.org/wiki/MavenGettingStarted
11 |
12 | 2) Use the provided settings.xml, by running "mvn -s settings.xml".
13 |
14 |
15 |
--------------------------------------------------------------------------------
/dist/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 | 4.0.0
20 |
21 |
22 | org.jboss.seam.servlet
23 | seam-servlet-parent
24 | 3.1.0-SNAPSHOT
25 | ../pom.xml
26 |
27 |
28 | seam-servlet-distribution
29 | Seam Servlet Distribution
30 | Builds a Seam Servlet module release distribution
31 | pom
32 |
33 |
34 | true
35 |
36 |
37 |
38 |
39 | org.jboss.seam.servlet
40 | seam-servlet-api
41 | false
42 |
43 |
44 |
45 | org.jboss.seam.servlet
46 | seam-servlet
47 | true
48 |
49 |
50 |
51 | org.jboss.seam.servlet
52 | seam-servlet-api
53 | ${project.version}
54 | sources
55 | true
56 |
57 |
58 |
59 | org.jboss.seam.servlet
60 | seam-servlet-api
61 | ${project.version}
62 | javadoc
63 | true
64 |
65 |
66 |
67 | org.jboss.seam.servlet
68 | seam-servlet
69 | ${project.version}
70 | sources
71 |
72 |
73 |
82 |
83 |
84 | org.jboss.seam.servlet
85 | seam-servlet-reference-guide
86 | ${project.version}
87 | war
88 | true
89 |
90 |
91 |
92 |
93 |
94 | seam-servlet
95 |
96 |
97 | org.apache.maven.plugins
98 | maven-assembly-plugin
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/dist/src/main/assembly/assembly.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
22 |
23 | distribution
24 |
25 |
26 | zip
27 |
28 |
29 | ${project.build.finalName}-${project.version}
30 |
31 |
32 |
33 |
34 | src/main/assembly
35 | .
36 | true
37 |
38 | readme.txt
39 | license.txt
40 | notice.txt
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | artifacts
49 | false
50 |
51 | org.jboss.seam.servlet:seam-servlet-api
52 | org.jboss.seam.servlet:seam-servlet
53 |
54 |
55 | org.jboss.seam.servlet:*:*:javadoc
56 | org.jboss.seam.servlet:*:*:sources
57 |
58 | ${artifact.artifactId}${dashClassifier?}.${artifact.extension}
59 |
60 |
61 |
62 |
63 | lib
64 | false
65 | true
66 |
67 | org.jboss.seam.servlet:*
68 |
69 | ${artifact.artifactId}${dashClassifier?}.${artifact.extension}
70 |
71 |
72 |
73 |
74 | doc/api
75 | true
76 | false
77 |
78 | org.jboss.seam.servlet:seam-servlet-api:jar:javadoc
79 |
80 |
81 |
82 | META-INF/
83 |
84 |
85 |
86 |
87 |
88 |
89 | doc/reference
90 | true
91 | false
92 |
93 | org.jboss.seam.servlet:seam-servlet-reference-guide
94 |
95 |
96 |
97 | META-INF/
98 |
99 |
100 |
101 |
102 |
103 |
104 | source
105 | true
106 | false
107 |
108 | org.jboss.seam.servlet:seam-servlet-api:*:sources
109 | org.jboss.seam.servlet:seam-servlet-impl:*:sources
110 |
111 |
112 |
113 | META-INF/
114 |
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/dist/src/main/assembly/notice.txt:
--------------------------------------------------------------------------------
1 | ===================================================================================
2 | == NOTICE file corresponding to section 4d of the Apache License, Version 2.0, ==
3 | == in this case for the Seam Servlet distribution. ==
4 | ===================================================================================
5 |
6 | Seam Servlet
7 | Copyright 2010 Red Hat, Inc., and individual contributors by the @authors tag
8 |
--------------------------------------------------------------------------------
/dist/src/main/assembly/readme.txt:
--------------------------------------------------------------------------------
1 |
2 | Seam Servlet Module
3 | ${project.version}
4 |
5 | What is it?
6 | ===========
7 |
8 | Seam Servlet provide portable enhancements to the Servlet API. Features
9 | include producers for implicit Servlet objects and request state, briding
10 | Servlet events to the CDI event bus and making the BeanManager available
11 | through the Servlet context.
12 |
13 | Contents of distribution
14 | ========================
15 |
16 | artifacts/
17 |
18 | Provided libraries
19 |
20 | lib/
21 |
22 | Dependencies
23 |
24 | doc/
25 |
26 | API Docs and reference guide.
27 |
28 | source/
29 |
30 | Module source code
31 |
32 | Licensing
33 | =========
34 |
35 | This distribution, as a whole, is licensed under the terms of the Apache
36 | Software License, Version 2.0 (ASL).
37 |
38 | Seam Servlet URLs
39 | =================
40 |
41 | Seam 3 Servlet Module: http://sfwk.org/Seam3/Servlet
42 | Seam 3 project: http://sfwk.org/Seam3
43 | Downloads: http://sfwk.org/Seam3/DistributionDownloads
44 | Forums: http://sfwk.org/Community/Seam3Users
45 | Source Code: http://github.com/seam/servlet
46 | Issue Tracking: http://issues.jboss.org/browse/SEAMSERVLET
47 |
48 | Release Notes
49 | =============
50 |
51 | * Migration to Seam Solder
52 | * Declarative exception handler facility
53 | * Additional startup event (@Started WebApplication)
54 | * Support for Enum, Date and Calendar in HTTP data injections
55 | * Combined API + implement JAR (seam-servlet)
56 | * @HttpMethod lifecycle event selector
57 | * Documentation edits
58 | * Assign name to web-fragment.xml
59 |
--------------------------------------------------------------------------------
/docs/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 | 4.0.0
21 |
22 |
23 | org.jboss.seam.servlet
24 | seam-servlet-parent
25 | 3.1.0-SNAPSHOT
26 | ../pom.xml
27 |
28 |
29 | org.jboss.seam.servlet
30 | seam-servlet-reference-guide
31 | jdocbook
32 | Seam Servlet Reference Guide
33 |
34 |
35 | ${project.artifactId}.pdf
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.jboss.maven.plugins
43 | maven-jdocbook-plugin
44 |
45 |
46 |
47 |
48 | org.codehaus.mojo
49 | build-helper-maven-plugin
50 |
51 |
52 | attach-zip
53 | package
54 |
55 | attach-artifact
56 |
57 |
58 |
59 |
60 | ${project.build.outputDirectory}/${project.artifactId}-${project.version}.war
61 | war
62 |
63 |
64 |
65 |
66 |
67 |
68 | attach-source
69 | generate-sources
70 |
71 | add-source
72 |
73 |
74 |
75 | src/main/docbook/en-US
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | distribution
87 |
88 |
89 | release
90 |
91 |
92 |
93 |
94 |
95 | org.apache.maven.plugins
96 | maven-assembly-plugin
97 |
98 |
99 |
100 |
101 |
102 | preview
103 |
104 |
105 |
106 | org.jboss.maven.plugins
107 | maven-jdocbook-plugin
108 |
109 |
110 |
111 | html
112 | classpath:/xslt/org/jboss/weld/xhtml.xsl
113 | index.html
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/docs/readme.md:
--------------------------------------------------------------------------------
1 | To build the Seam Servlet reference guide, execute the following command:
2 |
3 | mvn package
4 |
5 | If you want to build incremental changes to the reference guide, you can
6 | use this command after executing the build above at least once:
7 |
8 | mvn jdocbook:generate
9 |
10 |
--------------------------------------------------------------------------------
/docs/src/main/assembly/assembly.xml:
--------------------------------------------------------------------------------
1 |
17 |
21 | sources
22 |
23 | zip
24 |
25 | ${project.artifactId}
26 |
27 |
28 | .
29 | ${project.basedir}/src/main/docbook/en-US
30 | true
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/author_group.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 |
22 | Dan
23 | Allen
24 |
25 |
26 | Lincoln
27 | Baxter III
28 |
29 |
30 | Nicklas
31 | Karlsson
32 |
33 |
36 |
37 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/book_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 | Seam Servlet Module
22 | Reference Guide
23 | ${project.version}
24 |
25 |
26 |
27 |
30 |
31 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/master.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
36 |
37 |
40 |
41 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/servlet-beanmanager.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 | Retrieving the BeanManager from the servlet context
22 |
23 | Typically, the BeanManager is obtained using some form of injection. However, there are
24 | scenarios where the code being executed is outside of a managed bean environment and you need a way in. In these
25 | cases, it's necessary to lookup the BeanManager from a well-known location.
26 |
27 |
28 | In general, you should isolate external BeanManager lookups to integration code.
29 |
30 |
31 | The standard mechanism for locating the BeanManager from outside a managed bean environment, as
32 | defined by the JSR-299 specification, is to look it up in JNDI. However, JNDI isn't the most convenient technology
33 | to depend on when you consider all popular deployment environments (think Tomcat and Jetty).
34 |
35 |
36 | As a simpler alternative, Seam Servlet binds the BeanManager to the following servlet context
37 | attribute (whose name is equivalent to the fully-qualified class name of the BeanManager
38 | interface:
39 |
40 | javax.enterprise.inject.spi.BeanManager
41 |
42 | Seam Servlet also includes a provider that retrieves the BeanManager from this location.
43 | Anytime the Seam Servlet module needs a reference to the BeanManager, it uses this lookup
44 | mechanism to ensure that the module works consistently across deployment environments, especially in Servlet
45 | containers.
46 |
47 |
48 | You can retrieve the BeanManager in the same way. If you want to hide the lookup, you can
49 | extend the BeanManagerAware class and retrieve the BeanManager from the the
50 | method getBeanManager(), as shown here:
51 |
52 |
58 |
59 |
60 | Alternatively, you can retrieve the BeanManager from the method
61 | getBeanManager() on the BeanManagerLocator class, as shown here:
62 |
63 |
69 |
70 |
71 |
72 | The best way to transfer execution of the current context to the managed bean environment is to send an event
73 | to an observer bean, as this example above suggests.
74 |
75 |
76 |
77 | Under the covers, these classes look for the BeanManager in the servlet context attribute
78 | covered in this section, amongst other available strategies. Refer to the BeanManager
80 | provider chapter of the Seam Solder reference guide for information on how to leverage the servlet
81 | context attribute provider to access the BeanManager from outside the CDI environment.
82 |
83 |
86 |
87 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/servlet-exception_handling.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 | Exception handling: Seam Catch integration
22 |
23 | Seam Catch provides a simple, yet robust
24 | foundation for modules and/or applications to establish a customized exception handling process. Seam Servlet ties
25 | into the exception handling model by forwarding all unhandled Servlet exceptions to Catch so that they can be
26 | handled in a centralized, extensible and uniform manner.
27 |
28 |
29 | Background
30 |
31 | The Servlet API is extremely weak when it comes to handling exceptions. You are limited to handling exceptions
32 | using the built-in, declarative controls provided in web.xml. Those controls give you two options:
33 |
34 |
35 | send an HTTP status code
36 | forward to an error page (servlet path)
37 |
38 |
39 | To make matters more painful, you are required to configure these exception mappings in web.xml. It's really
40 | a dinosaur left over from the past. In general, the Servlet specification seems to be pretty non-chalant about
41 | exceptions, telling you to "handle them appropriately." But how?
42 |
43 |
44 | That's where the Catch integration in Seam Servlet comes in. The Catch integration traps all unhandled
45 | exceptions (those that bubble outside of the Servlet and any filters) and forwards them on to Catch.
46 | Exception handlers are free to handle the exception anyway they like, either programmatically or via
47 | a declarative mechanism.
48 |
49 |
50 | If a exception handler registered with Catch handles the exception, then the integration closes the response
51 | without raising any additional exceptions. If the exception is still unhandled after Catch finishes processing
52 | it, then the integration allows it to pass through to the normal Servlet exception handler.
53 |
54 |
55 |
56 | Defining a exception handler for a web request
57 |
58 | You can define an exception handler for a web request using the normal syntax of a Catch exception handler.
59 | Let's catch any exception that bubbles to the top and respond with a 500 error.
60 |
61 | caught, HttpServletResponse response) {
64 | response.sendError(500, "You've been caught by Catch!");
65 | }
66 | }]]>
67 |
68 | That's all there is to it! If you only want this handler to be used for exceptions raised by a web request
69 | (excluding web service requests like JAX-RS), then you can add the @WebRequest qualifier to
70 | the handler:
71 |
72 | caught, HttpServletResponse response) {
76 | response.sendError(500, "You've been caught by Catch!");
77 | }
78 | }]]>
79 |
80 |
81 | Currently, @WebRequest is required to catch exceptions initiated by the Servlet
82 | integration because of a bug in Catch.
83 |
84 |
85 |
86 | Let's consider another example. When the custom AccountNotFound exception is thrown,
87 | we'll send a 404 response using this handler.
88 |
89 | caught, HttpServletResponse response) {
91 | response.sendError(404, "Account not found: " + caught.getException().getAccountId());
92 | }]]>
93 |
94 | In a future release, Seam Servlet will include annotations that can be used to configure these responses
95 | declaratively.
96 |
97 |
98 |
101 |
102 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/servlet-installation.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 | Installation
22 |
23 | To use the Seam Servlet module, you need to put the API and implementation JARs on the classpath of your web
24 | application. Most of the features of Seam Servlet are enabled automatically when it's added to the classpath. Some
25 | extra configuration, covered below, is required if you are not using a Servlet 3-compliant container.
26 |
27 |
28 |
29 | Maven dependency configuration
30 |
31 | If you are using Maven as your build tool, you can add the
32 | following single dependency to your pom.xml file to include Seam Servlet:
33 |
34 |
35 | org.jboss.seam.servlet
36 | seam-servlet
37 | ${seam.servlet.version}
38 | ]]>
39 |
40 |
41 | Substitute the expression ${seam.servlet.version} with the most recent or appropriate version of Seam Servlet.
42 | Alternatively, you can create a Maven
44 | user-defined property to satisfy this substitution so you can centrally manage the version.
45 |
46 |
47 |
48 | Alternatively, you can use the API at compile time and only include the implementation at runtime. This protects
49 | you from inadvertantly depending on an implementation class.
50 |
51 |
52 | org.jboss.seam.servlet
53 | seam-servlet-api
54 | ${seam.servlet.version}
55 | compile
56 |
57 |
58 |
59 | org.jboss.seam.servlet
60 | seam-servlet-impl
61 | ${seam.servlet.version}
62 | runtime
63 | ]]>
64 |
65 | In a Servlet 3.0 or Java EE 6 environment, your configuration is now complete!
66 |
67 |
68 |
69 |
70 | Pre-Servlet 3.0 configuration
71 |
72 | If you are using Java EE 5 or some other Servlet 2.5 container, then you need to manually
73 | register several Servlet components in your application's web.xml to activate the features provided by this
74 | module:
75 |
76 |
77 | org.jboss.seam.servlet.event.ServletEventBridgeListener
78 |
79 |
80 |
81 | Servlet Event Bridge Servlet
82 | org.jboss.seam.servlet.event.ServletEventBridgeServlet
83 |
84 | 99999
85 |
86 |
87 |
88 | Servlet Event Bridge Servlet
89 | /*
90 |
91 |
92 |
93 | Catch Exception Filter
94 | org.jboss.seam.servlet.exception.CatchExceptionFilter
95 |
96 |
97 |
98 | Catch Exception Filter
99 | /*
100 |
101 |
102 |
103 | Servlet Event Bridge Filter
104 | org.jboss.seam.servlet.event.ServletEventBridgeFilter
105 |
106 |
107 |
108 | Servlet Event Bridge Filter
109 | /*
110 | ]]>
111 |
112 |
113 |
114 |
115 | In order for the Seam Servlet event bridge to properly fire the ServletContext initialized event, the CDI
116 | runtime must be started at the time the Seam Servlet listener is invoked. This ordering is guaranteed in a
117 | compliant Java EE 6 environment. If you are using a CDI implementation in a Servlet environment (e.g., Weld
118 | Servlet), and it relies on a Servlet listener to bootstrap, that listener must be registered
119 | before any Seam Servlet listener in web.xml.
120 |
121 |
122 |
123 |
124 | You're now ready to dive into the Servlet enhancements provided for you by the Seam Servlet module!
125 |
126 |
129 |
130 |
--------------------------------------------------------------------------------
/docs/src/main/docbook/en-US/servlet-introduction.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 | Introduction
22 |
23 | The goal of the Seam Servlet module is to provide portable enhancements to the Servlet API. Features include
24 | producers for implicit Servlet objects and HTTP request state, propagating Servlet events to the CDI event bus,
25 | forwarding uncaught exceptions to the Seam Catch handler chain and binding the BeanManager to a Servlet context
26 | attribute for convenient access.
27 |
28 |
29 |
32 |
33 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/ImplicitServletObjectsProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet;
18 |
19 | import javax.enterprise.context.ApplicationScoped;
20 | import javax.enterprise.context.RequestScoped;
21 | import javax.enterprise.inject.Produces;
22 | import javax.inject.Inject;
23 | import javax.servlet.ServletContext;
24 | import javax.servlet.ServletRequest;
25 | import javax.servlet.ServletResponse;
26 |
27 | import org.jboss.seam.servlet.event.ImplicitServletObjectsHolder;
28 |
29 | /**
30 | * Produces an application-scoped {@link ServletContext} bean. A references is obtained from the
31 | * {@link ImplicitServletObjectsHolder}.
32 | *
33 | * @author Dan Allen
34 | */
35 | public class ImplicitServletObjectsProducer {
36 | @Inject
37 | private ImplicitServletObjectsHolder holder;
38 |
39 | @Produces
40 | @ApplicationScoped
41 | protected ServletContext getServletContext() {
42 | return holder.getServletContext();
43 | }
44 |
45 | @Produces
46 | @RequestScoped
47 | protected ServletRequestContext getServletRequestContext() {
48 | return holder.getServletRequestContext();
49 | }
50 |
51 | @Produces
52 | @RequestScoped
53 | protected ServletRequest getServletRequest() {
54 | return holder.getServletRequest();
55 | }
56 |
57 | @Produces
58 | @RequestScoped
59 | protected ServletResponse getServletResponse() {
60 | return holder.getServletResponse();
61 | }
62 |
63 | @Produces
64 | @ServerInfo
65 | protected String getServerInfo() {
66 | return getServletContext().getServerInfo();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/beanManager/ServletContextAttributeProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.beanManager;
18 |
19 | import javax.enterprise.inject.spi.BeanManager;
20 | import javax.servlet.ServletContext;
21 |
22 | import org.jboss.seam.solder.beanManager.BeanManagerProvider;
23 |
24 | /**
25 | * A BeanManager provider for the Servlet Context attribute "javax.enterprise.inject.spi.BeanManager"
26 | *
27 | * @author Nicklas Karlsson
28 | * @see org.jboss.seam.servlet.ImplicitServletObjectsProducer
29 | */
30 | public class ServletContextAttributeProvider implements BeanManagerProvider {
31 | private static ThreadLocal servletContext = new ThreadLocal() {
32 | @Override
33 | protected ServletContext initialValue() {
34 | return null;
35 | }
36 | };
37 |
38 | public static void setServletContext(final ServletContext sc) {
39 | servletContext.set(sc);
40 | }
41 |
42 | public BeanManager getBeanManager() {
43 | if (servletContext.get() != null) {
44 | return (BeanManager) servletContext.get().getAttribute(BeanManager.class.getName());
45 | }
46 | return null;
47 | }
48 |
49 | public int getPrecedence() {
50 | return 20;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/config/CharacterEncodingConfig.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.config;
2 |
3 | import javax.enterprise.event.Observes;
4 | import javax.servlet.ServletRequest;
5 | import javax.servlet.ServletResponse;
6 |
7 | import org.jboss.seam.servlet.event.Initialized;
8 |
9 | /**
10 | * @author Dan Allen
11 | */
12 | public class CharacterEncodingConfig {
13 | private String encoding;
14 |
15 | private boolean override = false;
16 |
17 | protected void apply(@Observes @Initialized ServletResponse response, ServletRequest request) throws Exception {
18 | if (encoding != null && (override || request.getCharacterEncoding() == null)) {
19 | request.setCharacterEncoding(encoding);
20 | if (override) {
21 | response.setCharacterEncoding(encoding);
22 | }
23 | }
24 | }
25 |
26 | public String getEncoding() {
27 | return encoding;
28 | }
29 |
30 | public void setEncoding(String encoding) {
31 | this.encoding = encoding;
32 | }
33 |
34 | public boolean isOverride() {
35 | return override;
36 | }
37 |
38 | public void setOverride(boolean override) {
39 | this.override = override;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/event/AbstractServletEventBridge.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.lang.annotation.Annotation;
20 | import java.util.Arrays;
21 |
22 | import org.jboss.seam.logging.Logger;
23 | import org.jboss.seam.servlet.WebApplication;
24 | import org.jboss.seam.servlet.support.ServletLogger;
25 | import org.jboss.seam.solder.beanManager.BeanManagerAware;
26 | import org.jboss.seam.solder.beanManager.BeanManagerUnavailableException;
27 |
28 | /**
29 | * An abstract class that handles sending events to the CDI event bus with support for environments where injection into the
30 | * Servlet component is not available.
31 | *
32 | * @author Dan Allen
33 | */
34 | public abstract class AbstractServletEventBridge extends BeanManagerAware {
35 | private transient ServletLogger log = Logger.getMessageLogger(ServletLogger.class, ServletLogger.CATEGORY);
36 |
37 | public static String WEB_APPLICATION_ATTRIBUTE_NAME = WebApplication.class.getName();
38 |
39 | /**
40 | * Propagates the Servlet event to the CDI event bus if the BeanManager is available. If injection is available, this will
41 | * always be skipped, and thus the performance optimal
42 | */
43 | protected void fireEvent(final Object payload, final Annotation... qualifiers) {
44 | try {
45 | getBeanManager().fireEvent(payload, qualifiers);
46 | } catch (BeanManagerUnavailableException e) {
47 | log.skippingEventNoBeanManager(payload, Arrays.asList(qualifiers));
48 | return;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/event/ImplicitServletObjectsHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import javax.enterprise.context.ApplicationScoped;
20 | import javax.enterprise.event.Observes;
21 | import javax.enterprise.inject.spi.BeanManager;
22 | import javax.inject.Inject;
23 | import javax.servlet.ServletContext;
24 | import javax.servlet.ServletRequest;
25 | import javax.servlet.ServletResponse;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | import javax.servlet.http.HttpSession;
29 |
30 | import org.jboss.seam.servlet.ServletRequestContext;
31 | import org.jboss.seam.servlet.beanManager.ServletContextAttributeProvider;
32 | import org.jboss.seam.servlet.http.HttpServletRequestContext;
33 | import org.jboss.seam.servlet.support.ServletLogger;
34 | import org.jboss.seam.logging.Category;
35 |
36 | /**
37 | * A manager for tracking the contextual Servlet objects, specifically the {@link ServletContext}, {@link HttpServletRequest}
38 | * and {@link HttpServletResponse}.
39 | *
40 | * @author Dan Allen
41 | */
42 | @ApplicationScoped
43 | public class ImplicitServletObjectsHolder {
44 | @Inject
45 | @Category(ServletLogger.CATEGORY)
46 | private ServletLogger log;
47 |
48 | private ServletContext servletCtx;
49 |
50 | private final ThreadLocal requestCtx = new ThreadLocal() {
51 | @Override
52 | protected ServletRequestContext initialValue() {
53 | return null;
54 | }
55 | };
56 |
57 | protected void contextInitialized(@Observes @Initialized final InternalServletContextEvent e, BeanManager beanManager) {
58 | ServletContext ctx = e.getServletContext();
59 | log.servletContextInitialized(ctx);
60 | ctx.setAttribute(BeanManager.class.getName(), beanManager);
61 | ServletContextAttributeProvider.setServletContext(ctx);
62 | servletCtx = ctx;
63 | }
64 |
65 | protected void contextDestroyed(@Observes @Destroyed final InternalServletContextEvent e) {
66 | log.servletContextDestroyed(e.getServletContext());
67 | servletCtx = null;
68 | }
69 |
70 | protected void requestInitialized(@Observes @Initialized final InternalServletRequestEvent e) {
71 | ServletRequest req = e.getServletRequest();
72 | log.servletRequestInitialized(req);
73 | if (req instanceof HttpServletRequest) {
74 | requestCtx.set(new HttpServletRequestContext(req));
75 | } else {
76 | requestCtx.set(new ServletRequestContext(req));
77 | }
78 | }
79 |
80 | protected void requestDestroyed(@Observes @Destroyed final InternalServletRequestEvent e) {
81 | log.servletRequestDestroyed(e.getServletRequest());
82 | requestCtx.set(null);
83 | }
84 |
85 | protected void responseInitialized(@Observes @Initialized final InternalServletResponseEvent e) {
86 | ServletResponse res = e.getServletResponse();
87 | log.servletResponseInitialized(res);
88 | if (res instanceof HttpServletResponse) {
89 | requestCtx.set(new HttpServletRequestContext(requestCtx.get().getRequest(), res));
90 | } else {
91 | requestCtx.set(new ServletRequestContext(requestCtx.get().getRequest(), res));
92 | }
93 | }
94 |
95 | protected void responseDestroyed(@Observes @Destroyed final InternalServletResponseEvent e) {
96 | log.servletResponseDestroyed(e.getServletResponse());
97 | if (requestCtx.get() instanceof HttpServletRequestContext) {
98 | requestCtx.set(new HttpServletRequestContext(requestCtx.get().getRequest()));
99 | } else {
100 | requestCtx.set(new ServletRequestContext(requestCtx.get().getRequest()));
101 | }
102 | }
103 |
104 | public ServletContext getServletContext() {
105 | return servletCtx;
106 | }
107 |
108 | public ServletRequestContext getServletRequestContext() {
109 | return requestCtx.get();
110 | }
111 |
112 | public HttpServletRequestContext getHttpServletRequestContext() {
113 | if (requestCtx.get() instanceof HttpServletRequestContext) {
114 | return HttpServletRequestContext.class.cast(requestCtx.get());
115 | } else {
116 | return null;
117 | }
118 | }
119 |
120 | public ServletRequest getServletRequest() {
121 | if (requestCtx.get() != null) {
122 | return requestCtx.get().getRequest();
123 | } else {
124 | return null;
125 | }
126 | }
127 |
128 | public HttpServletRequest getHttpServletRequest() {
129 | if (requestCtx.get() instanceof HttpServletRequestContext) {
130 | return HttpServletRequestContext.class.cast(requestCtx.get()).getRequest();
131 | } else {
132 | return null;
133 | }
134 | }
135 |
136 | public ServletResponse getServletResponse() {
137 | if (requestCtx.get() != null) {
138 | return requestCtx.get().getResponse();
139 | } else {
140 | return null;
141 | }
142 | }
143 |
144 | public HttpServletResponse getHttpServletResponse() {
145 | if (requestCtx.get() instanceof HttpServletRequestContext) {
146 | return HttpServletRequestContext.class.cast(requestCtx.get()).getResponse();
147 | } else {
148 | return null;
149 | }
150 | }
151 |
152 | public HttpSession getHttpSession() {
153 | if (requestCtx.get() instanceof HttpServletRequestContext) {
154 | return HttpServletRequestContext.class.cast(requestCtx.get()).getRequest().getSession();
155 | } else {
156 | return null;
157 | }
158 | }
159 |
160 | static class InternalServletContextEvent {
161 | private ServletContext ctx;
162 |
163 | InternalServletContextEvent(ServletContext ctx) {
164 | this.ctx = ctx;
165 | }
166 |
167 | public ServletContext getServletContext() {
168 | return ctx;
169 | }
170 | }
171 |
172 | static class InternalServletRequestEvent {
173 | private ServletRequest request;
174 |
175 | InternalServletRequestEvent(ServletRequest request) {
176 | this.request = request;
177 | }
178 |
179 | public ServletRequest getServletRequest() {
180 | return request;
181 | }
182 | }
183 |
184 | static class InternalServletResponseEvent {
185 | private ServletResponse response;
186 |
187 | InternalServletResponseEvent(ServletResponse response) {
188 | this.response = response;
189 | }
190 |
191 | public ServletResponse getServletResponse() {
192 | return response;
193 | }
194 | }
195 |
196 | static class InternalHttpSessionEvent {
197 | private HttpSession session;
198 |
199 | InternalHttpSessionEvent(HttpSession session) {
200 | this.session = session;
201 | }
202 |
203 | public HttpSession getHttpSession() {
204 | return session;
205 | }
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridgeFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import java.io.IOException;
20 |
21 | import javax.servlet.Filter;
22 | import javax.servlet.FilterChain;
23 | import javax.servlet.FilterConfig;
24 | import javax.servlet.ServletException;
25 | import javax.servlet.ServletRequest;
26 | import javax.servlet.ServletResponse;
27 | import javax.servlet.http.HttpServletRequest;
28 |
29 | import org.jboss.seam.servlet.ServletRequestContext;
30 | import org.jboss.seam.servlet.event.ImplicitServletObjectsHolder.InternalServletResponseEvent;
31 | import org.jboss.seam.servlet.event.literal.DestroyedLiteral;
32 | import org.jboss.seam.servlet.event.literal.InitializedLiteral;
33 | import org.jboss.seam.servlet.event.literal.PathLiteral;
34 | import org.jboss.seam.servlet.http.HttpServletRequestContext;
35 |
36 | /**
37 | * Propagates the {@link ServletResponse} lifecycle events to the CDI event bus, complementing the ServletEventBridgeListener,
38 | * which handles the other lifecycle events.
39 | *
40 | *
41 | * This filter is auto-registered in Servlet 3.0 environments. If CDI injection is available into filters, the BeanManager will
42 | * be accessible to this instance as an injected resource. Otherwise, the BeanManager will be looked up using the BeanManager
43 | * provider service.
44 | *
45 | *
46 | *
47 | * The internal events are fired to ensure that the setup and tear down routines happen around the main events. The event
48 | * strategy is used to jump from a Servlet component which may not be managed by CDI to an observe we know to be a managed bean.
49 | *
50 | *
51 | * @author Dan Allen
52 | */
53 | public class ServletEventBridgeFilter extends AbstractServletEventBridge implements Filter {
54 | public void init(FilterConfig config) throws ServletException {
55 | }
56 |
57 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
58 | ServletException {
59 | fireEvent(new InternalServletResponseEvent(response), InitializedLiteral.INSTANCE);
60 | Path path = null;
61 | if (request instanceof HttpServletRequest) {
62 | path = new PathLiteral(HttpServletRequest.class.cast(request).getServletPath());
63 | fireEvent(response, InitializedLiteral.INSTANCE, path);
64 | fireEvent(new HttpServletRequestContext(request, response), InitializedLiteral.INSTANCE, path);
65 | } else {
66 | fireEvent(response, InitializedLiteral.INSTANCE);
67 | fireEvent(new ServletRequestContext(request, response), InitializedLiteral.INSTANCE);
68 | }
69 |
70 | try {
71 | if (!response.isCommitted()) {
72 | chain.doFilter(request, response);
73 | }
74 | } finally {
75 | if (request instanceof HttpServletRequest) {
76 | fireEvent(response, DestroyedLiteral.INSTANCE, path);
77 | fireEvent(new HttpServletRequestContext(request, response), DestroyedLiteral.INSTANCE, path);
78 | } else {
79 | fireEvent(response, DestroyedLiteral.INSTANCE);
80 | fireEvent(new ServletRequestContext(request, response), DestroyedLiteral.INSTANCE);
81 | }
82 | fireEvent(new InternalServletResponseEvent(response), DestroyedLiteral.INSTANCE);
83 | }
84 | }
85 |
86 | public void destroy() {
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridgeListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.event;
18 |
19 | import javax.servlet.ServletContextEvent;
20 | import javax.servlet.ServletContextListener;
21 | import javax.servlet.ServletRequestEvent;
22 | import javax.servlet.ServletRequestListener;
23 | import javax.servlet.http.HttpServletRequest;
24 | import javax.servlet.http.HttpSessionActivationListener;
25 | import javax.servlet.http.HttpSessionEvent;
26 | import javax.servlet.http.HttpSessionListener;
27 |
28 | import org.jboss.seam.servlet.WebApplication;
29 | import org.jboss.seam.servlet.event.ImplicitServletObjectsHolder.InternalHttpSessionEvent;
30 | import org.jboss.seam.servlet.event.ImplicitServletObjectsHolder.InternalServletContextEvent;
31 | import org.jboss.seam.servlet.event.ImplicitServletObjectsHolder.InternalServletRequestEvent;
32 | import org.jboss.seam.servlet.event.literal.DestroyedLiteral;
33 | import org.jboss.seam.servlet.event.literal.DidActivateLiteral;
34 | import org.jboss.seam.servlet.event.literal.HttpMethodLiteral;
35 | import org.jboss.seam.servlet.event.literal.InitializedLiteral;
36 | import org.jboss.seam.servlet.event.literal.PathLiteral;
37 | import org.jboss.seam.servlet.event.literal.WillPassivateLiteral;
38 |
39 | /**
40 | * Propagates Servlet lifecycle events to the CDI event bus.
41 | *
42 | *
43 | * This listener is auto-registered in Servlet 3.0 environments. If CDI injection is available into listeners, the BeanManager
44 | * will be accessible to this instance as an injected resource. Otherwise, the BeanManager will be looked up using the
45 | * BeanManager provider service.
46 | *
47 | *
48 | *
49 | * The internal events are fired to ensure that the setup and tear down routines happen around the main events. The event
50 | * strategy is used to jump from a Servlet component which may not be managed by CDI to an observe we know to be a managed bean.
51 | *
52 | *
53 | * @author Nicklas Karlsson
54 | * @author Dan Allen
55 | */
56 | public class ServletEventBridgeListener extends AbstractServletEventBridge implements HttpSessionActivationListener,
57 | HttpSessionListener, ServletContextListener, ServletRequestListener {
58 | public void contextInitialized(final ServletContextEvent e) {
59 | fireEvent(new InternalServletContextEvent(e.getServletContext()), InitializedLiteral.INSTANCE);
60 | WebApplication webapp = new WebApplication(e.getServletContext());
61 | e.getServletContext().setAttribute(WEB_APPLICATION_ATTRIBUTE_NAME, webapp);
62 | fireEvent(webapp, InitializedLiteral.INSTANCE);
63 | fireEvent(e.getServletContext(), InitializedLiteral.INSTANCE);
64 | }
65 |
66 | public void contextDestroyed(final ServletContextEvent e) {
67 | fireEvent(new InternalServletContextEvent(e.getServletContext()), DestroyedLiteral.INSTANCE);
68 | }
69 |
70 | public void requestInitialized(final ServletRequestEvent e) {
71 | fireEvent(new InternalServletRequestEvent(e.getServletRequest()), InitializedLiteral.INSTANCE);
72 | if (e.getServletRequest() instanceof HttpServletRequest) {
73 | HttpServletRequest httpRequest = HttpServletRequest.class.cast(e.getServletRequest());
74 | fireEvent(e.getServletRequest(), InitializedLiteral.INSTANCE, new PathLiteral(httpRequest.getServletPath()),
75 | new HttpMethodLiteral(httpRequest.getMethod()));
76 | } else {
77 | fireEvent(e.getServletRequest(), InitializedLiteral.INSTANCE);
78 | }
79 | }
80 |
81 | public void requestDestroyed(final ServletRequestEvent e) {
82 | if (e.getServletRequest() instanceof HttpServletRequest) {
83 | HttpServletRequest httpRequest = HttpServletRequest.class.cast(e.getServletRequest());
84 | fireEvent(e.getServletRequest(), DestroyedLiteral.INSTANCE, new PathLiteral(httpRequest.getServletPath()),
85 | new HttpMethodLiteral(httpRequest.getMethod()));
86 | } else {
87 | fireEvent(e.getServletRequest(), DestroyedLiteral.INSTANCE);
88 | }
89 | fireEvent(new InternalServletRequestEvent(e.getServletRequest()), DestroyedLiteral.INSTANCE);
90 | }
91 |
92 | public void sessionCreated(final HttpSessionEvent e) {
93 | fireEvent(new InternalHttpSessionEvent(e.getSession()), InitializedLiteral.INSTANCE);
94 | fireEvent(e.getSession(), InitializedLiteral.INSTANCE);
95 | }
96 |
97 | public void sessionDestroyed(final HttpSessionEvent e) {
98 | fireEvent(e.getSession(), DestroyedLiteral.INSTANCE);
99 | fireEvent(new InternalHttpSessionEvent(e.getSession()), DestroyedLiteral.INSTANCE);
100 | }
101 |
102 | public void sessionDidActivate(final HttpSessionEvent e) {
103 | fireEvent(e.getSession(), DidActivateLiteral.INSTANCE);
104 | }
105 |
106 | public void sessionWillPassivate(final HttpSessionEvent e) {
107 | fireEvent(e.getSession(), WillPassivateLiteral.INSTANCE);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/event/ServletEventBridgeServlet.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.event;
2 |
3 | import java.io.IOException;
4 | import java.lang.annotation.Annotation;
5 |
6 | import javax.servlet.Servlet;
7 | import javax.servlet.ServletConfig;
8 | import javax.servlet.ServletException;
9 | import javax.servlet.ServletRequest;
10 | import javax.servlet.ServletResponse;
11 |
12 | import org.jboss.seam.servlet.WebApplication;
13 | import org.jboss.seam.servlet.event.literal.DestroyedLiteral;
14 | import org.jboss.seam.servlet.event.literal.StartedLiteral;
15 |
16 | /**
17 | * Leverages the lifecycle of a Servlet to generate a CDI when the web application has been fully deployed and when it is
18 | * undeployed. This Servlet is assigned a high load-on-startup value (99999) in this module's web-fragment.xml to ensure it
19 | * comes last in the list of ordered Servlets.
20 | *
21 | * @author Dan Allen
22 | */
23 | public class ServletEventBridgeServlet extends AbstractServletEventBridge implements Servlet {
24 | private transient ServletConfig config;
25 |
26 | public void init(ServletConfig config) throws ServletException {
27 | this.config = config;
28 | fireWebApplicationEvent(StartedLiteral.INSTANCE);
29 | // fireEvent(config.getServletContext(), StartedLiteral.INSTANCE);
30 | }
31 |
32 | public void destroy() {
33 | if (config != null) {
34 | fireWebApplicationEvent(DestroyedLiteral.INSTANCE);
35 | fireEvent(config.getServletContext(), DestroyedLiteral.INSTANCE);
36 | }
37 | }
38 |
39 | protected void fireWebApplicationEvent(Annotation qualifier) {
40 | if (config.getServletContext().getAttribute(WEB_APPLICATION_ATTRIBUTE_NAME) instanceof WebApplication) {
41 | fireEvent(config.getServletContext().getAttribute(WEB_APPLICATION_ATTRIBUTE_NAME), qualifier);
42 | }
43 | }
44 |
45 | public ServletConfig getServletConfig() {
46 | return config;
47 | }
48 |
49 | public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
50 | }
51 |
52 | public String getServletInfo() {
53 | return "Seam Servlet module WebApplication event publisher";
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/exception/CatchExceptionFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.exception;
18 |
19 | import java.io.IOException;
20 |
21 | import javax.servlet.Filter;
22 | import javax.servlet.FilterChain;
23 | import javax.servlet.FilterConfig;
24 | import javax.servlet.ServletException;
25 | import javax.servlet.ServletRequest;
26 | import javax.servlet.ServletResponse;
27 | import javax.servlet.http.HttpServletRequest;
28 |
29 | import org.jboss.seam.logging.Logger;
30 | import org.jboss.seam.exception.control.ExceptionToCatch;
31 | import org.jboss.seam.servlet.literal.WebRequestLiteral;
32 | import org.jboss.seam.servlet.support.ServletLogger;
33 | import org.jboss.seam.solder.beanManager.BeanManagerAware;
34 | import org.jboss.seam.solder.beanManager.BeanManagerUnavailableException;
35 | import org.jboss.seam.solder.core.Requires;
36 |
37 | /**
38 | * A bridge that forwards unhandled exceptions to the Seam exception handling facility (Seam Catch).
39 | *
40 | * @author Dan Allen
41 | */
42 | @Requires("org.jboss.seam.exception.control.extension.CatchExtension")
43 | public class CatchExceptionFilter extends BeanManagerAware implements Filter {
44 | private transient ServletLogger log = Logger.getMessageLogger(ServletLogger.class, ServletLogger.CATEGORY);
45 |
46 | private boolean enabled = false;
47 |
48 | public void init(FilterConfig config) throws ServletException {
49 | try {
50 | if (!getBeanManager().getBeans(CatchExceptionFilter.class).isEmpty()) {
51 | enabled = true;
52 | log.catchIntegrationEnabled();
53 | }
54 | } catch (BeanManagerUnavailableException e) {
55 | log.catchIntegrationDisabledNoBeanManager();
56 | }
57 | }
58 |
59 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
60 | ServletException {
61 | if (!enabled) {
62 | chain.doFilter(request, response);
63 | } else {
64 | try {
65 | chain.doFilter(request, response);
66 | } catch (Exception e) {
67 | ExceptionToCatch catchEvent;
68 | if (request instanceof HttpServletRequest) {
69 | catchEvent = new ExceptionToCatch(e, WebRequestLiteral.INSTANCE);
70 | // new PathLiteral(HttpServletRequest.class.cast(request).getServletPath()));
71 | } else {
72 | catchEvent = new ExceptionToCatch(e, WebRequestLiteral.INSTANCE);
73 | }
74 | getBeanManager().fireEvent(catchEvent);
75 | // QUESTION should catch handle rethrowing?
76 | if (!catchEvent.isHandled()) {
77 | if (e instanceof ServletException) {
78 | throw (ServletException) e;
79 | } else if (e instanceof IOException) {
80 | throw (IOException) e;
81 | } else {
82 | throw new ServletException(e);
83 | }
84 | }
85 | }
86 | }
87 | }
88 |
89 | public void destroy() {
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/exception/handler/ExceptionResponseServiceHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright [2010], Red Hat, Inc., and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.exception.handler;
18 |
19 | import java.lang.reflect.Method;
20 |
21 | import javax.enterprise.inject.Instance;
22 | import javax.inject.Inject;
23 | import javax.interceptor.AroundInvoke;
24 | import javax.interceptor.InvocationContext;
25 |
26 | import org.jboss.seam.exception.control.CaughtException;
27 | import org.jboss.seam.servlet.http.HttpServletRequestContext;
28 |
29 | public class ExceptionResponseServiceHandler {
30 | // does this have to be Instance?
31 | @Inject
32 | private Instance requestCtxResolver;
33 |
34 | @AroundInvoke
35 | public Object processException(InvocationContext ctx) throws Exception {
36 | Method m = ctx.getMethod();
37 | // FIXME would be helpful if Catch provided a utility to get the CaughtException
38 | if (ctx.getParameters().length > 0 && ctx.getParameters()[0] instanceof CaughtException) {
39 | HttpServletRequestContext requestCtx = requestCtxResolver.get();
40 | // we can't respond w/ this exception handler if response is committed
41 | // TODO should see if exception is marked handled already
42 | if (requestCtx.getResponse().isCommitted()) {
43 | return Void.TYPE;
44 | }
45 | CaughtException> c = (CaughtException>) ctx.getParameters()[0];
46 | if (m.isAnnotationPresent(SendHttpError.class)) {
47 | SendHttpError r = m.getAnnotation(SendHttpError.class);
48 | String message = r.message().trim();
49 | if (r.message().length() == 0 && r.useExceptionMessageAsDefault()) {
50 | message = c.getException().getMessage();
51 | }
52 |
53 | if (message != null && message.length() > 0) {
54 | requestCtx.getResponse().sendError(r.status(), message);
55 | } else {
56 | requestCtx.getResponse().sendError(r.status());
57 | }
58 | } else if (m.isAnnotationPresent(SendErrorPage.class)) {
59 | SendErrorPage r = m.getAnnotation(SendErrorPage.class);
60 | if (r.redirect()) {
61 | requestCtx.getResponse().sendRedirect(requestCtx.getResponse().encodeRedirectURL(r.value()));
62 | } else {
63 | requestCtx.getRequest().getRequestDispatcher(r.value())
64 | .forward(requestCtx.getRequest(), requestCtx.getResponse());
65 | }
66 | } else {
67 | // perhaps log a warning?
68 | }
69 | }
70 | return Void.TYPE;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/exception/handler/ExceptionResponses.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.exception.handler;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | import org.jboss.seam.solder.serviceHandler.ServiceHandlerType;
9 |
10 | @Retention(RetentionPolicy.RUNTIME)
11 | @Target(ElementType.TYPE)
12 | @ServiceHandlerType(ExceptionResponseServiceHandler.class)
13 | public @interface ExceptionResponses {
14 | }
15 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/CookieParamProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.reflect.Constructor;
20 | import java.lang.reflect.Member;
21 | import java.lang.reflect.Method;
22 | import java.lang.reflect.ParameterizedType;
23 | import java.lang.reflect.Type;
24 |
25 | import javax.enterprise.inject.Produces;
26 | import javax.enterprise.inject.spi.InjectionPoint;
27 | import javax.inject.Inject;
28 | import javax.servlet.http.Cookie;
29 | import javax.servlet.http.HttpServletRequest;
30 |
31 | import org.jboss.seam.servlet.ServletExtension;
32 | import org.jboss.seam.solder.reflection.PrimitiveTypes;
33 |
34 | /**
35 | * A producer for a String bean qualified @{@link CookieParam}.
36 | *
37 | *
38 | * Provides a producer method that retrieves the value of the specified cookie from {@link HttpServletRequest#getCookies()}
39 | * array and makes it available as a dependent-scoped bean of type String qualified @CookieParam. The name of the cookie to
40 | * lookup is either the value of the @CookieParam annotation or, if the annotation value is empty, the name of the
41 | * injection point (e.g., the field name).
42 | *
43 | *
44 | * If the cookie is not present, and the injection point is annotated with @DefaultValue, the value of the
45 | * @DefaultValue annotation is returned instead. If @DefaultValue is not present, null is returned.
46 | *
47 | *
48 | * @author Dan Allen
49 | * @see CookieParam
50 | * @see DefaultValue
51 | */
52 | public class CookieParamProducer {
53 | @Inject
54 | private HttpServletRequest request;
55 |
56 | @Produces
57 | @TypedParamValue
58 | // FIXME find better place to cache the valueOf methods
59 | protected Object getTypedParamValue(InjectionPoint ip, ServletExtension ext) {
60 | String cookieName = getCookieName(ip);
61 | Class> t = PrimitiveTypes.box(resolveExpectedType(ip));
62 | if (t.equals(Cookie.class)) {
63 | return getCookie(cookieName, ip);
64 | }
65 |
66 | String v = getCookieValue(cookieName, ip);
67 | if (t.equals(String.class)) {
68 | return v;
69 | }
70 | try {
71 | Member converter = ext.getConverterMember(t);
72 | return converter instanceof Constructor ? ((Constructor>) converter).newInstance(v) : ((Method) converter)
73 | .invoke(null, v);
74 | }
75 | // TODO should at least debug we couldn't convert the value
76 | catch (Exception e) {
77 | }
78 | return null;
79 | }
80 |
81 | private String getCookieName(InjectionPoint ip) {
82 | String headerName = ip.getAnnotated().getAnnotation(CookieParam.class).value();
83 | if ("".equals(headerName)) {
84 | headerName = ip.getMember().getName();
85 | }
86 | return headerName;
87 | }
88 |
89 | private Cookie getCookie(String cookieName, InjectionPoint ip) {
90 | Cookie cookie = null;
91 | for (Cookie c : request.getCookies()) {
92 | if (c.getName().equals(cookieName)) {
93 | cookie = c;
94 | break;
95 | }
96 | }
97 |
98 | if (cookie == null) {
99 | String defaultValue = getDefaultValue(ip);
100 | if (defaultValue != null) {
101 | cookie = new Cookie(cookieName, defaultValue);
102 | }
103 | }
104 |
105 | return cookie;
106 | }
107 |
108 | private String getCookieValue(String cookieName, InjectionPoint ip) {
109 | // do we have to do any specific filtering here?
110 | for (Cookie c : request.getCookies()) {
111 | if (c.getName().equals(cookieName)) {
112 | return c.getValue();
113 | }
114 | }
115 | return getDefaultValue(ip);
116 | }
117 |
118 | private String getDefaultValue(InjectionPoint ip) {
119 | DefaultValue defaultValueAnnotation = ip.getAnnotated().getAnnotation(DefaultValue.class);
120 | return defaultValueAnnotation == null ? null : defaultValueAnnotation.value();
121 | }
122 |
123 | private Class> resolveExpectedType(final InjectionPoint ip) {
124 | Type t = ip.getType();
125 | if (t instanceof ParameterizedType && ((ParameterizedType) t).getActualTypeArguments().length == 1) {
126 | return (Class>) ((ParameterizedType) t).getActualTypeArguments()[0];
127 | } else if (t instanceof Class) {
128 | return (Class>) t;
129 | } else {
130 | return Object.class;
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/HeaderParamProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.reflect.Constructor;
20 | import java.lang.reflect.Member;
21 | import java.lang.reflect.Method;
22 | import java.lang.reflect.ParameterizedType;
23 | import java.lang.reflect.Type;
24 | import java.util.Enumeration;
25 |
26 | import javax.enterprise.inject.Produces;
27 | import javax.enterprise.inject.spi.InjectionPoint;
28 | import javax.inject.Inject;
29 | import javax.servlet.http.HttpServletRequest;
30 |
31 | import org.jboss.seam.servlet.ServletExtension;
32 | import org.jboss.seam.solder.reflection.PrimitiveTypes;
33 |
34 | /**
35 | * A producer for a String bean qualified @{@link HeaderParam}.
36 | *
37 | *
38 | * Provides a producer method that retrieves the value of the specified HTTP header from
39 | * {@link HttpServletRequest#getHeader(String)} and makes it available as a dependent-scoped bean of type String qualified
40 | * @HeaderParam. The name of the HTTP header to lookup is either the value of the @HeaderParam annotation or, if the
41 | * annotation value is empty, the name of the injection point (e.g., the field name).
42 | *
43 | *
44 | * If the HTTP header is not present, and the injection point is annotated with @DefaultValue, the value of the
45 | * @DefaultValue annotation is returned instead. If @DefaultValue is not present, null is returned.
46 | *
47 | *
48 | * @author Dan Allen
49 | * @see HeaderParam
50 | * @see DefaultValue
51 | */
52 | public class HeaderParamProducer {
53 | @Inject
54 | private HttpServletRequest request;
55 |
56 | @Produces
57 | @TypedParamValue
58 | // FIXME find better place to cache the valueOf methods
59 | protected Object getTypedParamValue(InjectionPoint ip, ServletExtension ext) {
60 | String v = getHeaderValue(getHeaderName(ip), ip);
61 | Class> t = PrimitiveTypes.box(resolveExpectedType(ip));
62 | if (t.equals(String.class)) {
63 | return v;
64 | }
65 | try {
66 | Member converter = ext.getConverterMember(t);
67 | return converter instanceof Constructor ? ((Constructor>) converter).newInstance(v) : ((Method) converter)
68 | .invoke(null, v);
69 | }
70 | // TODO should at least debug we couldn't convert the value
71 | catch (Exception e) {
72 | }
73 | return null;
74 | }
75 |
76 | private String getHeaderName(InjectionPoint ip) {
77 | String headerName = ip.getAnnotated().getAnnotation(HeaderParam.class).value();
78 | if ("".equals(headerName)) {
79 | headerName = ip.getMember().getName();
80 | }
81 | return headerName;
82 | }
83 |
84 | private String getHeaderValue(String headerName, InjectionPoint ip) {
85 | return isHeaderInRequest(headerName) ? request.getHeader(headerName) : getDefaultValue(ip);
86 | }
87 |
88 | private boolean isHeaderInRequest(String headerName) {
89 | for (Enumeration names = request.getHeaderNames(); names.hasMoreElements();) {
90 | if (names.nextElement().equals(headerName)) {
91 | return true;
92 | }
93 | }
94 | return false;
95 | }
96 |
97 | private String getDefaultValue(InjectionPoint ip) {
98 | DefaultValue defaultValueAnnotation = ip.getAnnotated().getAnnotation(DefaultValue.class);
99 | return defaultValueAnnotation == null ? null : defaultValueAnnotation.value();
100 | }
101 |
102 | private Class> resolveExpectedType(final InjectionPoint ip) {
103 | Type t = ip.getType();
104 | if (t instanceof ParameterizedType && ((ParameterizedType) t).getActualTypeArguments().length == 1) {
105 | return (Class>) ((ParameterizedType) t).getActualTypeArguments()[0];
106 | } else if (t instanceof Class) {
107 | return (Class>) t;
108 | } else {
109 | return Object.class;
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/ImplicitHttpServletObjectsProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.io.Serializable;
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | import javax.enterprise.context.RequestScoped;
24 | import javax.enterprise.inject.Produces;
25 | import javax.enterprise.inject.Typed;
26 | import javax.inject.Inject;
27 | import javax.servlet.http.Cookie;
28 | import javax.servlet.http.HttpServletRequest;
29 | import javax.servlet.http.HttpServletResponse;
30 | import javax.servlet.http.HttpSession;
31 |
32 | import org.jboss.seam.servlet.event.ImplicitServletObjectsHolder;
33 |
34 | /**
35 | * A producer for implicit HTTP Servlet objects, specifically the {@link HttpServletRequest}, {@link HttpServletResponse} and
36 | * {@link HttpSession}. References are obtained from the {@link ImplicitServletObjectsHolder}.
37 | *
38 | * TODO should probably throw IllegalStateException if accessed outside request
39 | *
40 | * @author Nicklas Karlsson
41 | * @author Dan Allen
42 | */
43 | public class ImplicitHttpServletObjectsProducer implements Serializable {
44 | @Inject
45 | private ImplicitServletObjectsHolder holder;
46 |
47 | @Produces
48 | @RequestScoped
49 | protected HttpSession getHttpSession() {
50 | return holder.getHttpSession();
51 | }
52 |
53 | @Produces
54 | @Typed(HttpServletRequestContext.class)
55 | @RequestScoped
56 | protected HttpServletRequestContext getHttpServletRequestContext() {
57 | return holder.getHttpServletRequestContext();
58 | }
59 |
60 | @Produces
61 | @Typed(HttpServletRequest.class)
62 | @RequestScoped
63 | protected HttpServletRequest getHttpServletRequest() {
64 | return holder.getHttpServletRequest();
65 | }
66 |
67 | @Produces
68 | @Typed(HttpServletResponse.class)
69 | @RequestScoped
70 | protected HttpServletResponse getHttpServletResponse() {
71 | return holder.getHttpServletResponse();
72 | }
73 |
74 | @Produces
75 | @RequestScoped
76 | protected List getCookies() {
77 | return Arrays.asList(getHttpServletRequest().getCookies());
78 | }
79 |
80 | @Produces
81 | @ContextPath
82 | protected String getContextPath() {
83 | return getHttpServletRequest().getContextPath();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/RedirectBuilderImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.io.IOException;
20 | import java.util.ArrayList;
21 | import java.util.Enumeration;
22 | import java.util.LinkedHashMap;
23 | import java.util.List;
24 | import java.util.Map;
25 | import java.util.Map.Entry;
26 |
27 | import javax.inject.Inject;
28 | import javax.servlet.http.Cookie;
29 | import javax.servlet.http.HttpServletRequest;
30 | import javax.servlet.http.HttpServletResponse;
31 |
32 | /**
33 | * @author Dan Allen
34 | */
35 | // todo support switching to https/http
36 | public class RedirectBuilderImpl implements RedirectBuilder {
37 | @Inject
38 | private HttpServletRequest request;
39 |
40 | @Inject
41 | private HttpServletResponse response;
42 |
43 | private String path = null;
44 |
45 | private String fragment = null;
46 |
47 | private Map paramMap = new LinkedHashMap();
48 |
49 | private Map headerMap = new LinkedHashMap();
50 |
51 | private List cookies = new ArrayList();
52 |
53 | private int status = HttpServletResponse.SC_MOVED_TEMPORARILY;
54 |
55 | private boolean encode = false;
56 |
57 | public RedirectBuilder mirror() {
58 | paramMap = new LinkedHashMap(request.getParameterMap());
59 | headerMap = new LinkedHashMap();
60 | for (Enumeration names = request.getHeaderNames(); names.hasMoreElements();) {
61 | String name = names.nextElement();
62 | List v = new ArrayList();
63 | for (Enumeration values = request.getHeaders(name); values.hasMoreElements();) {
64 | v.add(values.nextElement());
65 | }
66 | headerMap.put(name, v.toArray(new String[0]));
67 | }
68 | path = request.getRequestURI();
69 | if (path.indexOf("#") >= 0) {
70 | fragment = path.substring(path.indexOf("#") + 1);
71 | }
72 | return this;
73 | }
74 |
75 | public RedirectBuilder header(String name, Object... values) {
76 | return header(true, name, values);
77 | }
78 |
79 | public RedirectBuilder header(boolean replace, String name, Object... values) {
80 | List stringValues = new ArrayList(values.length);
81 | if (!replace && headerMap.containsKey(name)) {
82 | for (String existing : headerMap.get(name)) {
83 | stringValues.add(existing);
84 | }
85 | }
86 |
87 | for (Object value : values) {
88 | if (value != null) {
89 | stringValues.add(value.toString());
90 | }
91 | }
92 | headerMap.put(name, stringValues.toArray(new String[0]));
93 | return this;
94 | }
95 |
96 | public RedirectBuilder param(String name, Object... values) {
97 | return param(true, name, values);
98 | }
99 |
100 | public RedirectBuilder param(boolean replace, String name, Object... values) {
101 | List stringValues = new ArrayList(values.length);
102 | if (!replace && paramMap.containsKey(name)) {
103 | for (String existing : paramMap.get(name)) {
104 | stringValues.add(existing);
105 | }
106 | }
107 |
108 | for (Object value : values) {
109 | if (value != null) {
110 | stringValues.add(value.toString());
111 | }
112 | }
113 | paramMap.put(name, stringValues.toArray(new String[0]));
114 | return this;
115 | }
116 |
117 | public RedirectBuilder cookie(Cookie... cookies) {
118 | for (Cookie c : cookies) {
119 | this.cookies.add(c);
120 | }
121 | return this;
122 | }
123 |
124 | public RedirectBuilder fragment(String fragment) {
125 | this.fragment = fragment;
126 | return this;
127 | }
128 |
129 | public RedirectBuilder seeOther(String path) {
130 | status = HttpServletResponse.SC_SEE_OTHER;
131 | this.path = path;
132 | return this;
133 | }
134 |
135 | public RedirectBuilder temporaryRedirect(String path) {
136 | status = HttpServletResponse.SC_TEMPORARY_REDIRECT;
137 | this.path = path;
138 | return this;
139 | }
140 |
141 | public RedirectBuilder redirect() {
142 | return redirect(null);
143 | }
144 |
145 | // TODO respect query string on path
146 | public RedirectBuilder redirect(String path) {
147 | status = HttpServletResponse.SC_MOVED_TEMPORARILY;
148 | this.path = path;
149 | return this;
150 | }
151 |
152 | public RedirectBuilder encodeSessionId() {
153 | encode = true;
154 | return this;
155 | }
156 |
157 | public void send() {
158 | if (response.isCommitted()) {
159 | throw new RuntimeException("Cannot issue redirect. Response already committed.");
160 | }
161 |
162 | String location = path;
163 | if (location == null) {
164 | location = request.getRequestURI();
165 | } else if (!location.startsWith("/")) {
166 | location = request.getContextPath() + location;
167 | }
168 |
169 | for (Entry headers : headerMap.entrySet()) {
170 | String name = headers.getKey();
171 | for (String value : headers.getValue()) {
172 | response.addHeader(name, value);
173 | }
174 | }
175 |
176 | for (Cookie c : cookies) {
177 | response.addCookie(c);
178 | }
179 |
180 | String query = "";
181 | for (Entry params : paramMap.entrySet()) {
182 | String name = params.getKey();
183 | for (String value : params.getValue()) {
184 | // FIXME naive
185 | query += (query.length() == 0 ? "?" : "&") + name + "=" + value;
186 | }
187 | }
188 |
189 | location += query;
190 |
191 | if (fragment != null) {
192 | location += "#" + fragment;
193 | }
194 |
195 | try {
196 | response.resetBuffer();
197 | if (encode) {
198 | location = response.encodeRedirectURL(location);
199 | }
200 | response.setHeader("Location", location);
201 | response.setStatus(status);
202 | response.getWriter().flush();
203 | // more flexible to do it ourselves
204 | // response.sendRedirect(response.encodeRedirectURL(location));
205 | } catch (IOException e) {
206 | throw new RuntimeException("Failed to issue redirect. " + e.getMessage());
207 | }
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/RequestParamProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.reflect.Constructor;
20 | import java.lang.reflect.Member;
21 | import java.lang.reflect.Method;
22 | import java.lang.reflect.ParameterizedType;
23 | import java.lang.reflect.Type;
24 |
25 | import javax.enterprise.inject.Produces;
26 | import javax.enterprise.inject.spi.InjectionPoint;
27 | import javax.inject.Inject;
28 | import javax.servlet.http.HttpServletRequest;
29 |
30 | import org.jboss.seam.servlet.ServletExtension;
31 | import org.jboss.seam.solder.reflection.PrimitiveTypes;
32 |
33 | /**
34 | * A producer for a String bean qualified @{@link RequestParam}.
35 | *
36 | *
37 | * Provides a producer method that retrieves the value of the specified request parameter from
38 | * {@link HttpServletRequest#getParameter(String)} and makes it available as a dependent-scoped bean of type String qualified
39 | * @RequestParam. The name of the request parameter to lookup is either the value of the @RequestParam annotation or,
40 | * if the annotation value is empty, the name of the injection point (e.g., the field name).
41 | *
42 | *
43 | * If the request parameter is not present, and the injection point is annotated with @DefaultValue, the value of the
44 | * @DefaultValue annotation is returned instead. If @DefaultValue is not present, null is returned.
45 | *
46 | *
47 | * @author Nicklas Karlsson
48 | * @author Dan Allen
49 | * @see RequestParam
50 | * @see DefaultValue
51 | */
52 | public class RequestParamProducer {
53 | @Inject
54 | private HttpServletRequest request;
55 |
56 | @Produces
57 | @TypedParamValue
58 | // FIXME find better place to cache the valueOf methods
59 | // TODO support collection values
60 | protected Object getTypedParamValue(InjectionPoint ip, ServletExtension ext) {
61 | String v = getParameterValue(getParameterName(ip), ip);
62 | Class> t = PrimitiveTypes.box(resolveExpectedType(ip));
63 | if (t.equals(String.class)) {
64 | return v;
65 | }
66 | try {
67 | Member converter = ext.getConverterMember(t);
68 | return converter instanceof Constructor ? ((Constructor>) converter).newInstance(v) : ((Method) converter)
69 | .invoke(null, v);
70 | }
71 | // TODO should at least debug we couldn't convert the value
72 | catch (Exception e) {
73 | }
74 | return null;
75 | }
76 |
77 | private String getParameterName(InjectionPoint ip) {
78 | String parameterName = ip.getAnnotated().getAnnotation(RequestParam.class).value();
79 | if ("".equals(parameterName)) {
80 | parameterName = ip.getMember().getName();
81 | }
82 | return parameterName;
83 | }
84 |
85 | private String getParameterValue(String parameterName, InjectionPoint ip) {
86 | return isParameterInRequest(parameterName) ? request.getParameter(parameterName) : getDefaultValue(ip);
87 | }
88 |
89 | private boolean isParameterInRequest(String parameterName) {
90 | return request.getParameterMap().containsKey(parameterName);
91 | }
92 |
93 | private String getDefaultValue(InjectionPoint ip) {
94 | DefaultValue defaultValueAnnotation = ip.getAnnotated().getAnnotation(DefaultValue.class);
95 | return defaultValueAnnotation == null ? null : defaultValueAnnotation.value();
96 | }
97 |
98 | private Class> resolveExpectedType(final InjectionPoint ip) {
99 | Type t = ip.getType();
100 | if (t instanceof ParameterizedType && ((ParameterizedType) t).getActualTypeArguments().length == 1) {
101 | return (Class>) ((ParameterizedType) t).getActualTypeArguments()[0];
102 | } else if (t instanceof Class) {
103 | return (Class>) t;
104 | } else {
105 | return Object.class;
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/TemporalConverters.java:
--------------------------------------------------------------------------------
1 | package org.jboss.seam.servlet.http;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Calendar;
6 | import java.util.Date;
7 |
8 | public class TemporalConverters {
9 | public static final String[] DATE_TIME_PATTERNS = {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd"};
10 |
11 | public static Date parseDate(String source) {
12 | for (String pattern : DATE_TIME_PATTERNS) {
13 | try {
14 | return new SimpleDateFormat(pattern).parse(source);
15 | } catch (ParseException e) {
16 | }
17 | }
18 | return null;
19 | }
20 |
21 | public static Calendar parseCalendar(String source) {
22 | Calendar calendar = Calendar.getInstance();
23 | calendar.setTime(parseDate(source));
24 | return calendar;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/http/TypedParamValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * by the @authors tag. See the copyright.txt in the distribution for a
5 | * full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.http;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | import javax.inject.Qualifier;
26 |
27 | /**
28 | * @author Dan Allen
29 | */
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Qualifier
32 | @Documented
33 | @Target(ElementType.METHOD)
34 | public @interface TypedParamValue {
35 | }
36 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/logging/TypedMessageBundle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
4 | * contributors by the @authors tag. See the copyright.txt in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.logging;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import javax.inject.Qualifier;
24 |
25 | import static java.lang.annotation.ElementType.FIELD;
26 | import static java.lang.annotation.ElementType.METHOD;
27 | import static java.lang.annotation.ElementType.PARAMETER;
28 | import static java.lang.annotation.ElementType.TYPE;
29 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
30 |
31 | /**
32 | * Internal-qualifier used to identify the typed message bundle producer for the wrapping bean.
33 | *
34 | * TEMPORARY UNTIL GLASSFISH-15735
35 | *
36 | * @author Pete Muir
37 | */
38 | @Qualifier
39 | @Target({TYPE, METHOD, PARAMETER, FIELD})
40 | @Retention(RUNTIME)
41 | @Documented
42 | @interface TypedMessageBundle {
43 | }
44 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/jboss/seam/servlet/logging/TypedMessageBundleAndLoggerExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source
3 | * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
4 | * contributors by the @authors tag. See the copyright.txt in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.jboss.seam.servlet.logging;
18 |
19 | import java.util.Collection;
20 | import java.util.HashSet;
21 |
22 | import javax.enterprise.event.Observes;
23 | import javax.enterprise.inject.spi.AfterBeanDiscovery;
24 | import javax.enterprise.inject.spi.AfterDeploymentValidation;
25 | import javax.enterprise.inject.spi.AnnotatedMethod;
26 | import javax.enterprise.inject.spi.AnnotatedType;
27 | import javax.enterprise.inject.spi.Bean;
28 | import javax.enterprise.inject.spi.BeanManager;
29 | import javax.enterprise.inject.spi.Extension;
30 | import javax.enterprise.inject.spi.ProcessAnnotatedType;
31 | import javax.enterprise.inject.spi.ProcessProducerMethod;
32 |
33 | import org.jboss.seam.solder.bean.NarrowingBeanBuilder;
34 | import org.jboss.seam.solder.literal.MessageBundleLiteral;
35 | import org.jboss.seam.logging.MessageLogger;
36 | import org.jboss.seam.solder.messages.MessageBundle;
37 |
38 | /**
39 | * Adds TypedMessageBundleAndLoggerProducers to the deployment, and detects and installs beans for any typed loggers defined.
40 | *
41 | * TEMPORARY UNTIL GLASSFISH-15735 is resolved
42 | *
43 | * @author Pete Muir
44 | */
45 | public class TypedMessageBundleAndLoggerExtension implements Extension {
46 | private final Collection> messageLoggerTypes;
47 | private final Collection> messageBundleTypes;
48 | private Bean