You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/08/28 09:14:16 UTC
svn commit: r570338 - in /wicket/trunk:
jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/
jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/
jdk-1.5/wicket-examples/src/main/webapp/WEB-INF/
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
- * {@link org.apache.wicket.protocol.http.WebSession} instances available to
- * non-wicket servlets.
+ * This filter can be used to make the Wicket {@link 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>
- * <filter>
- * <filter-name>WicketSessionFilter</filter-name>
- * <filter-class>org.apache.wicket.protocol.http.servlet.WicketSessionFilter</filter-class>
- * <init-param>
- * <param-name>servletPath</param-name>
- * <param-value>sessiontest</param-value>
- * </init-param>
- * </filter>
- *
- * <filter-mapping>
- * <filter-name>WicketSessionFilter</filter-name>
- * <url-pattern>/servlet/sessiontest</url-pattern>
- * </filter-mapping>
- *
- * <servlet>
- * <servlet-name>SessionApplication</servlet-name>
- * <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
- * <init-param>
- * <param-name>applicationClassName</param-name>
- * <param-value>session.SessionApplication</param-value>
- * </init-param>
- * <load-on-startup>1</load-on-startup>
- * </servlet>
- *
- * <servlet>
- * <servlet-name>WicketSessionServlet</servlet-name>
- * <servlet-class>session.WicketSessionServlet</servlet-class>
- * <load-on-startup>1</load-on-startup>
- * </servlet>
- *
- * <servlet-mapping>
- * <servlet-name>SessionApplication</servlet-name>
- * <url-pattern>/sessiontest/*</url-pattern>
- * </servlet-mapping>
- *
- * <servlet-mapping>
- * <servlet-name>WicketSessionServlet</servlet-name>
- * <url-pattern>/servlet/sessiontest</url-pattern>
- * </servlet-mapping>
+ * <!-- 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>
+ * ...
+ *
+ * <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>
* </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("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();
+ * }
+ * }
* </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 {@link 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>