1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.myfaces.orchestra.frameworkAdapter.jsf;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.myfaces.orchestra.lib._UrlMatcher;
25
26 import javax.servlet.Filter;
27 import javax.servlet.FilterChain;
28 import javax.servlet.FilterConfig;
29 import javax.servlet.ServletException;
30 import javax.servlet.ServletRequest;
31 import javax.servlet.ServletResponse;
32 import java.io.IOException;
33
34 /**
35 * Configures the JsfFrameworkAdapter.
36 * <p>
37 * Orchestra accesses information about the request, response, session, etc via a
38 * FrameworkAdapter so that it can be used with multiple web tier frameworks. This
39 * class selects and configures the JSF version of this adapter.
40 * <p>
41 * Note that the conversation.jsf.OrchestraServletFilter class executes this class
42 * as a "subfilter", so defining this filter is not required if that filter is
43 * already defined.
44 * <p>
45 * If filter config parameter "conversationMessagerClass" is set, then this is
46 * passed to the BasicFrameworkAdapter, meaning that this can be either a
47 * beanname defined in the dependency-injection framework, or an absolute
48 * classname of a type implementing ConversationMessager.
49 * <p>
50 * Note that this class is generally only needed in Orchestra 1.0. In later
51 * releases the OrchestraFacesContextFactory configures the JsfFrameworkAdapter
52 * instead, requiring less configuration. However this class can be used if the
53 * OrchestraFacesContextFactory approach cannot be used for some reason.
54 */
55 public class JsfFrameworkAdapterFilter implements Filter
56 {
57 private final static String INIT_CONVERSATION_MESSAGER = "conversationMessagerClass";
58
59 private final Log log = LogFactory.getLog(JsfFrameworkAdapterFilter.class);
60 private JsfFrameworkAdapter adapter;
61 private _UrlMatcher urlMatcher;
62
63 public void init(FilterConfig filterConfig) throws ServletException
64 {
65 String conversationMessager = filterConfig.getInitParameter(INIT_CONVERSATION_MESSAGER);
66
67 adapter = new JsfFrameworkAdapter(conversationMessager);
68 urlMatcher = new _UrlMatcher(filterConfig);
69 }
70
71 public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain filterChain)
72 throws IOException, ServletException
73 {
74 if (!urlMatcher.accept(req))
75 {
76 filterChain.doFilter(req, rsp);
77 return;
78 }
79
80 if (log.isDebugEnabled())
81 {
82 log.debug("doFilter");
83 }
84 try
85 {
86 adapter.beginRequest();
87 filterChain.doFilter(req, rsp);
88 }
89 finally
90 {
91 adapter.endRequest();
92 }
93 }
94
95 public void destroy()
96 {
97 }
98 }