Author: ehillenius
Date: Tue Aug 28 00:14:13 2007
New Revision: 570338

URL: http://svn.apache.org/viewvc?rev=570338&view=rev
Log:
WICKET-897

Added:
    
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/HelloWorldServlet.java
Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilter.java
    wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilter.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilter.java?rev=570338&r1=570337&r2=570338&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilter.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilter.java
 Tue Aug 28 00:14:13 2007
@@ -31,65 +31,69 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * <p>
- * This filter can be used to make the Wicket
- * [EMAIL PROTECTED] org.apache.wicket.protocol.http.WebSession} instances 
available to
- * non-wicket servlets.
+ * This filter can be used to make the Wicket [EMAIL PROTECTED] 
org.apache.wicket.protocol.http.WebSession}
+ * instances available to non-wicket servlets.
  * </p>
  * <p>
- * The following example displays how you can make the Wicket session object of
- * application SessionApplication, mapped on <code>/sessiontest/*</code>
- * available for servlet WicketSessionServlet, mapped under
- * <code>/servlet/sessiontest</code>:
+ * The following example shows how this filter is setup to for a servlet. You 
can find the example
+ * in the wicket-examples project.
  * 
  * <pre>
- *    &lt;filter&gt;
- *      &lt;filter-name&gt;WicketSessionFilter&lt;/filter-name&gt;
- *      
&lt;filter-class&gt;org.apache.wicket.protocol.http.servlet.WicketSessionFilter&lt;/filter-class&gt;
- *      &lt;init-param&gt;
- *        &lt;param-name&gt;servletPath&lt;/param-name&gt;
- *        &lt;param-value&gt;sessiontest&lt;/param-value&gt;
- *      &lt;/init-param&gt;
- *    &lt;/filter&gt;
- *   
- *    &lt;filter-mapping&gt;
- *      &lt;filter-name&gt;WicketSessionFilter&lt;/filter-name&gt;
- *      &lt;url-pattern&gt;/servlet/sessiontest&lt;/url-pattern&gt;
- *    &lt;/filter-mapping&gt;
- *   
- *    &lt;servlet&gt;
- *      &lt;servlet-name&gt;SessionApplication&lt;/servlet-name&gt;
- *      
&lt;servlet-class&gt;org.apache.wicket.protocol.http.WicketServlet&lt;/servlet-class&gt;
- *      &lt;init-param&gt;
- *        &lt;param-name&gt;applicationClassName&lt;/param-name&gt;
- *        &lt;param-value&gt;session.SessionApplication&lt;/param-value&gt;
- *      &lt;/init-param&gt;
- *      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
- *    &lt;/servlet&gt;
- *   
- *    &lt;servlet&gt;
- *      &lt;servlet-name&gt;WicketSessionServlet&lt;/servlet-name&gt;
- *      &lt;servlet-class&gt;session.WicketSessionServlet&lt;/servlet-class&gt;
- *      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
- *    &lt;/servlet&gt;
- *   
- *    &lt;servlet-mapping&gt;
- *      &lt;servlet-name&gt;SessionApplication&lt;/servlet-name&gt;
- *      &lt;url-pattern&gt;/sessiontest/*&lt;/url-pattern&gt;
- *    &lt;/servlet-mapping&gt;
- *   
- *    &lt;servlet-mapping&gt;
- *      &lt;servlet-name&gt;WicketSessionServlet&lt;/servlet-name&gt;
- *      &lt;url-pattern&gt;/servlet/sessiontest&lt;/url-pattern&gt;
- *    &lt;/servlet-mapping&gt;
+ *  &lt;!-- The WicketSesionFilter can be used to provide thread local access 
to servlets/ JSPs/ etc --&gt;
+ *  &lt;filter&gt;
+ *    &lt;filter-name&gt;WicketSessionFilter&lt;/filter-name&gt;
+ *    
&lt;filter-class&gt;org.apache.wicket.protocol.http.servlet.WicketSessionFilter&lt;/filter-class&gt;
+ *    &lt;init-param&gt;
+ *      &lt;param-name&gt;filterName&lt;/param-name&gt;
+ *      &lt;!-- expose the session of the input example app --&gt;
+ *      &lt;param-value&gt;FormInputApplication&lt;/param-value&gt;
+ *    &lt;/init-param&gt;
+ *  &lt;/filter&gt;
+ * 
+ *  &lt;!-- couple the session filter to the helloworld servlet --&gt;
+ *  &lt;filter-mapping&gt;
+ *    &lt;filter-name&gt;WicketSessionFilter&lt;/filter-name&gt;
+ *    &lt;url-pattern&gt;/helloworldservlet/*&lt;/url-pattern&gt;
+ *  &lt;/filter-mapping&gt;
+ *  ...
+ * 
+ *  &lt;servlet&gt;
+ *    &lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
+ *    
&lt;servlet-class&gt;org.apache.wicket.examples.HelloWorldServlet&lt;/servlet-class&gt;
+ *  &lt;/servlet&gt;
+ * 
+ *  &lt;servlet-mapping&gt;
+ *    &lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
+ *    &lt;url-pattern&gt;/helloworldservlet/*&lt;/url-pattern&gt;
+ *  &lt;/servlet-mapping&gt;
  * </pre>
  * 
  * After that, you can get to the Wicket session in the usual fashion:
  * 
  * <pre>
- * org.apache.wicket.Session wicketSession = org.apache.wicket.Session.get();
+ * Session wicketSession = Session.get();
+ * </pre>
+ * 
+ * like the HelloWorldServlet does:
+ * 
+ * <pre>
+ * public class HelloWorldServlet extends HttpServlet
+ * {
+ *     public void doGet(HttpServletRequest req, HttpServletResponse res) 
throws ServletException,
+ *                     IOException
+ *     {
+ *             res.setContentType(&quot;text/html&quot;);
+ *             PrintWriter out = res.getWriter();
+ *             String message = &quot;Hi. &quot; +
+ *                             (Session.exists()
+ *                                             ? &quot; I know Wicket session 
&quot; + Session.get() + &quot;.&quot;
+ *                                             : &quot; I can't find a Wicket 
session.&quot;);
+ *             out.println(message);
+ *             out.close();
+ *     }
+ * }
  * </pre>
  * 
  * </p>
@@ -103,8 +107,8 @@
 
        private FilterConfig filterConfig;
 
-       /** the servlet path. */
-       private String servletPath;
+       /** the filter name/ application key. */
+       private String filterName;
 
        /** the session key where the Wicket session should be stored. */
        private String sessionKey;
@@ -123,26 +127,21 @@
        {
                this.filterConfig = filterConfig;
 
-               servletPath = filterConfig.getInitParameter("servletPath");
+               filterName = filterConfig.getInitParameter("filterName");
 
-               if (servletPath == null)
+               if (filterName == null)
                {
                        throw new ServletException(
-                                       "you must provide init parameter 
servlet-path if you want to use " +
+                                       "you must provide init parameter 
'filterName if you want to use " +
                                                        getClass().getName());
                }
 
-               if (servletPath.charAt(0) != '/')
-               {
-                       servletPath = '/' + servletPath;
-               }
-
                if (log.isDebugEnabled())
                {
-                       log.debug("servlet path set to " + servletPath);
+                       log.debug("filterName/ application key set to " + 
filterName);
                }
 
-               sessionKey = "wicket:" + servletPath + ":" + 
Session.SESSION_ATTRIBUTE_NAME;
+               sessionKey = "wicket:" + filterName + ":" + 
Session.SESSION_ATTRIBUTE_NAME;
 
                if (log.isDebugEnabled())
                {

Added: 
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/HelloWorldServlet.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/HelloWorldServlet.java?rev=570338&view=auto
==============================================================================
--- 
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/HelloWorldServlet.java
 (added)
+++ 
wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/HelloWorldServlet.java
 Tue Aug 28 00:14:13 2007
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.examples;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.wicket.Session;
+import org.apache.wicket.protocol.http.servlet.WicketSessionFilter;
+
+/**
+ * Simple servlet that if configured with [EMAIL PROTECTED] 
WicketSessionFilter} prints the
+ * current session.
+ */
+public class HelloWorldServlet extends HttpServlet
+{
+       /**
+        * @see 
javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
+        *      javax.servlet.http.HttpServletResponse)
+        */
+       public void doGet(HttpServletRequest req, HttpServletResponse res) 
throws ServletException,
+                       IOException
+       {
+               res.setContentType("text/html");
+               PrintWriter out = res.getWriter();
+               String message = "Hi. " +
+                               (Session.exists()
+                                               ? " I know Wicket session " + 
Session.get() + "."
+                                               : " I can't find a Wicket 
session.");
+               out.println(message);
+               out.close();
+       }
+
+}

Modified: wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml?rev=570338&r1=570337&r2=570338&view=diff
==============================================================================
--- wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml 
(original)
+++ wicket/trunk/jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/web.xml Tue 
Aug 28 00:14:13 2007
@@ -387,6 +387,23 @@
             
<param-value>org.apache.wicket.examples.dates.DatesApplication</param-value>
                </init-param>
        </filter>
+       
+       <!-- The WicketSesionFilter can be used to provide thread local access 
to servlets/ JSPs/ etc -->
+       <filter>
+               <filter-name>WicketSessionFilter</filter-name>
+               
<filter-class>org.apache.wicket.protocol.http.servlet.WicketSessionFilter</filter-class>
+               <init-param>
+            <param-name>filterName</param-name>
+            <!-- expose the session of the input example app -->
+            <param-value>FormInputApplication</param-value>
+               </init-param>
+       </filter>
+
+       <!-- couple the session filter to the helloworld servlet -->
+       <filter-mapping>
+               <filter-name>WicketSessionFilter</filter-name>
+               <url-pattern>/helloworldservlet/*</url-pattern>
+       </filter-mapping>
 
        <filter-mapping>
                <filter-name>AjaxApplication</filter-name>
@@ -576,6 +593,16 @@
        <listener>
                
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
+
+       <servlet>
+               <servlet-name>HelloWorldServlet</servlet-name>
+               
<servlet-class>org.apache.wicket.examples.HelloWorldServlet</servlet-class>
+       </servlet>
+
+       <servlet-mapping>
+               <servlet-name>HelloWorldServlet</servlet-name>
+               <url-pattern>/helloworldservlet/*</url-pattern>
+       </servlet-mapping>
 
        <session-config>
                <session-timeout>5</session-timeout>


Reply via email to