升级Tomcat版本 apache-tomcat-7.0.77
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.class b/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.class
index bc8e321..5b481e7 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.java b/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.java
index 5d7d5ce..b3e1c09 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/CookieExample.java
@@ -15,10 +15,15 @@
* limitations under the License.
*/
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ResourceBundle;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import util.HTMLFilter;
@@ -30,29 +35,42 @@
public class CookieExample extends HttpServlet {
- ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
-
+ private static final long serialVersionUID = 1L;
+
+ private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
+
+ @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
+
+ String cookieName = request.getParameter("cookiename");
+ String cookieValue = request.getParameter("cookievalue");
+ Cookie aCookie = null;
+ if (cookieName != null && cookieValue != null) {
+ aCookie = new Cookie(cookieName, cookieValue);
+ aCookie.setPath(request.getContextPath() + "/");
+ response.addCookie(aCookie);
+ }
+
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
- String title = rb.getString("cookies.title");
+ String title = RB.getString("cookies.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
- // relative links
+ // relative links
// XXX
// making these absolute till we work out the
- // addition of a PathInfo issue
-
+ // addition of a PathInfo issue
+
out.println("<a href=\"../cookies.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
@@ -64,47 +82,44 @@
Cookie[] cookies = request.getCookies();
if ((cookies != null) && (cookies.length > 0)) {
- out.println(rb.getString("cookies.cookies") + "<br>");
+ out.println(RB.getString("cookies.cookies") + "<br>");
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
out.print("Cookie Name: " + HTMLFilter.filter(cookie.getName())
+ "<br>");
- out.println(" Cookie Value: "
+ out.println(" Cookie Value: "
+ HTMLFilter.filter(cookie.getValue())
+ "<br><br>");
}
} else {
- out.println(rb.getString("cookies.no-cookies"));
+ out.println(RB.getString("cookies.no-cookies"));
}
- String cookieName = request.getParameter("cookiename");
- String cookieValue = request.getParameter("cookievalue");
- if (cookieName != null && cookieValue != null) {
- Cookie cookie = new Cookie(cookieName, cookieValue);
- response.addCookie(cookie);
+ if (aCookie != null) {
out.println("<P>");
- out.println(rb.getString("cookies.set") + "<br>");
- out.print(rb.getString("cookies.name") + " "
+ out.println(RB.getString("cookies.set") + "<br>");
+ out.print(RB.getString("cookies.name") + " "
+ HTMLFilter.filter(cookieName) + "<br>");
- out.print(rb.getString("cookies.value") + " "
+ out.print(RB.getString("cookies.value") + " "
+ HTMLFilter.filter(cookieValue));
}
-
+
out.println("<P>");
- out.println(rb.getString("cookies.make-cookie") + "<br>");
+ out.println(RB.getString("cookies.make-cookie") + "<br>");
out.print("<form action=\"");
out.println("CookieExample\" method=POST>");
- out.print(rb.getString("cookies.name") + " ");
+ out.print(RB.getString("cookies.name") + " ");
out.println("<input type=text length=20 name=cookiename><br>");
- out.print(rb.getString("cookies.value") + " ");
+ out.print(RB.getString("cookies.value") + " ");
out.println("<input type=text length=20 name=cookievalue><br>");
out.println("<input type=submit></form>");
-
-
+
+
out.println("</body>");
out.println("</html>");
}
+ @Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.class b/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.class
index 0d3c85e..41e3c40 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.java b/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.java
index 3702542..9902e3b 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/HelloWorldExample.java
@@ -14,11 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ResourceBundle;
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
/**
* The simplest possible servlet.
@@ -28,7 +31,9 @@
public class HelloWorldExample extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+ @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
@@ -41,22 +46,22 @@
out.println("<html>");
out.println("<head>");
- String title = rb.getString("helloworld.title");
+ String title = rb.getString("helloworld.title");
- out.println("<title>" + title + "</title>");
+ out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
- // note that all links are created to be relative. this
- // ensures that we can move the web application that this
- // servlet belongs to to a different place in the url
- // tree and not have any harmful side effects.
+ // note that all links are created to be relative. this
+ // ensures that we can move the web application that this
+ // servlet belongs to to a different place in the url
+ // tree and not have any harmful side effects.
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
- out.println("<a href=\"../helloworld.html\">");
+ out.println("<a href=\"../helloworld.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"../index.html\">");
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/LocalStrings_es.properties b/tomcat-cas/webapps/examples/WEB-INF/classes/LocalStrings_es.properties
index f5a1261..009e34d 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/LocalStrings_es.properties
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/LocalStrings_es.properties
@@ -12,40 +12,31 @@
# 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.
-
-# Default localized string information
-# Localized para Locale es_ES
-
-helloworld.title=Hola Mundo!
-
-requestinfo.title=Ejemplo de Informacion de Request
-requestinfo.label.method=Metodo:
-requestinfo.label.requesturi=Request URI:
-requestinfo.label.protocol=Protocolo:
-requestinfo.label.pathinfo=Path Info:
-requestinfo.label.remoteaddr=Direccion Remota:
-
-requestheader.title=Ejemplo de Cabecera de Request
-
-requestparams.title=Ejemplo de parametros de Request
-requestparams.params-in-req=Parametros en este Request:
-requestparams.no-params=No hay parametro. por favor usa alguno
-requestparams.firstname=Nombre:
-requestparams.lastname=Apellidos:
-
-cookies.title=Ejemplo de Cookies
-cookies.cookies=Tu navegador esta enviando los siguientes cookies:
-cookies.no-cookies=Tu navegador no esta enviando cookies
-cookies.make-cookie=Crea un cookie para enviarlo a tu navegador
-cookies.name=Nombre:
-cookies.value=Valor:
-cookies.set=Acabas de enviar a tu navegador estos cookies:
-
-sessions.title=ejemplo de Sesiones
-sessions.id=ID de Sesion:
-sessions.created=Creado:
-sessions.lastaccessed=Ultimo Acceso:
-sessions.data=Lo siguientes datos estan en tu sesion:
-sessions.adddata=A\u00f1ade datos a tu sesion:
-sessions.dataname=Nombre del atributo de sesion:
-sessions.datavalue=Valor del atributo de sesion:
+helloworld.title = Hola Mundo\!
+requestinfo.title = Ejemplo de Informacion de Requerimiento\:
+requestinfo.label.method = M\u00E9todo\:
+requestinfo.label.requesturi = URI de Requerimiento\:
+requestinfo.label.protocol = Protocolo\:
+requestinfo.label.pathinfo = Info de Ruta\:
+requestinfo.label.remoteaddr = Direccion Remota\:
+requestheader.title = Ejemplo de Cabecera de Requerimiento\:
+requestparams.title = Ejemplo de par\u00E1metros de Requerimiento\:
+requestparams.params-in-req = Par\u00E1metros en este Request\:
+requestparams.no-params = No hay p\u00E1rametro. Por favor, usa alguno
+requestparams.firstname = Nombre\:
+requestparams.lastname = Apellidos\:
+cookies.title = Ejemplo de Cookies
+cookies.cookies = Tu navegador est\u00E1 enviando los siguientes cookies\:
+cookies.no-cookies = Tu navegador no est\u00E1 enviando cookies
+cookies.make-cookie = Crea un cookie para enviarlo a tu navegador
+cookies.name = Nombre\:
+cookies.value = Valor\:
+cookies.set = Acabas de enviar a tu navegador estos cookies\:
+sessions.title = Ejemplo de Sesiones
+sessions.id = ID de Sesi\u00F3n\:
+sessions.created = Creado\:
+sessions.lastaccessed = Ultimo Acceso\:
+sessions.data = Lo siguientes datos est\u00E1n en tu sesi\u00F3n\:
+sessions.adddata = A\u00F1ade datos a tu sesi\u00F3n\:
+sessions.dataname = Nombre del atributo de sesi\u00F3n\:
+sessions.datavalue = Valor del atributo de sesi\u00F3n\:
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.class b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.class
index 8270f63..23151e8 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.java b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
index 2a550f2..2010767 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
@@ -15,11 +15,19 @@
* limitations under the License.
*/
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import util.CookieFilter;
import util.HTMLFilter;
/**
@@ -30,8 +38,11 @@
public class RequestHeaderExample extends HttpServlet {
- ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
-
+ private static final long serialVersionUID = 1L;
+
+ private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
+
+ @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
@@ -42,17 +53,17 @@
out.println("<html>");
out.println("<head>");
- String title = rb.getString("requestheader.title");
+ String title = RB.getString("requestheader.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
- // all links relative
+ // all links relative
// XXX
// making these absolute till we work out the
- // addition of a PathInfo issue
-
+ // addition of a PathInfo issue
+
out.println("<a href=\"../reqheaders.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
@@ -62,19 +73,29 @@
out.println("<h3>" + title + "</h3>");
out.println("<table border=0>");
- Enumeration e = request.getHeaderNames();
+ Enumeration<String> e = request.getHeaderNames();
while (e.hasMoreElements()) {
- String headerName = (String)e.nextElement();
+ String headerName = e.nextElement();
String headerValue = request.getHeader(headerName);
out.println("<tr><td bgcolor=\"#CCCCCC\">");
out.println(HTMLFilter.filter(headerName));
out.println("</td><td>");
- out.println(HTMLFilter.filter(headerValue));
+ if (headerName.toLowerCase(Locale.ENGLISH).contains("cookie")) {
+ HttpSession session = request.getSession(false);
+ String sessionId = null;
+ if (session != null) {
+ sessionId = session.getId();
+ }
+ out.println(HTMLFilter.filter(CookieFilter.filter(headerValue, sessionId)));
+ } else {
+ out.println(HTMLFilter.filter(headerValue));
+ }
out.println("</td></tr>");
}
out.println("</table>");
}
+ @Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.class b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.class
index e93ed68..b060caf 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.java b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.java
index 86313e5..1f429e8 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestInfoExample.java
@@ -15,10 +15,14 @@
* limitations under the License.
*/
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ResourceBundle;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import util.HTMLFilter;
@@ -30,9 +34,11 @@
public class RequestInfoExample extends HttpServlet {
+ private static final long serialVersionUID = 1L;
- ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
+ private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
+ @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
@@ -43,7 +49,7 @@
out.println("<html>");
out.println("<head>");
- String title = rb.getString("requestinfo.title");
+ String title = RB.getString("requestinfo.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
@@ -64,23 +70,23 @@
out.println("<h3>" + title + "</h3>");
out.println("<table border=0><tr><td>");
- out.println(rb.getString("requestinfo.label.method"));
+ out.println(RB.getString("requestinfo.label.method"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getMethod()));
out.println("</td></tr><tr><td>");
- out.println(rb.getString("requestinfo.label.requesturi"));
+ out.println(RB.getString("requestinfo.label.requesturi"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getRequestURI()));
out.println("</td></tr><tr><td>");
- out.println(rb.getString("requestinfo.label.protocol"));
+ out.println(RB.getString("requestinfo.label.protocol"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getProtocol()));
out.println("</td></tr><tr><td>");
- out.println(rb.getString("requestinfo.label.pathinfo"));
+ out.println(RB.getString("requestinfo.label.pathinfo"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getPathInfo()));
out.println("</td></tr><tr><td>");
- out.println(rb.getString("requestinfo.label.remoteaddr"));
+ out.println(RB.getString("requestinfo.label.remoteaddr"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getRemoteAddr()));
out.println("</td></tr>");
@@ -98,6 +104,7 @@
out.println("</table>");
}
+ @Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.class b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.class
index dccd0ba..a0233b4 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.java b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.java
index 2b8b77c..a4c5c67 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/RequestParamExample.java
@@ -15,10 +15,14 @@
* limitations under the License.
*/
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ResourceBundle;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import util.HTMLFilter;
@@ -30,9 +34,11 @@
public class RequestParamExample extends HttpServlet {
+ private static final long serialVersionUID = 1L;
- ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
-
+ private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
+
+ @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
@@ -43,19 +49,19 @@
out.println("<html>");
out.println("<head>");
- String title = rb.getString("requestparams.title");
+ String title = RB.getString("requestparams.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
// img stuff not req'd for source code html showing
- // all links relative
+ // all links relative
// XXX
// making these absolute till we work out the
- // addition of a PathInfo issue
-
+ // addition of a PathInfo issue
+
out.println("<a href=\"../reqparams.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
@@ -66,23 +72,23 @@
out.println("<h3>" + title + "</h3>");
String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
- out.println(rb.getString("requestparams.params-in-req") + "<br>");
+ out.println(RB.getString("requestparams.params-in-req") + "<br>");
if (firstName != null || lastName != null) {
- out.println(rb.getString("requestparams.firstname"));
+ out.println(RB.getString("requestparams.firstname"));
out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
- out.println(rb.getString("requestparams.lastname"));
+ out.println(RB.getString("requestparams.lastname"));
out.println(" = " + HTMLFilter.filter(lastName));
} else {
- out.println(rb.getString("requestparams.no-params"));
+ out.println(RB.getString("requestparams.no-params"));
}
out.println("<P>");
out.print("<form action=\"");
out.print("RequestParamExample\" ");
out.println("method=POST>");
- out.println(rb.getString("requestparams.firstname"));
+ out.println(RB.getString("requestparams.firstname"));
out.println("<input type=text size=20 name=firstname>");
out.println("<br>");
- out.println(rb.getString("requestparams.lastname"));
+ out.println(RB.getString("requestparams.lastname"));
out.println("<input type=text size=20 name=lastname>");
out.println("<br>");
out.println("<input type=submit>");
@@ -92,6 +98,7 @@
out.println("</html>");
}
+ @Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.class b/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.class
index 372e463..232cc36 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.java b/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.java
index 33f4f8f..cca91e0 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/SessionExample.java
@@ -15,10 +15,17 @@
* limitations under the License.
*/
-import java.io.*;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.ResourceBundle;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import util.HTMLFilter;
@@ -30,8 +37,11 @@
public class SessionExample extends HttpServlet {
- ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
-
+ private static final long serialVersionUID = 1L;
+
+ private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
+
+ @Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
@@ -42,18 +52,18 @@
out.println("<html>");
out.println("<head>");
- String title = rb.getString("sessions.title");
+ String title = RB.getString("sessions.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
// img stuff not req'd for source code html showing
- // relative links everywhere!
+ // relative links everywhere!
// XXX
// making these absolute till we work out the
- // addition of a PathInfo issue
-
+ // addition of a PathInfo issue
+
out.println("<a href=\"../sessions.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
@@ -64,11 +74,11 @@
out.println("<h3>" + title + "</h3>");
HttpSession session = request.getSession(true);
- out.println(rb.getString("sessions.id") + " " + session.getId());
+ out.println(RB.getString("sessions.id") + " " + session.getId());
out.println("<br>");
- out.println(rb.getString("sessions.created") + " ");
+ out.println(RB.getString("sessions.created") + " ");
out.println(new Date(session.getCreationTime()) + "<br>");
- out.println(rb.getString("sessions.lastaccessed") + " ");
+ out.println(RB.getString("sessions.lastaccessed") + " ");
out.println(new Date(session.getLastAccessedTime()));
String dataName = request.getParameter("dataname");
@@ -78,24 +88,24 @@
}
out.println("<P>");
- out.println(rb.getString("sessions.data") + "<br>");
- Enumeration names = session.getAttributeNames();
+ out.println(RB.getString("sessions.data") + "<br>");
+ Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
+ String name = names.nextElement();
String value = session.getAttribute(name).toString();
- out.println(HTMLFilter.filter(name) + " = "
+ out.println(HTMLFilter.filter(name) + " = "
+ HTMLFilter.filter(value) + "<br>");
}
out.println("<P>");
out.print("<form action=\"");
- out.print(response.encodeURL("SessionExample"));
+ out.print(response.encodeURL("SessionExample"));
out.print("\" ");
out.println("method=POST>");
- out.println(rb.getString("sessions.dataname"));
+ out.println(RB.getString("sessions.dataname"));
out.println("<input type=text size=20 name=dataname>");
out.println("<br>");
- out.println(rb.getString("sessions.datavalue"));
+ out.println(RB.getString("sessions.datavalue"));
out.println("<input type=text size=20 name=datavalue>");
out.println("<br>");
out.println("<input type=submit>");
@@ -103,13 +113,13 @@
out.println("<P>GET based form:<br>");
out.print("<form action=\"");
- out.print(response.encodeURL("SessionExample"));
+ out.print(response.encodeURL("SessionExample"));
out.print("\" ");
out.println("method=GET>");
- out.println(rb.getString("sessions.dataname"));
+ out.println(RB.getString("sessions.dataname"));
out.println("<input type=text size=20 name=dataname>");
out.println("<br>");
- out.println(rb.getString("sessions.datavalue"));
+ out.println(RB.getString("sessions.datavalue"));
out.println("<input type=text size=20 name=datavalue>");
out.println("<br>");
out.println("<input type=submit>");
@@ -118,11 +128,12 @@
out.print("<p><a href=\"");
out.print(HTMLFilter.filter(response.encodeURL("SessionExample?dataname=foo&datavalue=bar")));
out.println("\" >URL encoded </a>");
-
+
out.println("</body>");
out.println("</html>");
}
+ @Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0$1.class
new file mode 100644
index 0000000..021733f
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0.class
new file mode 100644
index 0000000..16fde39
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0.java b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0.java
new file mode 100644
index 0000000..ea4df76
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async0.java
@@ -0,0 +1,67 @@
+/*
+* 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 async;
+
+import java.io.IOException;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class Async0 extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Log log = LogFactory.getLog(Async0.class);
+
+ @Override
+ protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
+ if (Boolean.TRUE.equals(req.getAttribute("dispatch"))) {
+ log.info("Received dispatch, completing on the worker thread.");
+ log.info("After complete called started:"+req.isAsyncStarted());
+ resp.getWriter().write("Async dispatch worked:+"+System.currentTimeMillis()+"\n");
+ } else {
+ resp.setContentType("text/plain");
+ final AsyncContext actx = req.startAsync();
+ actx.setTimeout(Long.MAX_VALUE);
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ req.setAttribute("dispatch", Boolean.TRUE);
+ Thread.currentThread().setName("Async0-Thread");
+ log.info("Putting AsyncThread to sleep");
+ Thread.sleep(2*1000);
+ log.info("Dispatching");
+ actx.dispatch();
+ }catch (InterruptedException x) {
+ log.error("Async1",x);
+ }catch (IllegalStateException x) {
+ log.error("Async1",x);
+ }
+ }
+ };
+ Thread t = new Thread(run);
+ t.start();
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1$1.class
new file mode 100644
index 0000000..531cadb
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1.class
new file mode 100644
index 0000000..eb85ea0
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1.java b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1.java
new file mode 100644
index 0000000..9403a3a
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async1.java
@@ -0,0 +1,62 @@
+/*
+* 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 async;
+
+import java.io.IOException;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class Async1 extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Log log = LogFactory.getLog(Async1.class);
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final AsyncContext actx = req.startAsync();
+ actx.setTimeout(30*1000);
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ String path = "/jsp/async/async1.jsp";
+ Thread.currentThread().setName("Async1-Thread");
+ log.info("Putting AsyncThread to sleep");
+ Thread.sleep(2*1000);
+ log.info("Dispatching to "+path);
+ actx.dispatch(path);
+ }catch (InterruptedException x) {
+ log.error("Async1",x);
+ }catch (IllegalStateException x) {
+ log.error("Async1",x);
+ }
+ }
+ };
+ Thread t = new Thread(run);
+ t.start();
+ }
+
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2$1.class
new file mode 100644
index 0000000..10cfa14
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2.class
new file mode 100644
index 0000000..d79bb88
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2.java b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2.java
new file mode 100644
index 0000000..649afbc
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async2.java
@@ -0,0 +1,64 @@
+/*
+* 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 async;
+
+import java.io.IOException;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class Async2 extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Log log = LogFactory.getLog(Async2.class);
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final AsyncContext actx = req.startAsync();
+ actx.setTimeout(30*1000);
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.currentThread().setName("Async2-Thread");
+ log.info("Putting AsyncThread to sleep");
+ Thread.sleep(2*1000);
+ log.info("Writing data.");
+ actx.getResponse().getWriter().write("Output from background thread. Time:"+System.currentTimeMillis()+"\n");
+ actx.complete();
+ }catch (InterruptedException x) {
+ log.error("Async2",x);
+ }catch (IllegalStateException x) {
+ log.error("Async2",x);
+ }catch (IOException x) {
+ log.error("Async2",x);
+ }
+ }
+ };
+ Thread t = new Thread(run);
+ t.start();
+ }
+
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async3.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async3.class
new file mode 100644
index 0000000..bd90d90
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async3.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async3.java b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async3.java
new file mode 100644
index 0000000..39e0fe5
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Async3.java
@@ -0,0 +1,39 @@
+/*
+* 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 async;
+
+import java.io.IOException;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class Async3 extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final AsyncContext actx = req.startAsync();
+ actx.setTimeout(30*1000);
+ actx.dispatch("/jsp/async/async3.jsp");
+ }
+
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/AsyncStockServlet.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/AsyncStockServlet.class
new file mode 100644
index 0000000..117f084
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/AsyncStockServlet.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/AsyncStockServlet.java b/tomcat-cas/webapps/examples/WEB-INF/classes/async/AsyncStockServlet.java
new file mode 100644
index 0000000..ad4c43e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/AsyncStockServlet.java
@@ -0,0 +1,131 @@
+/*
+ * 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 async;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.AsyncEvent;
+import javax.servlet.AsyncListener;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import async.Stockticker.Stock;
+import async.Stockticker.TickListener;
+
+public class AsyncStockServlet extends HttpServlet implements TickListener, AsyncListener{
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String POLL = "POLL";
+ public static final String LONG_POLL = "LONG-POLL";
+ public static final String STREAM = "STREAM";
+
+ static ArrayList<Stock> ticks = new ArrayList<Stock>();
+ static ConcurrentLinkedQueue<AsyncContext> clients = new ConcurrentLinkedQueue<AsyncContext>();
+ static AtomicInteger clientcount = new AtomicInteger(0);
+ static Stockticker ticker = new Stockticker();
+
+ public AsyncStockServlet() {
+ System.out.println("AsyncStockServlet created");
+ }
+
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ if (req.isAsyncStarted()) {
+ req.getAsyncContext().complete();
+ } else if (req.isAsyncSupported()) {
+ AsyncContext actx = req.startAsync();
+ actx.addListener(this);
+ resp.setContentType("text/plain");
+ clients.add(actx);
+ if (clientcount.incrementAndGet()==1) {
+ ticker.addTickListener(this);
+ }
+ } else {
+ new Exception("Async Not Supported").printStackTrace();
+ resp.sendError(400,"Async is not supported.");
+ }
+ }
+
+
+ @Override
+ public void tick(Stock stock) {
+ ticks.add((Stock)stock.clone());
+ Iterator<AsyncContext> it = clients.iterator();
+ while (it.hasNext()) {
+ AsyncContext actx = it.next();
+ try {
+ writeStock(actx, stock);
+ } catch (Exception e) {
+ // Ignore. The async error handling will deal with this.
+ }
+ }
+ }
+
+ public void writeStock(AsyncContext actx, Stock stock) {
+ HttpServletResponse response = (HttpServletResponse)actx.getResponse();
+ try {
+ PrintWriter writer = response.getWriter();
+ writer.write("STOCK#");//make client parsing easier
+ writer.write(stock.getSymbol());
+ writer.write("#");
+ writer.write(stock.getValueAsString());
+ writer.write("#");
+ writer.write(stock.getLastChangeAsString());
+ writer.write("#");
+ writer.write(String.valueOf(stock.getCnt()));
+ writer.write("\n");
+ writer.flush();
+ response.flushBuffer();
+ }catch (IOException x) {
+ try {actx.complete();}catch (Exception ignore){/* Ignore */}
+ }
+ }
+
+ @Override
+ public void onComplete(AsyncEvent event) throws IOException {
+ if (clients.remove(event.getAsyncContext()) && clientcount.decrementAndGet()==0) {
+ ticker.removeTickListener(this);
+ }
+ }
+
+ @Override
+ public void onError(AsyncEvent event) throws IOException {
+ event.getAsyncContext().complete();
+ }
+
+ @Override
+ public void onTimeout(AsyncEvent event) throws IOException {
+ event.getAsyncContext().complete();
+ }
+
+
+ @Override
+ public void onStartAsync(AsyncEvent event) throws IOException {
+ // NOOP
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker$Stock.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker$Stock.class
new file mode 100644
index 0000000..bf771c3
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker$Stock.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker$TickListener.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker$TickListener.class
new file mode 100644
index 0000000..928b52f
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker$TickListener.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker.class b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker.class
new file mode 100644
index 0000000..7a99163
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker.java b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker.java
new file mode 100644
index 0000000..0bebf86
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/async/Stockticker.java
@@ -0,0 +1,188 @@
+/*
+ * 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 async;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class Stockticker implements Runnable {
+ public volatile boolean run = true;
+ protected AtomicInteger counter = new AtomicInteger(0);
+ ArrayList<TickListener> listeners = new ArrayList<TickListener>();
+ protected volatile Thread ticker = null;
+ protected volatile int ticknr = 0;
+
+ public synchronized void start() {
+ run = true;
+ ticker = new Thread(this);
+ ticker.setName("Ticker Thread");
+ ticker.start();
+ }
+
+ public synchronized void stop() {
+ run = false;
+ try {
+ ticker.join();
+ }catch (InterruptedException x) {
+ Thread.interrupted();
+ }
+
+ ticker = null;
+ }
+
+ public void addTickListener(TickListener listener) {
+ if (listeners.add(listener)) {
+ if (counter.incrementAndGet()==1) start();
+ }
+
+ }
+
+ public void removeTickListener(TickListener listener) {
+ if (listeners.remove(listener)) {
+ if (counter.decrementAndGet()==0) stop();
+ }
+ }
+
+ @Override
+ public void run() {
+ try {
+
+ Stock[] stocks = new Stock[] { new Stock("GOOG", 435.43),
+ new Stock("YHOO", 27.88), new Stock("ASF", 1015.55), };
+ Random r = new Random(System.currentTimeMillis());
+ while (run) {
+ for (int j = 0; j < 1; j++) {
+ int i = r.nextInt() % 3;
+ if (i < 0)
+ i = i * (-1);
+ Stock stock = stocks[i];
+ double change = r.nextDouble();
+ boolean plus = r.nextBoolean();
+ if (plus) {
+ stock.setValue(stock.getValue() + change);
+ } else {
+ stock.setValue(stock.getValue() - change);
+ }
+ stock.setCnt(++ticknr);
+ for (TickListener l : listeners) {
+ l.tick(stock);
+ }
+
+ }
+ Thread.sleep(850);
+ }
+ } catch (InterruptedException ix) {
+ // Ignore
+ } catch (Exception x) {
+ x.printStackTrace();
+ }
+ }
+
+
+ public static interface TickListener {
+ public void tick(Stock stock);
+ }
+
+ public static final class Stock implements Cloneable {
+ protected static DecimalFormat df = new DecimalFormat("0.00");
+ protected String symbol = "";
+ protected double value = 0.0d;
+ protected double lastchange = 0.0d;
+ protected int cnt = 0;
+
+ public Stock(String symbol, double initvalue) {
+ this.symbol = symbol;
+ this.value = initvalue;
+ }
+
+ public void setCnt(int c) {
+ this.cnt = c;
+ }
+
+ public int getCnt() {
+ return cnt;
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ double old = this.value;
+ this.value = value;
+ this.lastchange = value - old;
+ }
+
+ public String getValueAsString() {
+ return df.format(value);
+ }
+
+ public double getLastChange() {
+ return this.lastchange;
+ }
+
+ public void setLastChange(double lastchange) {
+ this.lastchange = lastchange;
+ }
+
+ public String getLastChangeAsString() {
+ return df.format(lastchange);
+ }
+
+ @Override
+ public int hashCode() {
+ return symbol.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof Stock) {
+ return this.symbol.equals(((Stock) other).symbol);
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder("STOCK#");
+ buf.append(getSymbol());
+ buf.append("#");
+ buf.append(getValueAsString());
+ buf.append("#");
+ buf.append(getLastChangeAsString());
+ buf.append("#");
+ buf.append(String.valueOf(getCnt()));
+ return buf.toString();
+
+ }
+
+ @Override
+ public Object clone() {
+ Stock s = new Stock(this.getSymbol(), this.getValue());
+ s.setLastChange(this.getLastChange());
+ s.setCnt(this.cnt);
+ return s;
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.class b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.class
index ab44434..30bed2f 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.java b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.java
index ea0867b..443cd60 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entries.java
@@ -1,72 +1,60 @@
/*
-* 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.
-*/
+ * 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 cal;
import java.util.Hashtable;
-import javax.servlet.http.*;
+
+import javax.servlet.http.HttpServletRequest;
public class Entries {
- private Hashtable entries;
- private static final String[] time = {"8am", "9am", "10am", "11am", "12pm",
- "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
- "7pm", "8pm" };
- public static final int rows = 12;
+ private Hashtable<String, Entry> entries;
+ private static final String[] time = { "8am", "9am", "10am", "11am",
+ "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", "7pm", "8pm" };
+ public static final int rows = 12;
- public Entries () {
- entries = new Hashtable (rows);
- for (int i=0; i < rows; i++) {
- entries.put (time[i], new Entry(time[i]));
- }
- }
-
- public int getRows () {
- return rows;
- }
-
- public Entry getEntry (int index) {
- return (Entry)this.entries.get(time[index]);
- }
-
- public int getIndex (String tm) {
- for (int i=0; i<rows; i++)
- if(tm.equals(time[i])) return i;
- return -1;
- }
-
- public void processRequest (HttpServletRequest request, String tm) {
- int index = getIndex (tm);
- if (index >= 0) {
- String descr = request.getParameter ("description");
- ((Entry)entries.get(time[index])).setDescription (descr);
+ public Entries() {
+ entries = new Hashtable<String, Entry>(rows);
+ for (int i = 0; i < rows; i++) {
+ entries.put(time[i], new Entry(time[i]));
+ }
}
- }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public Entry getEntry(int index) {
+ return this.entries.get(time[index]);
+ }
+
+ public int getIndex(String tm) {
+ for (int i = 0; i < rows; i++)
+ if (tm.equals(time[i]))
+ return i;
+ return -1;
+ }
+
+ public void processRequest(HttpServletRequest request, String tm) {
+ int index = getIndex(tm);
+ if (index >= 0) {
+ String descr = request.getParameter("description");
+ entries.get(time[index]).setDescription(descr);
+ }
+ }
}
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.class b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.class
index b4619a6..44c493d 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.java b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.java
index d4596d9..e6403b2 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/Entry.java
@@ -1,55 +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.
-*/
+ * 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 cal;
public class Entry {
- String hour;
- String description;
- String color;
+ String hour;
+ String description;
- public Entry (String hour) {
- this.hour = hour;
- this.description = "";
+ public Entry(String hour) {
+ this.hour = hour;
+ this.description = "";
- }
+ }
- public String getHour () {
- return this.hour;
- }
+ public String getHour() {
+ return this.hour;
+ }
- public String getColor () {
- if (description.equals("")) return "lightblue";
- else return "red";
- }
+ public String getColor() {
+ if (description.equals("")) {
+ return "lightblue";
+ }
+ return "red";
+ }
- public String getDescription () {
- if (description.equals("")) return "None";
- else return this.description;
- }
+ public String getDescription() {
+ if (description.equals("")) {
+ return "None";
+ }
+ return this.description;
+ }
- public void setDescription (String descr) {
- description = descr;
- }
-
+ public void setDescription(String descr) {
+ description = descr;
+ }
+
}
-
-
-
-
-
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.class b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.class
index dfd95e1..e1c6efa 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.java b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.java
index b2db6c0..dff319c 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/JspCalendar.java
@@ -17,138 +17,135 @@
package cal;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Date;
public class JspCalendar {
Calendar calendar = null;
- Date currentDate;
public JspCalendar() {
- calendar = Calendar.getInstance();
- Date trialTime = new Date();
- calendar.setTime(trialTime);
+ calendar = Calendar.getInstance();
+ Date trialTime = new Date();
+ calendar.setTime(trialTime);
}
public int getYear() {
- return calendar.get(Calendar.YEAR);
+ return calendar.get(Calendar.YEAR);
}
-
+
public String getMonth() {
- int m = getMonthInt();
- String[] months = new String [] { "January", "February", "March",
- "April", "May", "June",
- "July", "August", "September",
- "October", "November", "December" };
- if (m > 12)
- return "Unknown to Man";
-
- return months[m - 1];
+ int m = getMonthInt();
+ String[] months = new String [] { "January", "February", "March",
+ "April", "May", "June",
+ "July", "August", "September",
+ "October", "November", "December" };
+ if (m > 12)
+ return "Unknown to Man";
+
+ return months[m - 1];
}
public String getDay() {
- int x = getDayOfWeek();
- String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday"};
+ int x = getDayOfWeek();
+ String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"};
- if (x > 7)
- return "Unknown to Man";
+ if (x > 7)
+ return "Unknown to Man";
- return days[x - 1];
+ return days[x - 1];
}
-
+
public int getMonthInt() {
- return 1 + calendar.get(Calendar.MONTH);
+ return 1 + calendar.get(Calendar.MONTH);
}
public String getDate() {
- return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
+ return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getCurrentDate() {
Date dt = new Date ();
- calendar.setTime (dt);
- return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
+ calendar.setTime (dt);
+ return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getNextDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
- return getDate ();
+ return getDate ();
}
public String getPrevDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
- return getDate ();
+ return getDate ();
}
public String getTime() {
- return getHour() + ":" + getMinute() + ":" + getSecond();
+ return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth() {
- return calendar.get(Calendar.DAY_OF_MONTH);
+ return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear() {
- return calendar.get(Calendar.DAY_OF_YEAR);
+ return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear() {
- return calendar.get(Calendar.WEEK_OF_YEAR);
+ return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth() {
- return calendar.get(Calendar.WEEK_OF_MONTH);
+ return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek() {
- return calendar.get(Calendar.DAY_OF_WEEK);
+ return calendar.get(Calendar.DAY_OF_WEEK);
}
-
+
public int getHour() {
- return calendar.get(Calendar.HOUR_OF_DAY);
+ return calendar.get(Calendar.HOUR_OF_DAY);
}
-
+
public int getMinute() {
- return calendar.get(Calendar.MINUTE);
+ return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
- return calendar.get(Calendar.SECOND);
+ return calendar.get(Calendar.SECOND);
}
-
+
public int getEra() {
- return calendar.get(Calendar.ERA);
+ return calendar.get(Calendar.ERA);
}
public String getUSTimeZone() {
- String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
- "Mountain", "Central", "Eastern"};
-
- return zones[10 + getZoneOffset()];
+ String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
+ "Mountain", "Central", "Eastern"};
+
+ return zones[10 + getZoneOffset()];
}
public int getZoneOffset() {
- return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
+ return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
}
public int getDSTOffset() {
- return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
+ return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
}
-
+
public int getAMPM() {
- return calendar.get(Calendar.AM_PM);
+ return calendar.get(Calendar.AM_PM);
}
}
-
-
-
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.class b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.class
index 8afd547..fdd37a8 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.java b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.java
index f55327c..1c32e68 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/cal/TableBean.java
@@ -1,100 +1,101 @@
/*
-* 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.
-*/
+ * 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 cal;
-import javax.servlet.http.*;
import java.util.Hashtable;
+import javax.servlet.http.HttpServletRequest;
+
public class TableBean {
- Hashtable table;
- JspCalendar JspCal;
- Entries entries;
- String date;
- String name = null;
- String email = null;
- boolean processError = false;
+ Hashtable<String, Entries> table;
+ JspCalendar JspCal;
+ Entries entries;
+ String date;
+ String name = null;
+ String email = null;
+ boolean processError = false;
- public TableBean () {
- this.table = new Hashtable (10);
- this.JspCal = new JspCalendar ();
- this.date = JspCal.getCurrentDate ();
- }
-
- public void setName (String nm) {
- this.name = nm;
- }
-
- public String getName () {
- return this.name;
- }
-
- public void setEmail (String mail) {
- this.email = mail;
- }
-
- public String getEmail () {
- return this.email;
- }
-
- public String getDate () {
- return this.date;
- }
-
- public Entries getEntries () {
- return this.entries;
- }
-
- public void processRequest (HttpServletRequest request) {
-
- // Get the name and e-mail.
- this.processError = false;
- if (name == null || name.equals("")) setName(request.getParameter ("name"));
- if (email == null || email.equals("")) setEmail(request.getParameter ("email"));
- if (name == null || email == null ||
- name.equals("") || email.equals("")) {
- this.processError = true;
- return;
+ public TableBean() {
+ this.table = new Hashtable<String, Entries>(10);
+ this.JspCal = new JspCalendar();
+ this.date = JspCal.getCurrentDate();
}
- // Get the date.
- String dateR = request.getParameter ("date");
- if (dateR == null) date = JspCal.getCurrentDate ();
- else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate ();
- else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate ();
-
- entries = (Entries) table.get (date);
- if (entries == null) {
- entries = new Entries ();
- table.put (date, entries);
+ public void setName(String nm) {
+ this.name = nm;
}
- // If time is provided add the event.
- String time = request.getParameter("time");
- if (time != null) entries.processRequest (request, time);
- }
+ public String getName() {
+ return this.name;
+ }
- public boolean getProcessError () {
- return this.processError;
- }
+ public void setEmail(String mail) {
+ this.email = mail;
+ }
+
+ public String getEmail() {
+ return this.email;
+ }
+
+ public String getDate() {
+ return this.date;
+ }
+
+ public Entries getEntries() {
+ return this.entries;
+ }
+
+ public void processRequest(HttpServletRequest request) {
+
+ // Get the name and e-mail.
+ this.processError = false;
+ if (name == null || name.equals(""))
+ setName(request.getParameter("name"));
+ if (email == null || email.equals(""))
+ setEmail(request.getParameter("email"));
+ if (name == null || email == null || name.equals("")
+ || email.equals("")) {
+ this.processError = true;
+ return;
+ }
+
+ // Get the date.
+ String dateR = request.getParameter("date");
+ if (dateR == null)
+ date = JspCal.getCurrentDate();
+ else if (dateR.equalsIgnoreCase("next"))
+ date = JspCal.getNextDate();
+ else if (dateR.equalsIgnoreCase("prev"))
+ date = JspCal.getPrevDate();
+
+ entries = table.get(date);
+ if (entries == null) {
+ entries = new Entries();
+ table.put(date, entries);
+ }
+
+ // If time is provided add the event.
+ String time = request.getParameter("time");
+ if (time != null)
+ entries.processRequest(request, time);
+ }
+
+ public boolean getProcessError() {
+ return this.processError;
+ }
}
-
-
-
-
-
-
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet$MessageSender.class b/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet$MessageSender.class
index 6712d68..c4be561 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet$MessageSender.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet$MessageSender.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.class b/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.class
index 752adba..ea047bd 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.java b/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
index 11d3757..d92092d 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/chat/ChatServlet.java
@@ -5,9 +5,9 @@
* 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.
@@ -24,14 +24,14 @@
import java.io.PrintWriter;
import java.util.ArrayList;
-import org.apache.catalina.CometEvent;
-import org.apache.catalina.CometProcessor;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.catalina.comet.CometEvent;
+import org.apache.catalina.comet.CometProcessor;
+
/**
* Helper class to implement Comet functionality.
@@ -39,20 +39,24 @@
public class ChatServlet
extends HttpServlet implements CometProcessor {
+ private static final long serialVersionUID = 1L;
+
private static final String CHARSET = "UTF-8";
- protected ArrayList<HttpServletResponse> connections =
+ protected ArrayList<HttpServletResponse> connections =
new ArrayList<HttpServletResponse>();
- protected MessageSender messageSender = null;
-
+ protected transient MessageSender messageSender = null;
+
+ @Override
public void init() throws ServletException {
messageSender = new MessageSender();
- Thread messageSenderThread =
+ Thread messageSenderThread =
new Thread(messageSender, "MessageSender[" + getServletContext().getContextPath() + "]");
messageSenderThread.setDaemon(true);
messageSenderThread.start();
}
+ @Override
public void destroy() {
connections.clear();
messageSender.stop();
@@ -61,11 +65,12 @@
/**
* Process the given Comet event.
- *
+ *
* @param event The Comet event that will be processed
* @throws IOException
* @throws ServletException
*/
+ @Override
public void event(CometEvent event)
throws IOException, ServletException {
@@ -73,7 +78,7 @@
// mixing Comet stuff with regular connection processing
HttpServletRequest request = event.getHttpServletRequest();
HttpServletResponse response = event.getHttpServletResponse();
-
+
if (event.getEventType() == CometEvent.EventType.BEGIN) {
String action = request.getParameter("action");
if (action != null) {
@@ -83,22 +88,20 @@
response.sendRedirect("index.jsp");
event.close();
return;
- } else {
- String nickname = (String) request.getSession(true).getAttribute("nickname");
- String message = request.getParameter("message");
- messageSender.send(nickname, message);
- response.sendRedirect("post.jsp");
- event.close();
- return;
}
- } else {
- if (request.getSession(true).getAttribute("nickname") == null) {
- // Redirect to "login"
- log("Redirect to login for session: " + request.getSession(true).getId());
- response.sendRedirect("login.jsp");
- event.close();
- return;
- }
+ String nickname = (String) request.getSession(true).getAttribute("nickname");
+ String message = request.getParameter("message");
+ messageSender.send(nickname, message);
+ response.sendRedirect("post.jsp");
+ event.close();
+ return;
+ }
+ if (request.getSession(true).getAttribute("nickname") == null) {
+ // Redirect to "login"
+ log("Redirect to login for session: " + request.getSession(true).getId());
+ response.sendRedirect("login.jsp");
+ event.close();
+ return;
}
begin(event, request, response);
} else if (event.getEventType() == CometEvent.EventType.ERROR) {
@@ -110,8 +113,9 @@
}
}
- protected void begin(CometEvent event, HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ protected void begin(@SuppressWarnings("unused") CometEvent event,
+ HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
log("Begin for session: " + request.getSession(true).getId());
response.setContentType("text/html; charset=" + CHARSET);
@@ -128,38 +132,38 @@
messageSender.send("Tomcat", request.getSession(true).getAttribute("nickname") + " joined the chat.");
}
-
+
protected void end(CometEvent event, HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ throws IOException {
log("End for session: " + request.getSession(true).getId());
synchronized(connections) {
connections.remove(response);
}
-
+
PrintWriter writer = response.getWriter();
writer.println("</body></html>");
-
+
event.close();
}
-
+
protected void error(CometEvent event, HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ throws IOException {
log("Error for session: " + request.getSession(true).getId());
synchronized(connections) {
connections.remove(response);
}
event.close();
}
-
+
protected void read(CometEvent event, HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ throws IOException {
InputStream is = request.getInputStream();
byte[] buf = new byte[512];
while (is.available() > 0) {
log("Available: " + is.available());
int n = is.read(buf);
if (n > 0) {
- log("Read " + n + " bytes: " + new String(buf, 0, n)
+ log("Read " + n + " bytes: " + new String(buf, 0, n)
+ " for session: " + request.getSession(true).getId());
} else if (n < 0) {
log("End of file: " + n);
@@ -169,6 +173,7 @@
}
}
+ @Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// Compatibility method: equivalent method using the regular connection model
@@ -180,7 +185,7 @@
writer.println("Configure a connector that supports Comet and try again.");
writer.println("</body></html>");
}
-
+
/**
* Poller class.
@@ -189,10 +194,11 @@
protected boolean running = true;
protected ArrayList<String> messages = new ArrayList<String>();
-
+
public MessageSender() {
+ // Default contructor
}
-
+
public void stop() {
running = false;
synchronized (messages) {
@@ -200,14 +206,6 @@
}
}
- /**
- * Add specified socket and associated pool to the poller. The socket will
- * be added to a temporary array, and polled first after a maximum amount
- * of time equal to pollTime (in most cases, latency will be much lower,
- * however).
- *
- * @param socket to add to the poller
- */
public void send(String user, String message) {
synchronized (messages) {
messages.add("[" + user + "]: " + message);
@@ -219,6 +217,7 @@
* The background thread that listens for incoming TCP/IP connections and
* hands them off to an appropriate processor.
*/
+ @Override
public void run() {
// Loop until we receive a shutdown command
@@ -226,7 +225,7 @@
String[] pendingMessages;
synchronized (messages) {
try {
- if (messages.size() == 0) {
+ if (running && messages.size() == 0) {
messages.wait();
}
} catch (InterruptedException e) {
@@ -261,7 +260,7 @@
* in HTML.
*
* @param message The message string to be filtered
- * @author Copied from org.apache.catalina.util.RequestUtil#filter(String)
+ * @author Copied from org.apache.catalina.util.RequestUtil#filter(String)
*/
protected static String filter(String message) {
if (message == null)
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.class b/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.class
index 87011a7..e5fc31c 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java b/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java
index 70623e2..c25448b 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java
@@ -22,10 +22,10 @@
String b[] = new String[] { "1", "2", "3", "4" };
public String[] getFruit() {
- return b;
+ return b;
}
public void setFruit(String [] b) {
- this.b = b;
+ this.b = b;
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.class b/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.class
index 408dc45..bed4bf3 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java b/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java
index 5748217..6e2d741 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java
@@ -16,8 +16,6 @@
*/
package colors;
-import javax.servlet.http.*;
-
public class ColorGameBean {
private String background = "yellow";
@@ -26,90 +24,90 @@
private String color2 = background;
private String hint = "no";
private int attempts = 0;
- private int intval = 0;
+ private int intval = 0;
private boolean tookHints = false;
- public void processRequest(HttpServletRequest request) {
+ public void processRequest() {
- // background = "yellow";
- // foreground = "red";
+ // background = "yellow";
+ // foreground = "red";
- if (! color1.equals(foreground)) {
- if (color1.equalsIgnoreCase("black") ||
- color1.equalsIgnoreCase("cyan")) {
- background = color1;
- }
- }
+ if (! color1.equals(foreground)) {
+ if (color1.equalsIgnoreCase("black") ||
+ color1.equalsIgnoreCase("cyan")) {
+ background = color1;
+ }
+ }
- if (! color2.equals(background)) {
- if (color2.equalsIgnoreCase("black") ||
- color2.equalsIgnoreCase("cyan")) {
- foreground = color2;
- }
- }
+ if (! color2.equals(background)) {
+ if (color2.equalsIgnoreCase("black") ||
+ color2.equalsIgnoreCase("cyan")) {
+ foreground = color2;
+ }
+ }
- attempts++;
+ attempts++;
}
public void setColor2(String x) {
- color2 = x;
+ color2 = x;
}
public void setColor1(String x) {
- color1 = x;
+ color1 = x;
}
public void setAction(String x) {
- if (!tookHints)
- tookHints = x.equalsIgnoreCase("Hint");
- hint = x;
+ if (!tookHints)
+ tookHints = x.equalsIgnoreCase("Hint");
+ hint = x;
}
public String getColor2() {
- return background;
+ return background;
}
public String getColor1() {
- return foreground;
+ return foreground;
}
public int getAttempts() {
- return attempts;
+ return attempts;
}
public boolean getHint() {
- return hint.equalsIgnoreCase("Hint");
+ return hint.equalsIgnoreCase("Hint");
}
public boolean getSuccess() {
- if (background.equalsIgnoreCase("black") ||
- background.equalsIgnoreCase("cyan")) {
-
- if (foreground.equalsIgnoreCase("black") ||
- foreground.equalsIgnoreCase("cyan"))
- return true;
- else
- return false;
- }
+ if (background.equalsIgnoreCase("black") ||
+ background.equalsIgnoreCase("cyan")) {
- return false;
+ if (foreground.equalsIgnoreCase("black") ||
+ foreground.equalsIgnoreCase("cyan")) {
+ return true;
+ }
+ return false;
+ }
+
+ return false;
}
public boolean getHintTaken() {
- return tookHints;
+ return tookHints;
}
public void reset() {
- foreground = "red";
- background = "yellow";
+ foreground = "red";
+ background = "yellow";
}
public void setIntval(int value) {
- intval = value;
- }
+ intval = value;
+ }
public int getIntval() {
- return intval;
- }
+ return intval;
+ }
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.class b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.class
index 619a1a2..f81aba7 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java
index fc298e2..350393a 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java
@@ -14,11 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package compressionFilters;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.List;
+import java.util.StringTokenizer;
+
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -28,7 +31,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
/**
* Implementation of <code>javax.servlet.Filter</code> used to compress
* the ServletResponse if it is bigger than a threshold.
@@ -36,7 +38,7 @@
* @author Amy Roh
* @author Dmitri Valdin
*/
-public class CompressionFilter implements Filter{
+public class CompressionFilter implements Filter {
/**
* The filter configuration object we are associated with. If this value
@@ -45,18 +47,32 @@
private FilterConfig config = null;
/**
- * Minimal reasonable threshold
+ * Minimal reasonable threshold.
*/
private int minThreshold = 128;
-
/**
- * The threshold number to compress
+ * The threshold number to compress.
*/
- protected int compressionThreshold;
+ protected int compressionThreshold = 0;
/**
- * Debug level for this filter
+ * Minimal reasonable buffer.
+ */
+ private int minBuffer = 8192; // 8KB is what tomcat would use by default anyway
+
+ /**
+ * The compression buffer size to avoid chunking.
+ */
+ protected int compressionBuffer = 0;
+
+ /**
+ * The mime types to compress.
+ */
+ protected String[] compressionMimeTypes = {"text/html", "text/xml", "text/plain"};
+
+ /**
+ * Debug level for this filter.
*/
private int debug = 0;
@@ -65,7 +81,7 @@
*
* @param filterConfig The filter configuration object
*/
-
+ @Override
public void init(FilterConfig filterConfig) {
config = filterConfig;
@@ -73,9 +89,8 @@
String value = filterConfig.getInitParameter("debug");
if (value!=null) {
debug = Integer.parseInt(value);
- } else {
- debug = 0;
}
+
String str = filterConfig.getInitParameter("compressionThreshold");
if (str!=null) {
compressionThreshold = Integer.parseInt(str);
@@ -86,12 +101,43 @@
}
compressionThreshold = minThreshold;
}
- } else {
- compressionThreshold = 0;
}
- } else {
- compressionThreshold = 0;
+ str = filterConfig.getInitParameter("compressionBuffer");
+ if (str!=null) {
+ compressionBuffer = Integer.parseInt(str);
+ if (compressionBuffer < minBuffer) {
+ if (debug > 0) {
+ System.out.println("compressionBuffer should be >= " + minBuffer);
+ System.out.println("compressionBuffer set to " + minBuffer);
+ }
+ compressionBuffer = minBuffer;
+ }
+ }
+
+ str = filterConfig.getInitParameter("compressionMimeTypes");
+ if (str!=null) {
+ List<String> values = new ArrayList<String>();
+ StringTokenizer st = new StringTokenizer(str, ",");
+
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken().trim();
+ if (token.length() > 0) {
+ values.add(token);
+ }
+ }
+
+ if (values.size() > 0) {
+ compressionMimeTypes = values.toArray(
+ new String[values.size()]);
+ } else {
+ compressionMimeTypes = null;
+ }
+
+ if (debug > 0) {
+ System.out.println("compressionMimeTypes set to " + compressionMimeTypes);
+ }
+ }
}
}
@@ -99,6 +145,7 @@
/**
* Take this filter out of service.
*/
+ @Override
public void destroy() {
this.config = null;
@@ -121,7 +168,7 @@
* It then invokes the next entity in the chain using the FilterChain object
* (<code>chain.doFilter()</code>), <br>
**/
-
+ @Override
public void doFilter ( ServletRequest request, ServletResponse response,
FilterChain chain ) throws IOException, ServletException {
@@ -131,7 +178,7 @@
if (compressionThreshold == 0) {
if (debug > 0) {
- System.out.println("doFilter gets called, but compressionTreshold is set to 0 - no compression");
+ System.out.println("doFilter got called, but compressionThreshold is set to 0 - no compression");
}
chain.doFilter(request, response);
return;
@@ -144,7 +191,7 @@
}
// Are we allowed to compress ?
- String s = (String) ((HttpServletRequest)request).getParameter("gzip");
+ String s = ((HttpServletRequest)request).getParameter("gzip");
if ("false".equals(s)) {
if (debug > 0) {
System.out.println("got parameter gzip=false --> don't compress, just chain filter");
@@ -153,10 +200,10 @@
return;
}
- Enumeration e =
+ Enumeration<String> e =
((HttpServletRequest)request).getHeaders("Accept-Encoding");
while (e.hasMoreElements()) {
- String name = (String)e.nextElement();
+ String name = e.nextElement();
if (name.indexOf("gzip") != -1) {
if (debug > 0) {
System.out.println("supports compression");
@@ -164,24 +211,20 @@
supportCompression = true;
} else {
if (debug > 0) {
- System.out.println("no support for compresion");
+ System.out.println("no support for compression");
}
}
}
}
- if (!supportCompression) {
- if (debug > 0) {
- System.out.println("doFilter gets called wo compression");
- }
- chain.doFilter(request, response);
- return;
- } else {
+ if (supportCompression) {
if (response instanceof HttpServletResponse) {
CompressionServletResponseWrapper wrappedResponse =
new CompressionServletResponseWrapper((HttpServletResponse)response);
wrappedResponse.setDebugLevel(debug);
wrappedResponse.setCompressionThreshold(compressionThreshold);
+ wrappedResponse.setCompressionBuffer(compressionBuffer);
+ wrappedResponse.setCompressionMimeTypes(compressionMimeTypes);
if (debug > 0) {
System.out.println("doFilter gets called with compression");
}
@@ -192,6 +235,12 @@
}
return;
}
+ } else {
+ if (debug > 0) {
+ System.out.println("doFilter gets called w/o compression");
+ }
+ chain.doFilter(request, response);
+ return;
}
}
@@ -206,12 +255,12 @@
}
/**
- * Return filter config
* Required by Weblogic 6.1
+ *
+ * @return the FilterConfig that was used to initialise this filter.
*/
public FilterConfig getFilterConfig() {
return config;
}
-
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.class b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.class
index a48332d..ce695cb 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java
index 9f6090a..700cd1f 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java
@@ -14,13 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package compressionFilters;
import java.io.IOException;
import java.util.Enumeration;
-import javax.servlet.*;
-import javax.servlet.http.*;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
/**
* Very Simple test servlet to test compression filter
@@ -28,15 +31,18 @@
*/
public class CompressionFilterTestServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletOutputStream out = response.getOutputStream();
response.setContentType("text/plain");
- Enumeration e = ((HttpServletRequest)request).getHeaders("Accept-Encoding");
+ Enumeration<String> e = request.getHeaders("Accept-Encoding");
while (e.hasMoreElements()) {
- String name = (String)e.nextElement();
+ String name = e.nextElement();
out.println(name);
if (name.indexOf("gzip") != -1) {
out.println("gzip supported -- able to compress");
@@ -48,6 +54,11 @@
out.println("Compression Filter Test Servlet");
+ out.println("Minimum content length for compression is 128 bytes");
+ out.println("********** 32 bytes **********");
+ out.println("********** 32 bytes **********");
+ out.println("********** 32 bytes **********");
+ out.println("********** 32 bytes **********");
out.close();
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.class b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.class
index a52f332..3d05f19 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java
index 120b82a..a79027a 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java
@@ -19,9 +19,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletOutputStream;
/**
* Implementation of <b>ServletOutputStream</b> that works with
@@ -30,25 +29,24 @@
* @author Amy Roh
* @author Dmitri Valdin
*/
-public class CompressionResponseStream
- extends ServletOutputStream {
-
+public class CompressionResponseStream extends ServletOutputStream {
// ----------------------------------------------------------- Constructors
-
/**
* Construct a servlet output stream associated with the specified Response.
*
- * @param response The associated response
+ * @param responseWrapper The associated response wrapper
+ * @param originalOutput the output stream
*/
- public CompressionResponseStream(HttpServletResponse response) throws IOException{
+ public CompressionResponseStream(
+ CompressionServletResponseWrapper responseWrapper,
+ ServletOutputStream originalOutput) {
super();
closed = false;
- this.response = response;
- this.output = response.getOutputStream();
-
+ this.response = responseWrapper;
+ this.output = originalOutput;
}
@@ -62,6 +60,16 @@
protected int compressionThreshold = 0;
/**
+ * The compression buffer size to avoid chunking
+ */
+ protected int compressionBuffer = 0;
+
+ /**
+ * The mime types to compress
+ */
+ protected String[] compressionMimeTypes = {"text/html", "text/xml", "text/plain"};
+
+ /**
* Debug level
*/
private int debug = 0;
@@ -95,10 +103,10 @@
/**
* The response with which this servlet output stream is associated.
*/
- protected HttpServletResponse response = null;
+ protected CompressionServletResponseWrapper response = null;
/**
- * The underlying servket output stream to which we should write data.
+ * The underlying servlet output stream to which we should write data.
*/
protected ServletOutputStream output = null;
@@ -116,11 +124,31 @@
/**
* Set the compressionThreshold number and create buffer for this size
*/
- protected void setBuffer(int threshold) {
- compressionThreshold = threshold;
- buffer = new byte[compressionThreshold];
+ protected void setCompressionThreshold(int compressionThreshold) {
+ this.compressionThreshold = compressionThreshold;
+ buffer = new byte[this.compressionThreshold];
if (debug > 1) {
- System.out.println("buffer is set to "+compressionThreshold);
+ System.out.println("compressionThreshold is set to "+ this.compressionThreshold);
+ }
+ }
+
+ /**
+ * The compression buffer size to avoid chunking
+ */
+ protected void setCompressionBuffer(int compressionBuffer) {
+ this.compressionBuffer = compressionBuffer;
+ if (debug > 1) {
+ System.out.println("compressionBuffer is set to "+ this.compressionBuffer);
+ }
+ }
+
+ /**
+ * Set supported mime types
+ */
+ public void setCompressionMimeTypes(String[] compressionMimeTypes) {
+ this.compressionMimeTypes = compressionMimeTypes;
+ if (debug > 1) {
+ System.out.println("compressionMimeTypes is set to " + this.compressionMimeTypes);
}
}
@@ -128,6 +156,7 @@
* Close this output stream, causing any buffered data to be flushed and
* any further output data to throw an IOException.
*/
+ @Override
public void close() throws IOException {
if (debug > 1) {
@@ -162,6 +191,7 @@
* Flush any buffered data for this output stream, which also causes the
* response to be committed.
*/
+ @Override
public void flush() throws IOException {
if (debug > 1) {
@@ -199,6 +229,7 @@
*
* @exception IOException if an input/output error occurs
*/
+ @Override
public void write(int b) throws IOException {
if (debug > 1) {
@@ -224,6 +255,7 @@
*
* @exception IOException if an input/output error occurs
*/
+ @Override
public void write(byte b[]) throws IOException {
write(b, 0, b.length);
@@ -241,6 +273,7 @@
*
* @exception IOException if an input/output error occurs
*/
+ @Override
public void write(byte b[], int off, int len) throws IOException {
if (debug > 1) {
@@ -293,12 +326,53 @@
if (debug > 1) {
System.out.println("new GZIPOutputStream");
}
+
+ boolean alreadyCompressed = false;
+ String contentEncoding = response.getHeader("Content-Encoding");
+ if (contentEncoding != null) {
+ if (contentEncoding.contains("gzip")) {
+ alreadyCompressed = true;
+ if (debug > 0) {
+ System.out.println("content is already compressed");
+ }
+ } else {
+ if (debug > 0) {
+ System.out.println("content is not compressed yet");
+ }
+ }
+ }
+
+ boolean compressibleMimeType = false;
+ // Check for compatible MIME-TYPE
+ if (compressionMimeTypes != null) {
+ if (startsWithStringArray(compressionMimeTypes, response.getContentType())) {
+ compressibleMimeType = true;
+ if (debug > 0) {
+ System.out.println("mime type " + response.getContentType() + " is compressible");
+ }
+ } else {
+ if (debug > 0) {
+ System.out.println("mime type " + response.getContentType() + " is not compressible");
+ }
+ }
+ }
+
if (response.isCommitted()) {
if (debug > 1)
System.out.print("Response already committed. Using original output stream");
gzipstream = output;
+ } else if (alreadyCompressed) {
+ if (debug > 1)
+ System.out.print("Response already compressed. Using original output stream");
+ gzipstream = output;
+ } else if (!compressibleMimeType) {
+ if (debug > 1)
+ System.out.print("Response mime type is not compressible. Using original output stream");
+ gzipstream = output;
} else {
response.addHeader("Content-Encoding", "gzip");
+ response.setContentLength(-1); // don't use any preset content-length as it will be wrong after gzipping
+ response.setBufferSize(compressionBuffer);
gzipstream = new GZIPOutputStream(output);
}
}
@@ -319,4 +393,20 @@
}
+ /**
+ * Checks if any entry in the string array starts with the specified value
+ *
+ * @param sArray the StringArray
+ * @param value string
+ */
+ private boolean startsWithStringArray(String sArray[], String value) {
+ if (value == null)
+ return false;
+ for (int i = 0; i < sArray.length; i++) {
+ if (value.startsWith(sArray[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.class b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.class
index 838e08c..1198e42 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
index e2cd66b..1e28d44 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
@@ -19,6 +19,9 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
@@ -30,7 +33,8 @@
* @author Amy Roh
* @author Dmitri Valdin
*/
-public class CompressionServletResponseWrapper extends HttpServletResponseWrapper {
+public class CompressionServletResponseWrapper
+ extends HttpServletResponseWrapper {
// ----------------------------------------------------- Constructor
@@ -38,7 +42,6 @@
* Calls the parent constructor which creates a ServletResponse adaptor
* wrapping the given response object.
*/
-
public CompressionServletResponseWrapper(HttpServletResponse response) {
super(response);
origResponse = response;
@@ -80,43 +83,61 @@
/**
* The threshold number to compress
*/
- protected int threshold = 0;
+ protected int compressionThreshold = 0;
+
+ /**
+ * The compression buffer size
+ */
+ protected int compressionBuffer = 8192; // 8KB default
+
+ /**
+ * The mime types to compress
+ */
+ protected String[] compressionMimeTypes = {"text/html", "text/xml", "text/plain"};
/**
* Debug level
*/
- private int debug = 0;
+ protected int debug = 0;
/**
- * Content type
+ * keeps a copy of all headers set
*/
- protected String contentType = null;
+ private Map<String,String> headerCopies = new HashMap<String,String>();
+
// --------------------------------------------------------- Public Methods
/**
- * Set content type
- */
- public void setContentType(String contentType) {
- if (debug > 1) {
- System.out.println("setContentType to "+contentType);
- }
- this.contentType = contentType;
- origResponse.setContentType(contentType);
- }
-
-
- /**
* Set threshold number
*/
public void setCompressionThreshold(int threshold) {
if (debug > 1) {
System.out.println("setCompressionThreshold to " + threshold);
}
- this.threshold = threshold;
+ this.compressionThreshold = threshold;
}
+ /**
+ * Set compression buffer
+ */
+ public void setCompressionBuffer(int buffer) {
+ if (debug > 1) {
+ System.out.println("setCompressionBuffer to " + buffer);
+ }
+ this.compressionBuffer = buffer;
+ }
+
+ /**
+ * Set compressible mime types
+ */
+ public void setCompressionMimeTypes(String[] mimeTypes) {
+ if (debug > 1) {
+ System.out.println("setCompressionMimeTypes to " + mimeTypes);
+ }
+ this.compressionMimeTypes = mimeTypes;
+ }
/**
* Set debug level
@@ -137,12 +158,14 @@
System.out.println("createOutputStream gets called");
}
- CompressionResponseStream stream = new CompressionResponseStream(origResponse);
+ CompressionResponseStream stream = new CompressionResponseStream(
+ this, origResponse.getOutputStream());
stream.setDebugLevel(debug);
- stream.setBuffer(threshold);
+ stream.setCompressionThreshold(compressionThreshold);
+ stream.setCompressionBuffer(compressionBuffer);
+ stream.setCompressionMimeTypes(compressionMimeTypes);
return stream;
-
}
@@ -158,6 +181,7 @@
stream.close();
}
} catch (IOException e) {
+ // Ignore
}
}
@@ -170,9 +194,10 @@
*
* @exception IOException if an input/output error occurs
*/
+ @Override
public void flushBuffer() throws IOException {
if (debug > 1) {
- System.out.println("flush buffer @ CompressionServletResponseWrapper");
+ System.out.println("flush buffer @ GZipServletResponseWrapper");
}
((CompressionResponseStream)stream).flush();
@@ -185,6 +210,7 @@
* already been called for this response
* @exception IOException if an input/output error occurs
*/
+ @Override
public ServletOutputStream getOutputStream() throws IOException {
if (writer != null)
@@ -207,6 +233,7 @@
* already been called for this response
* @exception IOException if an input/output error occurs
*/
+ @Override
public PrintWriter getWriter() throws IOException {
if (writer != null)
@@ -219,7 +246,6 @@
if (debug > 1) {
System.out.println("stream is set to "+stream+" in getWriter");
}
- //String charset = getCharsetFromContentType(contentType);
String charEnc = origResponse.getCharacterEncoding();
if (debug > 1) {
System.out.println("character encoding is " + charEnc);
@@ -231,13 +257,29 @@
} else {
writer = new PrintWriter(stream);
}
-
+
return (writer);
+ }
+ @Override
+ public String getHeader(String name) {
+ return headerCopies.get(name);
+ }
+
+ @Override
+ public void addHeader(String name, String value) {
+ if (headerCopies.containsKey(name)) {
+ String existingValue = headerCopies.get(name);
+ if ((existingValue != null) && (existingValue.length() > 0)) headerCopies.put(name, existingValue + "," + value);
+ else headerCopies.put(name, value);
+ } else headerCopies.put(name, value);
+ super.addHeader(name, value);
}
- public void setContentLength(int length) {
+ @Override
+ public void setHeader(String name, String value) {
+ headerCopies.put(name, value);
+ super.setHeader(name, value);
}
-
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.class b/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.class
index 7ae66d3..56cd2b5 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.java b/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.java
index 22e1f86..9c90bbd 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/dates/JspCalendar.java
@@ -16,137 +16,138 @@
*/
package dates;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Date;
public class JspCalendar {
Calendar calendar = null;
public JspCalendar() {
- calendar = Calendar.getInstance();
- Date trialTime = new Date();
- calendar.setTime(trialTime);
+ calendar = Calendar.getInstance();
+ Date trialTime = new Date();
+ calendar.setTime(trialTime);
}
public int getYear() {
- return calendar.get(Calendar.YEAR);
+ return calendar.get(Calendar.YEAR);
}
-
+
public String getMonth() {
- int m = getMonthInt();
- String[] months = new String [] { "January", "February", "March",
- "April", "May", "June",
- "July", "August", "September",
- "October", "November", "December" };
- if (m > 12)
- return "Unknown to Man";
-
- return months[m - 1];
+ int m = getMonthInt();
+ String[] months = new String [] { "January", "February", "March",
+ "April", "May", "June",
+ "July", "August", "September",
+ "October", "November", "December" };
+ if (m > 12)
+ return "Unknown to Man";
+
+ return months[m - 1];
}
public String getDay() {
- int x = getDayOfWeek();
- String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday"};
+ int x = getDayOfWeek();
+ String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"};
- if (x > 7)
- return "Unknown to Man";
+ if (x > 7)
+ return "Unknown to Man";
- return days[x - 1];
+ return days[x - 1];
}
-
+
public int getMonthInt() {
- return 1 + calendar.get(Calendar.MONTH);
+ return 1 + calendar.get(Calendar.MONTH);
}
public String getDate() {
- return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
+ return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getTime() {
- return getHour() + ":" + getMinute() + ":" + getSecond();
+ return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth() {
- return calendar.get(Calendar.DAY_OF_MONTH);
+ return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear() {
- return calendar.get(Calendar.DAY_OF_YEAR);
+ return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear() {
- return calendar.get(Calendar.WEEK_OF_YEAR);
+ return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth() {
- return calendar.get(Calendar.WEEK_OF_MONTH);
+ return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek() {
- return calendar.get(Calendar.DAY_OF_WEEK);
+ return calendar.get(Calendar.DAY_OF_WEEK);
}
-
+
public int getHour() {
- return calendar.get(Calendar.HOUR_OF_DAY);
+ return calendar.get(Calendar.HOUR_OF_DAY);
}
-
+
public int getMinute() {
- return calendar.get(Calendar.MINUTE);
+ return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
- return calendar.get(Calendar.SECOND);
+ return calendar.get(Calendar.SECOND);
}
public static void main(String args[]) {
- JspCalendar db = new JspCalendar();
- p("date: " + db.getDayOfMonth());
- p("year: " + db.getYear());
- p("month: " + db.getMonth());
- p("time: " + db.getTime());
- p("date: " + db.getDate());
- p("Day: " + db.getDay());
- p("DayOfYear: " + db.getDayOfYear());
- p("WeekOfYear: " + db.getWeekOfYear());
- p("era: " + db.getEra());
- p("ampm: " + db.getAMPM());
- p("DST: " + db.getDSTOffset());
- p("ZONE Offset: " + db.getZoneOffset());
- p("TIMEZONE: " + db.getUSTimeZone());
+ JspCalendar db = new JspCalendar();
+ p("date: " + db.getDayOfMonth());
+ p("year: " + db.getYear());
+ p("month: " + db.getMonth());
+ p("time: " + db.getTime());
+ p("date: " + db.getDate());
+ p("Day: " + db.getDay());
+ p("DayOfYear: " + db.getDayOfYear());
+ p("WeekOfYear: " + db.getWeekOfYear());
+ p("era: " + db.getEra());
+ p("ampm: " + db.getAMPM());
+ p("DST: " + db.getDSTOffset());
+ p("ZONE Offset: " + db.getZoneOffset());
+ p("TIMEZONE: " + db.getUSTimeZone());
}
private static void p(String x) {
- System.out.println(x);
+ System.out.println(x);
}
public int getEra() {
- return calendar.get(Calendar.ERA);
+ return calendar.get(Calendar.ERA);
}
public String getUSTimeZone() {
- String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
- "Mountain", "Central", "Eastern"};
-
- return zones[10 + getZoneOffset()];
+ String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
+ "Mountain", "Central", "Eastern"};
+
+ return zones[10 + getZoneOffset()];
}
public int getZoneOffset() {
- return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
+ return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
}
public int getDSTOffset() {
- return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
+ return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
}
-
+
public int getAMPM() {
- return calendar.get(Calendar.AM_PM);
+ return calendar.get(Calendar.AM_PM);
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.class b/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.class
index 5445742..fd96ee2 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.java b/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.java
index 3af3a38..67aff03 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/error/Smart.java
@@ -1,32 +1,30 @@
/*
-* 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.
-*/
-
-
+ * 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 error;
public class Smart {
- String name = "JSP";
+ String name = "JSP";
- public String getName () {
- return name;
- }
+ public String getName() {
+ return name;
+ }
- public void setName (String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.class b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.class
index 35edd28..4ac9330 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java
index 13bcd16..d339adb 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java
@@ -16,52 +16,59 @@
*/
package examples;
-import javax.servlet.jsp.*;
-import javax.servlet.jsp.tagext.*;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.Tag;
public abstract class ExampleTagBase extends BodyTagSupport {
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void setParent(Tag parent) {
this.parent = parent;
}
+ @Override
public void setBodyContent(BodyContent bodyOut) {
this.bodyOut = bodyOut;
}
- public void setPageContext(PageContext pageContext) {
- this.pageContext = pageContext;
- }
-
+ @Override
public Tag getParent() {
return this.parent;
}
-
+
+ @Override
public int doStartTag() throws JspException {
return SKIP_BODY;
}
+ @Override
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
-
- // Default implementations for BodyTag methods as well
- // just in case a tag decides to implement BodyTag.
+
+ @Override
public void doInitBody() throws JspException {
+ // Default implementations for BodyTag methods as well
+ // just in case a tag decides to implement BodyTag.
}
+ @Override
public int doAfterBody() throws JspException {
return SKIP_BODY;
}
+ @Override
public void release() {
bodyOut = null;
pageContext = null;
parent = null;
}
-
+
protected BodyContent bodyOut;
- protected PageContext pageContext;
protected Tag parent;
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.class
index d60a6bd..3d6d760 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.java
index 4e11f30..c8fdb0a 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTag.java
@@ -16,9 +16,11 @@
*/
package examples;
-import javax.servlet.jsp.*;
import java.io.IOException;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+
/**
* Example1: the simplest tag
* Collect attributes and call into some actions
@@ -26,20 +28,21 @@
* <foo att1="..." att2="...." att3="...." />
*/
-public class FooTag
- extends ExampleTagBase
-{
+public class FooTag extends ExampleTagBase {
+
+ private static final long serialVersionUID = 1L;
+
private String atts[] = new String[3];
int i = 0;
-
+
private final void setAtt(int index, String value) {
atts[index] = value;
}
-
+
public void setAtt1(String value) {
setAtt(0, value);
}
-
+
public void setAtt2(String value) {
setAtt(1, value);
}
@@ -47,29 +50,33 @@
public void setAtt3(String value) {
setAtt(2, value);
}
-
+
/**
* Process start tag
*
* @return EVAL_BODY_INCLUDE
*/
+ @Override
public int doStartTag() throws JspException {
i = 0;
- return EVAL_BODY_BUFFERED;
+ return EVAL_BODY_BUFFERED;
}
+ @Override
public void doInitBody() throws JspException {
pageContext.setAttribute("member", atts[i]);
i++;
}
-
+
+ @Override
public int doAfterBody() throws JspException {
try {
if (i == 3) {
bodyOut.writeOut(bodyOut.getEnclosingWriter());
return SKIP_BODY;
- } else
- pageContext.setAttribute("member", atts[i]);
+ }
+
+ pageContext.setAttribute("member", atts[i]);
i++;
return EVAL_BODY_BUFFERED;
} catch (IOException ex) {
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.class b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.class
index 5ca9cfb..ead843e 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java
index 99e5dfb..1ae0492 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java
@@ -16,11 +16,14 @@
*/
package examples;
-import javax.servlet.jsp.tagext.*;
+import javax.servlet.jsp.tagext.TagData;
+import javax.servlet.jsp.tagext.TagExtraInfo;
+import javax.servlet.jsp.tagext.VariableInfo;
public class FooTagExtraInfo extends TagExtraInfo {
+ @Override
public VariableInfo[] getVariableInfo(TagData data) {
- return new VariableInfo[]
+ return new VariableInfo[]
{
new VariableInfo("member",
"String",
@@ -30,4 +33,4 @@
}
}
-
+
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.class
index 92abeab..7b62ca8 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.java
index 961cfc8..32584fd 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/LogTag.java
@@ -16,19 +16,20 @@
*/
package examples;
-
-import javax.servlet.jsp.*;
-
import java.io.IOException;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+
/**
- * Log the contents of the body. Could be used to handle errors etc.
+ * Log the contents of the body. Could be used to handle errors etc.
*/
-public class LogTag
- extends ExampleTagBase
-{
+public class LogTag extends ExampleTagBase {
+
+ private static final long serialVersionUID = 1L;
+
boolean toBrowser = false;
-
+
public void setToBrowser(String value) {
if (value == null)
toBrowser = false;
@@ -38,10 +39,12 @@
toBrowser = false;
}
+ @Override
public int doStartTag() throws JspException {
return EVAL_BODY_BUFFERED;
}
-
+
+ @Override
public int doAfterBody() throws JspException {
try {
String s = bodyOut.getString();
@@ -55,6 +58,4 @@
}
}
-
-
-
+
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.class b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.class
index c02b3ff..5e4fba6 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.java b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.java
index 8afbf09..195e32d 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ShowSource.java
@@ -16,43 +16,45 @@
*/
package examples;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
-import javax.servlet.jsp.*;
-import javax.servlet.jsp.tagext.*;
-
-import java.io.*;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.TagSupport;
/**
* Display the sources of the JSP file.
*/
-public class ShowSource
- extends TagSupport
-{
+public class ShowSource extends TagSupport {
+
+ private static final long serialVersionUID = 1L;
+
String jspFile;
-
+
public void setJspFile(String jspFile) {
this.jspFile = jspFile;
}
+ @Override
public int doEndTag() throws JspException {
- if ((jspFile.indexOf( ".." ) >= 0) ||
- (jspFile.toUpperCase().indexOf("/WEB-INF/") != 0) ||
- (jspFile.toUpperCase().indexOf("/META-INF/") != 0))
- throw new JspTagException("Invalid JSP file " + jspFile);
+ if ((jspFile.indexOf( ".." ) >= 0) ||
+ (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/WEB-INF/") != 0) ||
+ (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/META-INF/") != 0))
+ throw new JspTagException("Invalid JSP file " + jspFile);
- InputStream in
- = pageContext.getServletContext().getResourceAsStream(jspFile);
-
+ InputStream in = pageContext.getServletContext().getResourceAsStream(
+ jspFile);
if (in == null)
- throw new JspTagException("Unable to find JSP file: "+jspFile);
-
- JspWriter out = pageContext.getOut();
-
+ throw new JspTagException("Unable to find JSP file: " + jspFile);
try {
+ JspWriter out = pageContext.getOut();
out.println("<body>");
out.println("<pre>");
- for(int ch = in.read(); ch != -1; ch = in.read())
+ for (int ch = in.read(); ch != -1; ch = in.read())
if (ch == '<')
out.print("<");
else
@@ -60,12 +62,16 @@
out.println("</pre>");
out.println("</body>");
} catch (IOException ex) {
- throw new JspTagException("IOException: "+ex.toString());
+ throw new JspTagException("IOException: " + ex.toString());
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ throw new JspTagException("Can't close inputstream: ", e);
+ }
}
return super.doEndTag();
}
}
-
-
-
+
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ValuesTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ValuesTag.class
new file mode 100644
index 0000000..cc4d3ff
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ValuesTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ValuesTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ValuesTag.java
new file mode 100644
index 0000000..20468dc
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/examples/ValuesTag.java
@@ -0,0 +1,79 @@
+/*
+ * 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 examples;
+
+import java.io.IOException;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.TagSupport;
+
+/**
+ * Accept and display a value.
+ */
+public class ValuesTag extends TagSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ // Using "-1" as the default value,
+ // in the assumption that it won't be used as the value.
+ // Cannot use null here, because null is an important case
+ // that should be present in the tests.
+ private Object objectValue = "-1";
+ private String stringValue = "-1";
+ private long longValue = -1;
+ private double doubleValue = -1;
+
+ public void setObject(Object objectValue) {
+ this.objectValue = objectValue;
+ }
+
+ public void setString(String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+ public void setLong(long longValue) {
+ this.longValue = longValue;
+ }
+
+ public void setDouble(double doubleValue) {
+ this.doubleValue = doubleValue;
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ JspWriter out = pageContext.getOut();
+
+ try {
+ if (!"-1".equals(objectValue)) {
+ out.print(objectValue);
+ } else if (!"-1".equals(stringValue)) {
+ out.print(stringValue);
+ } else if (longValue != -1) {
+ out.print(longValue);
+ } else if (doubleValue != -1) {
+ out.print(doubleValue);
+ } else {
+ out.print("-1");
+ }
+ } catch (IOException ex) {
+ throw new JspTagException("IOException: " + ex.toString(), ex);
+ }
+ return super.doEndTag();
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.class b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.class
index 10a6710..12e41d8 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java
index 0601b87..59764ef 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java
@@ -19,6 +19,7 @@
import java.io.IOException;
+
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -67,6 +68,7 @@
/**
* Take this filter out of service.
*/
+ @Override
public void destroy() {
this.attribute = null;
@@ -80,27 +82,28 @@
* current filter stack, including the ultimately invoked servlet.
*
* @param request The servlet request we are processing
- * @param result The servlet response we are creating
+ * @param response The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
+ @Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
- throws IOException, ServletException {
+ throws IOException, ServletException {
- // Store ourselves as a request attribute (if requested)
- if (attribute != null)
- request.setAttribute(attribute, this);
+ // Store ourselves as a request attribute (if requested)
+ if (attribute != null)
+ request.setAttribute(attribute, this);
- // Time and log the subsequent processing
- long startTime = System.currentTimeMillis();
+ // Time and log the subsequent processing
+ long startTime = System.currentTimeMillis();
chain.doFilter(request, response);
- long stopTime = System.currentTimeMillis();
- filterConfig.getServletContext().log
- (this.toString() + ": " + (stopTime - startTime) +
- " milliseconds");
+ long stopTime = System.currentTimeMillis();
+ filterConfig.getServletContext().log
+ (this.toString() + ": " + (stopTime - startTime) +
+ " milliseconds");
}
@@ -108,12 +111,13 @@
/**
* Place this filter into service.
*
- * @param filterConfig The filter configuration object
+ * @param fConfig The filter configuration object
*/
- public void init(FilterConfig filterConfig) throws ServletException {
+ @Override
+ public void init(FilterConfig fConfig) throws ServletException {
- this.filterConfig = filterConfig;
- this.attribute = filterConfig.getInitParameter("attribute");
+ this.filterConfig = fConfig;
+ this.attribute = fConfig.getInitParameter("attribute");
}
@@ -121,14 +125,15 @@
/**
* Return a String representation of this object.
*/
+ @Override
public String toString() {
- if (filterConfig == null)
- return ("InvokerFilter()");
- StringBuffer sb = new StringBuffer("InvokerFilter(");
- sb.append(filterConfig);
- sb.append(")");
- return (sb.toString());
+ if (filterConfig == null)
+ return ("TimingFilter()");
+ StringBuilder sb = new StringBuilder("TimingFilter(");
+ sb.append(filterConfig);
+ sb.append(")");
+ return (sb.toString());
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.class b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.class
deleted file mode 100644
index 5b244bf..0000000
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.class
+++ /dev/null
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java
deleted file mode 100644
index 7c45a40..0000000
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
-* 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 filters;
-
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.sql.Timestamp;
-import java.util.Enumeration;
-import java.util.Locale;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-
-
-/**
- * Example filter that dumps interesting state information about a request
- * to the associated servlet context log file, before allowing the servlet
- * to process the request in the usual way. This can be installed as needed
- * to assist in debugging problems.
- *
- * @author Craig McClanahan
- */
-public final class RequestDumperFilter implements Filter {
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The filter configuration object we are associated with. If this value
- * is null, this filter instance is not currently configured.
- */
- private FilterConfig filterConfig = null;
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Take this filter out of service.
- */
- public void destroy() {
-
- this.filterConfig = null;
-
- }
-
-
- /**
- * Time the processing that is performed by all subsequent filters in the
- * current filter stack, including the ultimately invoked servlet.
- *
- * @param request The servlet request we are processing
- * @param result The servlet response we are creating
- * @param chain The filter chain we are processing
- *
- * @exception IOException if an input/output error occurs
- * @exception ServletException if a servlet error occurs
- */
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain)
- throws IOException, ServletException {
-
- if (filterConfig == null)
- return;
-
- // Render the generic servlet request properties
- StringWriter sw = new StringWriter();
- PrintWriter writer = new PrintWriter(sw);
- writer.println("Request Received at " +
- (new Timestamp(System.currentTimeMillis())));
- writer.println(" characterEncoding=" + request.getCharacterEncoding());
- writer.println(" contentLength=" + request.getContentLength());
- writer.println(" contentType=" + request.getContentType());
- writer.println(" locale=" + request.getLocale());
- writer.print(" locales=");
- Enumeration locales = request.getLocales();
- boolean first = true;
- while (locales.hasMoreElements()) {
- Locale locale = (Locale) locales.nextElement();
- if (first)
- first = false;
- else
- writer.print(", ");
- writer.print(locale.toString());
- }
- writer.println();
- Enumeration names = request.getParameterNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- writer.print(" parameter=" + name + "=");
- String values[] = request.getParameterValues(name);
- for (int i = 0; i < values.length; i++) {
- if (i > 0)
- writer.print(", ");
- writer.print(values[i]);
- }
- writer.println();
- }
- writer.println(" protocol=" + request.getProtocol());
- writer.println(" remoteAddr=" + request.getRemoteAddr());
- writer.println(" remoteHost=" + request.getRemoteHost());
- writer.println(" scheme=" + request.getScheme());
- writer.println(" serverName=" + request.getServerName());
- writer.println(" serverPort=" + request.getServerPort());
- writer.println(" isSecure=" + request.isSecure());
-
- // Render the HTTP servlet request properties
- if (request instanceof HttpServletRequest) {
- writer.println("---------------------------------------------");
- HttpServletRequest hrequest = (HttpServletRequest) request;
- writer.println(" contextPath=" + hrequest.getContextPath());
- Cookie cookies[] = hrequest.getCookies();
- if (cookies == null)
- cookies = new Cookie[0];
- for (int i = 0; i < cookies.length; i++) {
- writer.println(" cookie=" + cookies[i].getName() +
- "=" + cookies[i].getValue());
- }
- names = hrequest.getHeaderNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- String value = hrequest.getHeader(name);
- writer.println(" header=" + name + "=" + value);
- }
- writer.println(" method=" + hrequest.getMethod());
- writer.println(" pathInfo=" + hrequest.getPathInfo());
- writer.println(" queryString=" + hrequest.getQueryString());
- writer.println(" remoteUser=" + hrequest.getRemoteUser());
- writer.println("requestedSessionId=" +
- hrequest.getRequestedSessionId());
- writer.println(" requestURI=" + hrequest.getRequestURI());
- writer.println(" servletPath=" + hrequest.getServletPath());
- }
- writer.println("=============================================");
-
- // Log the resulting string
- writer.flush();
- filterConfig.getServletContext().log(sw.getBuffer().toString());
-
- // Pass control on to the next filter
- chain.doFilter(request, response);
-
- }
-
-
- /**
- * Place this filter into service.
- *
- * @param filterConfig The filter configuration object
- */
- public void init(FilterConfig filterConfig) throws ServletException {
-
- this.filterConfig = filterConfig;
-
- }
-
-
- /**
- * Return a String representation of this object.
- */
- public String toString() {
-
- if (filterConfig == null)
- return ("RequestDumperFilter()");
- StringBuffer sb = new StringBuffer("RequestDumperFilter(");
- sb.append(filterConfig);
- sb.append(")");
- return (sb.toString());
-
- }
-
-
-}
-
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.class b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.class
deleted file mode 100644
index 94be00b..0000000
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.class
+++ /dev/null
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java b/tomcat-cas/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java
deleted file mode 100644
index 9373222..0000000
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
-* 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 filters;
-
-
-import java.io.IOException;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-
-/**
- * <p>Example filter that sets the character encoding to be used in parsing the
- * incoming request, either unconditionally or only if the client did not
- * specify a character encoding. Configuration of this filter is based on
- * the following initialization parameters:</p>
- * <ul>
- * <li><strong>encoding</strong> - The character encoding to be configured
- * for this request, either conditionally or unconditionally based on
- * the <code>ignore</code> initialization parameter. This parameter
- * is required, so there is no default.</li>
- * <li><strong>ignore</strong> - If set to "true", any character encoding
- * specified by the client is ignored, and the value returned by the
- * <code>selectEncoding()</code> method is set. If set to "false,
- * <code>selectEncoding()</code> is called <strong>only</strong> if the
- * client has not already specified an encoding. By default, this
- * parameter is set to "true".</li>
- * </ul>
- *
- * <p>Although this filter can be used unchanged, it is also easy to
- * subclass it and make the <code>selectEncoding()</code> method more
- * intelligent about what encoding to choose, based on characteristics of
- * the incoming request (such as the values of the <code>Accept-Language</code>
- * and <code>User-Agent</code> headers, or a value stashed in the current
- * user's session.</p>
- *
- * @author Craig McClanahan
- */
-public class SetCharacterEncodingFilter implements Filter {
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The default character encoding to set for requests that pass through
- * this filter.
- */
- protected String encoding = null;
-
-
- /**
- * The filter configuration object we are associated with. If this value
- * is null, this filter instance is not currently configured.
- */
- protected FilterConfig filterConfig = null;
-
-
- /**
- * Should a character encoding specified by the client be ignored?
- */
- protected boolean ignore = true;
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Take this filter out of service.
- */
- public void destroy() {
-
- this.encoding = null;
- this.filterConfig = null;
-
- }
-
-
- /**
- * Select and set (if specified) the character encoding to be used to
- * interpret request parameters for this request.
- *
- * @param request The servlet request we are processing
- * @param result The servlet response we are creating
- * @param chain The filter chain we are processing
- *
- * @exception IOException if an input/output error occurs
- * @exception ServletException if a servlet error occurs
- */
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain)
- throws IOException, ServletException {
-
- // Conditionally select and set the character encoding to be used
- if (ignore || (request.getCharacterEncoding() == null)) {
- String encoding = selectEncoding(request);
- if (encoding != null)
- request.setCharacterEncoding(encoding);
- }
-
- // Pass control on to the next filter
- chain.doFilter(request, response);
-
- }
-
-
- /**
- * Place this filter into service.
- *
- * @param filterConfig The filter configuration object
- */
- public void init(FilterConfig filterConfig) throws ServletException {
-
- this.filterConfig = filterConfig;
- this.encoding = filterConfig.getInitParameter("encoding");
- String value = filterConfig.getInitParameter("ignore");
- if (value == null)
- this.ignore = true;
- else if (value.equalsIgnoreCase("true"))
- this.ignore = true;
- else if (value.equalsIgnoreCase("yes"))
- this.ignore = true;
- else
- this.ignore = false;
-
- }
-
-
- // ------------------------------------------------------ Protected Methods
-
-
- /**
- * Select an appropriate character encoding to be used, based on the
- * characteristics of the current request and/or filter initialization
- * parameters. If no character encoding should be set, return
- * <code>null</code>.
- * <p>
- * The default implementation unconditionally returns the value configured
- * by the <strong>encoding</strong> initialization parameter for this
- * filter.
- *
- * @param request The servlet request we are processing
- */
- protected String selectEncoding(ServletRequest request) {
-
- return (this.encoding);
-
- }
-
-
-}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.class
index 98b8c31..e817362 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java
index 5e5dec4..cc7e805 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java
@@ -22,7 +22,7 @@
private String title;
private String author;
private String isbn;
-
+
public BookBean( String title, String author, String isbn ) {
this.title = title;
this.author = author;
@@ -32,13 +32,13 @@
public String getTitle() {
return this.title;
}
-
+
public String getAuthor() {
return this.author;
}
-
+
public String getIsbn() {
return this.isbn;
}
-
+
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.class
index 6605d19..f624400 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java
index c7f4d39..057a581 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java
@@ -20,17 +20,17 @@
public class FooBean {
private String bar;
-
+
public FooBean() {
bar = "Initial value";
}
-
+
public String getBar() {
return this.bar;
}
-
+
public void setBar(String bar) {
this.bar = bar;
}
-
+
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.class
new file mode 100644
index 0000000..1ae6315
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java
new file mode 100644
index 0000000..b7ff056
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/ValuesBean.java
@@ -0,0 +1,52 @@
+/*
+* 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 jsp2.examples;
+
+/**
+ * Accept and display a value.
+ */
+public class ValuesBean {
+ private String string;
+ private double doubleValue;
+ private long longValue;
+
+ public String getStringValue() {
+ return this.string;
+ }
+
+ public void setStringValue(String string) {
+ this.string = string;
+ }
+
+ public double getDoubleValue() {
+ return doubleValue;
+ }
+
+ public void setDoubleValue(double doubleValue) {
+ this.doubleValue = doubleValue;
+ }
+
+ public long getLongValue() {
+ return longValue;
+ }
+
+ public void setLongValue(long longValue) {
+ this.longValue = longValue;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.class
index e0a869c..54f11ef 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java
index c42c0f7..cc15bf3 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java
@@ -16,28 +16,30 @@
*/
package jsp2.examples.el;
+import java.util.Locale;
+
/**
* Defines the functions for the jsp2 example tag library.
- *
+ *
* <p>Each function is defined as a static method.</p>
*/
public class Functions {
public static String reverse( String text ) {
- return new StringBuffer( text ).reverse().toString();
+ return new StringBuilder( text ).reverse().toString();
}
public static int numVowels( String text ) {
String vowels = "aeiouAEIOU";
- int result = 0;
+ int result = 0;
for( int i = 0; i < text.length(); i++ ) {
- if( vowels.indexOf( text.charAt( i ) ) != -1 ) {
- result++;
- }
- }
- return result;
+ if( vowels.indexOf( text.charAt( i ) ) != -1 ) {
+ result++;
+ }
+ }
+ return result;
}
public static String caps( String text ) {
- return text.toUpperCase();
+ return text.toUpperCase(Locale.ENGLISH);
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.class
index 5cf67e4..f1ca8cd 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java
index c1a5f92..4dd5322 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java
@@ -18,37 +18,40 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+import java.util.ArrayList;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.tagext.SimpleTagSupport;
import javax.servlet.jsp.tagext.DynamicAttributes;
-import java.util.ArrayList;
-import java.io.IOException;
+import javax.servlet.jsp.tagext.SimpleTagSupport;
/**
- * SimpleTag handler that echoes all its attributes
+ * SimpleTag handler that echoes all its attributes
*/
-public class EchoAttributesTag
+public class EchoAttributesTag
extends SimpleTagSupport
implements DynamicAttributes
{
- private ArrayList keys = new ArrayList();
- private ArrayList values = new ArrayList();
+ private ArrayList<String> keys = new ArrayList<String>();
+ private ArrayList<Object> values = new ArrayList<Object>();
+ @Override
public void doTag() throws JspException, IOException {
- JspWriter out = getJspContext().getOut();
- for( int i = 0; i < keys.size(); i++ ) {
- String key = (String)keys.get( i );
- Object value = values.get( i );
- out.println( "<li>" + key + " = " + value + "</li>" );
+ JspWriter out = getJspContext().getOut();
+ for( int i = 0; i < keys.size(); i++ ) {
+ String key = keys.get( i );
+ Object value = values.get( i );
+ out.println( "<li>" + key + " = " + value + "</li>" );
}
}
- public void setDynamicAttribute( String uri, String localName,
- Object value )
- throws JspException
+ @Override
+ public void setDynamicAttribute( String uri, String localName,
+ Object value )
+ throws JspException
{
- keys.add( localName );
- values.add( value );
+ keys.add( localName );
+ values.add( value );
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.class
index dd95ddb..4b3a691 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java
index 3d4357d..7554558 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java
@@ -20,6 +20,7 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
+
import jsp2.examples.BookBean;
/**
@@ -28,17 +29,18 @@
*/
public class FindBookSimpleTag extends SimpleTagSupport {
private String var;
-
+
private static final String BOOK_TITLE = "The Lord of the Rings";
private static final String BOOK_AUTHOR = "J. R. R. Tolkein";
private static final String BOOK_ISBN = "0618002251";
+ @Override
public void doTag() throws JspException {
BookBean book = new BookBean( BOOK_TITLE, BOOK_AUTHOR, BOOK_ISBN );
getJspContext().setAttribute( this.var, book );
}
public void setVar( String var ) {
- this.var = var;
+ this.var = var;
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.class
index ff44a1d..21450f5 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java
index 3085739..e068b65 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java
@@ -18,15 +18,17 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* SimpleTag handler that prints "Hello, world!"
*/
public class HelloWorldSimpleTag extends SimpleTagSupport {
+ @Override
public void doTag() throws JspException, IOException {
- getJspContext().getOut().write( "Hello, world!" );
+ getJspContext().getOut().write( "Hello, world!" );
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.class
index 55e4835..6307468 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java
index 9903a21..a9dda90 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java
@@ -18,25 +18,27 @@
package jsp2.examples.simpletag;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.SimpleTagSupport;
+
/**
- * SimpleTag handler that accepts a num attribute and
+ * SimpleTag handler that accepts a num attribute and
* invokes its body 'num' times.
*/
public class RepeatSimpleTag extends SimpleTagSupport {
private int num;
+ @Override
public void doTag() throws JspException, IOException {
for (int i=0; i<num; i++) {
getJspContext().setAttribute("count", String.valueOf( i + 1 ) );
- getJspBody().invoke(null);
+ getJspBody().invoke(null);
}
}
public void setNum(int num) {
- this.num = num;
+ this.num = num;
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.class
index 759c5ac..3ba23ed 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.java
index 64c5b72..e796af2 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/ShuffleSimpleTag.java
@@ -18,22 +18,28 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+import java.util.Random;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* SimpleTag handler that accepts takes three attributes of type
* JspFragment and invokes then in a random order.
*/
public class ShuffleSimpleTag extends SimpleTagSupport {
+ // No need for this to use SecureRandom
+ private static Random random = new Random();
+
private JspFragment fragment1;
private JspFragment fragment2;
private JspFragment fragment3;
+ @Override
public void doTag() throws JspException, IOException {
- switch( (int)(Math.random() * 6) ) {
+ switch(random.nextInt(6)) {
case 0:
fragment1.invoke( null );
fragment2.invoke( null );
@@ -70,11 +76,11 @@
public void setFragment1( JspFragment fragment1 ) {
this.fragment1 = fragment1;
}
-
+
public void setFragment2( JspFragment fragment2 ) {
this.fragment2 = fragment2;
}
-
+
public void setFragment3( JspFragment fragment3 ) {
this.fragment3 = fragment3;
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.class b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.class
index c33cccc..d2162fe 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.java b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.java
index 4f37e48..b95cc31 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/TileSimpleTag.java
@@ -18,9 +18,10 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* Displays a tile as a single cell in a table.
@@ -29,17 +30,18 @@
private String color;
private String label;
+ @Override
public void doTag() throws JspException, IOException {
- getJspContext().getOut().write(
- "<td width=\"32\" height=\"32\" bgcolor=\"" + this.color +
- "\"><font color=\"#ffffff\"><center>" + this.label +
+ getJspContext().getOut().write(
+ "<td width=\"32\" height=\"32\" bgcolor=\"" + this.color +
+ "\"><font color=\"#ffffff\"><center>" + this.label +
"</center></font></td>" );
}
public void setColor( String color ) {
this.color = color;
}
-
+
public void setLabel( String label ) {
this.label = label;
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.class b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.class
index 43f66ff..26619b0 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.java b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.java
index 4702546..7fd012f 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/ContextListener.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package listeners;
@@ -54,10 +53,11 @@
*
* @param event The servlet context attribute event
*/
+ @Override
public void attributeAdded(ServletContextAttributeEvent event) {
- log("attributeAdded('" + event.getName() + "', '" +
- event.getValue() + "')");
+ log("attributeAdded('" + event.getName() + "', '" +
+ event.getValue() + "')");
}
@@ -67,10 +67,11 @@
*
* @param event The servlet context attribute event
*/
+ @Override
public void attributeRemoved(ServletContextAttributeEvent event) {
- log("attributeRemoved('" + event.getName() + "', '" +
- event.getValue() + "')");
+ log("attributeRemoved('" + event.getName() + "', '" +
+ event.getValue() + "')");
}
@@ -80,10 +81,11 @@
*
* @param event The servlet context attribute event
*/
+ @Override
public void attributeReplaced(ServletContextAttributeEvent event) {
- log("attributeReplaced('" + event.getName() + "', '" +
- event.getValue() + "')");
+ log("attributeReplaced('" + event.getName() + "', '" +
+ event.getValue() + "')");
}
@@ -93,10 +95,11 @@
*
* @param event The servlet context event
*/
+ @Override
public void contextDestroyed(ServletContextEvent event) {
- log("contextDestroyed()");
- this.context = null;
+ log("contextDestroyed()");
+ this.context = null;
}
@@ -106,10 +109,11 @@
*
* @param event The servlet context event
*/
+ @Override
public void contextInitialized(ServletContextEvent event) {
- this.context = event.getServletContext();
- log("contextInitialized()");
+ this.context = event.getServletContext();
+ log("contextInitialized()");
}
@@ -124,10 +128,10 @@
*/
private void log(String message) {
- if (context != null)
- context.log("ContextListener: " + message);
- else
- System.out.println("ContextListener: " + message);
+ if (context != null)
+ context.log("ContextListener: " + message);
+ else
+ System.out.println("ContextListener: " + message);
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.class b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.class
index 8afca5e..22c53ea 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.java b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.java
index efac784..06a2aa8 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/listeners/SessionListener.java
@@ -1,23 +1,21 @@
/*
-* 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.
-*/
-
+ * 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 listeners;
-
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -26,135 +24,136 @@
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
-
/**
* Example listener for context-related application events, which were
- * introduced in the 2.3 version of the Servlet API. This listener
- * merely documents the occurrence of such events in the application log
- * associated with our servlet context.
+ * introduced in the 2.3 version of the Servlet API. This listener merely
+ * documents the occurrence of such events in the application log associated
+ * with our servlet context.
*
* @author Craig R. McClanahan
*/
-public final class SessionListener
- implements ServletContextListener,
- HttpSessionAttributeListener, HttpSessionListener {
-
+public final class SessionListener implements ServletContextListener,
+ HttpSessionAttributeListener, HttpSessionListener {
// ----------------------------------------------------- Instance Variables
-
/**
* The servlet context with which we are associated.
*/
private ServletContext context = null;
-
// --------------------------------------------------------- Public Methods
-
/**
* Record the fact that a servlet context attribute was added.
*
- * @param event The session attribute event
+ * @param event
+ * The session attribute event
*/
+ @Override
public void attributeAdded(HttpSessionBindingEvent event) {
- log("attributeAdded('" + event.getSession().getId() + "', '" +
- event.getName() + "', '" + event.getValue() + "')");
+ log("attributeAdded('" + event.getSession().getId() + "', '"
+ + event.getName() + "', '" + event.getValue() + "')");
}
-
/**
* Record the fact that a servlet context attribute was removed.
*
- * @param event The session attribute event
+ * @param event
+ * The session attribute event
*/
+ @Override
public void attributeRemoved(HttpSessionBindingEvent event) {
- log("attributeRemoved('" + event.getSession().getId() + "', '" +
- event.getName() + "', '" + event.getValue() + "')");
+ log("attributeRemoved('" + event.getSession().getId() + "', '"
+ + event.getName() + "', '" + event.getValue() + "')");
}
-
/**
* Record the fact that a servlet context attribute was replaced.
*
- * @param event The session attribute event
+ * @param event
+ * The session attribute event
*/
+ @Override
public void attributeReplaced(HttpSessionBindingEvent event) {
- log("attributeReplaced('" + event.getSession().getId() + "', '" +
- event.getName() + "', '" + event.getValue() + "')");
+ log("attributeReplaced('" + event.getSession().getId() + "', '"
+ + event.getName() + "', '" + event.getValue() + "')");
}
-
/**
* Record the fact that this web application has been destroyed.
*
- * @param event The servlet context event
+ * @param event
+ * The servlet context event
*/
+ @Override
public void contextDestroyed(ServletContextEvent event) {
- log("contextDestroyed()");
- this.context = null;
+ log("contextDestroyed()");
+ this.context = null;
}
-
/**
* Record the fact that this web application has been initialized.
*
- * @param event The servlet context event
+ * @param event
+ * The servlet context event
*/
+ @Override
public void contextInitialized(ServletContextEvent event) {
- this.context = event.getServletContext();
- log("contextInitialized()");
+ this.context = event.getServletContext();
+ log("contextInitialized()");
}
-
/**
* Record the fact that a session has been created.
*
- * @param event The session event
+ * @param event
+ * The session event
*/
+ @Override
public void sessionCreated(HttpSessionEvent event) {
- log("sessionCreated('" + event.getSession().getId() + "')");
+ log("sessionCreated('" + event.getSession().getId() + "')");
}
-
/**
* Record the fact that a session has been destroyed.
*
- * @param event The session event
+ * @param event
+ * The session event
*/
+ @Override
public void sessionDestroyed(HttpSessionEvent event) {
- log("sessionDestroyed('" + event.getSession().getId() + "')");
+ log("sessionDestroyed('" + event.getSession().getId() + "')");
}
-
// -------------------------------------------------------- Private Methods
-
/**
* Log a message to the servlet context application log.
*
- * @param message Message to be logged
+ * @param message
+ * Message to be logged
*/
private void log(String message) {
- if (context != null)
- context.log("SessionListener: " + message);
- else
- System.out.println("SessionListener: " + message);
+ if (context != null)
+ context.log("SessionListener: " + message);
+ else
+ System.out.println("SessionListener: " + message);
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.class b/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.class
index 51e5b62..e2051e9 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java b/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java
index 7eed08e..a619edb 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.
+ */
/*
* Originally written by Jason Hunter, http://www.servlets.com.
@@ -21,59 +21,79 @@
package num;
-import java.util.*;
+import java.io.Serializable;
+import java.util.Random;
-public class NumberGuessBean {
+public class NumberGuessBean implements Serializable {
- int answer;
- boolean success;
- String hint;
- int numGuesses;
+ private static final long serialVersionUID = 1L;
- public NumberGuessBean() {
- reset();
- }
+ private int answer;
+ private String hint;
+ private int numGuesses;
+ private boolean success;
+ private Random random = new Random();
- public void setGuess(String guess) {
- numGuesses++;
-
- int g;
- try {
- g = Integer.parseInt(guess);
- }
- catch (NumberFormatException e) {
- g = -1;
+ public NumberGuessBean() {
+ reset();
}
- if (g == answer) {
- success = true;
+ public int getAnswer() {
+ return answer;
}
- else if (g == -1) {
- hint = "a number next time";
+
+ public void setAnswer(int answer) {
+ this.answer = answer;
}
- else if (g < answer) {
- hint = "higher";
+
+ public String getHint() {
+ return "" + hint;
}
- else if (g > answer) {
- hint = "lower";
+
+ public void setHint(String hint) {
+ this.hint = hint;
}
- }
- public boolean getSuccess() {
- return success;
- }
+ public void setNumGuesses(int numGuesses) {
+ this.numGuesses = numGuesses;
+ }
- public String getHint() {
- return "" + hint;
- }
+ public int getNumGuesses() {
+ return numGuesses;
+ }
- public int getNumGuesses() {
- return numGuesses;
- }
+ public boolean getSuccess() {
+ return success;
+ }
- public void reset() {
- answer = Math.abs(new Random().nextInt() % 100) + 1;
- success = false;
- numGuesses = 0;
- }
+ public void setSuccess(boolean success) {
+ this.success = success;
+ }
+
+ public void setGuess(String guess) {
+ numGuesses++;
+
+ int g;
+ try {
+ g = Integer.parseInt(guess);
+ } catch (NumberFormatException e) {
+ g = -1;
+ }
+
+ if (g == answer) {
+ success = true;
+ } else if (g == -1) {
+ hint = "a number next time";
+ } else if (g < answer) {
+ hint = "higher";
+ } else if (g > answer) {
+ hint = "lower";
+ }
+ }
+
+ public void reset() {
+ answer = Math.abs(random.nextInt() % 100) + 1;
+ success = false;
+ numGuesses = 0;
+ }
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.class b/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.class
index c95143b..4432239 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.java b/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.java
index cfd198e..f5cd80a 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/servletToJsp.java
@@ -14,19 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import javax.servlet.http.*;
-public class servletToJsp extends HttpServlet {
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+public class ServletToJsp extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void doGet (HttpServletRequest request,
- HttpServletResponse response) {
+ HttpServletResponse response) {
- try {
- // Set the attribute and Forward to hello.jsp
- request.setAttribute ("servletName", "servletToJsp");
- getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response);
- } catch (Exception ex) {
- ex.printStackTrace ();
- }
+ try {
+ // Set the attribute and Forward to hello.jsp
+ request.setAttribute ("servletName", "servletToJsp");
+ getServletConfig().getServletContext().getRequestDispatcher(
+ "/jsp/jsptoserv/hello.jsp").forward(request, response);
+ } catch (Exception ex) {
+ ex.printStackTrace ();
+ }
}
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.class b/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.class
index 5518952..2ad60c0 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.java b/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.java
index f0597e7..01480a0 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/sessions/DummyCart.java
@@ -22,7 +22,7 @@
Vector<String> v = new Vector<String>();
String submit = null;
String item = null;
-
+
private void addItem(String name) {
v.addElement(name);
}
@@ -34,7 +34,7 @@
public void setItem(String name) {
item = name;
}
-
+
public void setSubmit(String s) {
submit = s;
}
@@ -44,15 +44,15 @@
v.copyInto(s);
return s;
}
-
+
public void processRequest() {
- // null value for submit - user hit enter instead of clicking on
+ // null value for submit - user hit enter instead of clicking on
// "add" or "remove"
if (submit == null || submit.equals("add"))
addItem(item);
- else if (submit.equals("remove"))
+ else if (submit.equals("remove"))
removeItem(item);
-
+
// reset at the end of the request
reset();
}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/util/CookieFilter.class b/tomcat-cas/webapps/examples/WEB-INF/classes/util/CookieFilter.class
new file mode 100644
index 0000000..429bbac
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/util/CookieFilter.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/util/CookieFilter.java b/tomcat-cas/webapps/examples/WEB-INF/classes/util/CookieFilter.java
new file mode 100644
index 0000000..005222f
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/util/CookieFilter.java
@@ -0,0 +1,81 @@
+/*
+ * 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 util;
+
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+/**
+ * Processes a cookie header and attempts to obfuscate any cookie values that
+ * represent session IDs from other web applications. Since session cookie names
+ * are configurable, as are session ID lengths, this filter is not expected to
+ * be 100% effective.
+ *
+ * It is required that the examples web application is removed in security
+ * conscious environments as documented in the Security How-To. This filter is
+ * intended to reduce the impact of failing to follow that advice. A failure by
+ * this filter to obfuscate a session ID or similar value is not a security
+ * vulnerability. In such instances the vulnerability is the failure to remove
+ * the examples web application.
+ */
+public class CookieFilter {
+
+ private static final String OBFUSCATED = "[obfuscated]";
+
+ private CookieFilter() {
+ // Hide default constructor
+ }
+
+ public static String filter(String input, String sessionId) {
+
+ StringBuilder sb = new StringBuilder(input.length());
+
+ // Cookie name value pairs are ';' separated.
+ // Session IDs don't use ; in the value so don't worry about quoted
+ // values that contain ;
+ StringTokenizer st = new StringTokenizer(input, ";");
+
+ boolean first = true;
+ while (st.hasMoreTokens()) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(';');
+ }
+ sb.append(filterNameValuePair(st.nextToken(), sessionId));
+ }
+
+
+ return sb.toString();
+ }
+
+ private static String filterNameValuePair(String input, String sessionId) {
+ int i = input.indexOf('=');
+ if (i == -1) {
+ return input;
+ }
+ String name = input.substring(0, i);
+ String value = input.substring(i + 1, input.length());
+
+ if (name.toLowerCase(Locale.ENGLISH).contains("jsessionid") &&
+ (sessionId == null || !value.contains(sessionId))) {
+ value = OBFUSCATED;
+ }
+
+ return name + "=" + value;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.class b/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.class
index 7555aa0..1ed1273 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.java b/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.java
index 3d85e81..ec66a89 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/util/HTMLFilter.java
@@ -39,7 +39,7 @@
char content[] = new char[message.length()];
message.getChars(0, message.length(), content, 0);
- StringBuffer result = new StringBuffer(content.length + 50);
+ StringBuilder result = new StringBuilder(content.length + 50);
for (int i = 0; i < content.length; i++) {
switch (content[i]) {
case '<':
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.class b/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.class
index 90b65ce..4a9fb4c 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.class
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.java b/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.java
index 1ddffc4..d5accba 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/validators/DebugValidator.java
@@ -19,8 +19,9 @@
package validators;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
+
import javax.servlet.jsp.tagext.PageData;
import javax.servlet.jsp.tagext.TagLibraryValidator;
import javax.servlet.jsp.tagext.ValidationMessage;
@@ -55,6 +56,7 @@
* @param uri The value of the URI argument in this directive
* @param page The page data for this page
*/
+ @Override
public ValidationMessage[] validate(String prefix, String uri,
PageData page) {
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/ExamplesConfig.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/ExamplesConfig.class
new file mode 100644
index 0000000..188802e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/ExamplesConfig.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/ExamplesConfig.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/ExamplesConfig.java
new file mode 100644
index 0000000..38ba838
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/ExamplesConfig.java
@@ -0,0 +1,66 @@
+/*
+ * 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 websocket;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.websocket.Endpoint;
+import javax.websocket.server.ServerApplicationConfig;
+import javax.websocket.server.ServerEndpointConfig;
+
+import websocket.drawboard.DrawboardEndpoint;
+import websocket.echo.EchoEndpoint;
+
+public class ExamplesConfig implements ServerApplicationConfig {
+
+ @Override
+ public Set<ServerEndpointConfig> getEndpointConfigs(
+ Set<Class<? extends Endpoint>> scanned) {
+
+ Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();
+
+ if (scanned.contains(EchoEndpoint.class)) {
+ result.add(ServerEndpointConfig.Builder.create(
+ EchoEndpoint.class,
+ "/websocket/echoProgrammatic").build());
+ }
+
+ if (scanned.contains(DrawboardEndpoint.class)) {
+ result.add(ServerEndpointConfig.Builder.create(
+ DrawboardEndpoint.class,
+ "/websocket/drawboard").build());
+ }
+
+ return result;
+ }
+
+
+ @Override
+ public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
+ // Deploy all WebSocket endpoints defined by annotations in the examples
+ // web application. Filter out all others to avoid issues when running
+ // tests on Gump
+ Set<Class<?>> results = new HashSet<Class<?>>();
+ for (Class<?> clazz : scanned) {
+ if (clazz.getPackage().getName().startsWith("websocket.")) {
+ results.add(clazz);
+ }
+ }
+ return results;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.class
new file mode 100644
index 0000000..154bd54
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java
new file mode 100644
index 0000000..d585d98
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java
@@ -0,0 +1,109 @@
+/*
+ * 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 websocket.chat;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.websocket.OnClose;
+import javax.websocket.OnError;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.ServerEndpoint;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+import util.HTMLFilter;
+
+@ServerEndpoint(value = "/websocket/chat")
+public class ChatAnnotation {
+
+ private static final Log log = LogFactory.getLog(ChatAnnotation.class);
+
+ private static final String GUEST_PREFIX = "Guest";
+ private static final AtomicInteger connectionIds = new AtomicInteger(0);
+ private static final Set<ChatAnnotation> connections =
+ new CopyOnWriteArraySet<ChatAnnotation>();
+
+ private final String nickname;
+ private Session session;
+
+ public ChatAnnotation() {
+ nickname = GUEST_PREFIX + connectionIds.getAndIncrement();
+ }
+
+
+ @OnOpen
+ public void start(Session session) {
+ this.session = session;
+ connections.add(this);
+ String message = String.format("* %s %s", nickname, "has joined.");
+ broadcast(message);
+ }
+
+
+ @OnClose
+ public void end() {
+ connections.remove(this);
+ String message = String.format("* %s %s",
+ nickname, "has disconnected.");
+ broadcast(message);
+ }
+
+
+ @OnMessage
+ public void incoming(String message) {
+ // Never trust the client
+ String filteredMessage = String.format("%s: %s",
+ nickname, HTMLFilter.filter(message.toString()));
+ broadcast(filteredMessage);
+ }
+
+
+
+
+ @OnError
+ public void onError(Throwable t) throws Throwable {
+ log.error("Chat Error: " + t.toString(), t);
+ }
+
+
+ private static void broadcast(String msg) {
+ for (ChatAnnotation client : connections) {
+ try {
+ synchronized (client) {
+ client.session.getBasicRemote().sendText(msg);
+ }
+ } catch (IOException e) {
+ log.debug("Chat Error: Failed to send message to client", e);
+ connections.remove(client);
+ try {
+ client.session.close();
+ } catch (IOException e1) {
+ // Ignore
+ }
+ String message = String.format("* %s %s",
+ client.nickname, "has been disconnected.");
+ broadcast(message);
+ }
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client$1.class
new file mode 100644
index 0000000..c152c6b
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client.class
new file mode 100644
index 0000000..53bb52a
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client.java
new file mode 100644
index 0000000..71e47c9
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Client.java
@@ -0,0 +1,233 @@
+/*
+ * 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 websocket.drawboard;
+
+import java.io.IOException;
+import java.util.LinkedList;
+
+import javax.websocket.CloseReason;
+import javax.websocket.CloseReason.CloseCodes;
+import javax.websocket.RemoteEndpoint.Async;
+import javax.websocket.SendHandler;
+import javax.websocket.SendResult;
+import javax.websocket.Session;
+
+import websocket.drawboard.wsmessages.AbstractWebsocketMessage;
+import websocket.drawboard.wsmessages.BinaryWebsocketMessage;
+import websocket.drawboard.wsmessages.CloseWebsocketMessage;
+import websocket.drawboard.wsmessages.StringWebsocketMessage;
+
+/**
+ * Represents a client with methods to send messages asynchronously.
+ */
+public class Client {
+
+ private final Session session;
+ private final Async async;
+
+ /**
+ * Contains the messages wich are buffered until the previous
+ * send operation has finished.
+ */
+ private final LinkedList<AbstractWebsocketMessage> messagesToSend =
+ new LinkedList<AbstractWebsocketMessage>();
+ /**
+ * If this client is currently sending a messages asynchronously.
+ */
+ private volatile boolean isSendingMessage = false;
+ /**
+ * If this client is closing. If <code>true</code>, new messages to
+ * send will be ignored.
+ */
+ private volatile boolean isClosing = false;
+ /**
+ * The length of all current buffered messages, to avoid iterating
+ * over a linked list.
+ */
+ private volatile long messagesToSendLength = 0;
+
+ public Client(Session session) {
+ this.session = session;
+ this.async = session.getAsyncRemote();
+ }
+
+ /**
+ * Asynchronously closes the Websocket session. This will wait until all
+ * remaining messages have been sent to the Client and then close
+ * the Websocket session.
+ */
+ public void close() {
+ sendMessage(new CloseWebsocketMessage());
+ }
+
+ /**
+ * Sends the given message asynchronously to the client.
+ * If there is already a async sending in progress, then the message
+ * will be buffered and sent when possible.<br><br>
+ *
+ * This method can be called from multiple threads.
+ * @param msg
+ */
+ public void sendMessage(AbstractWebsocketMessage msg) {
+ synchronized (messagesToSend) {
+ if (!isClosing) {
+ // Check if we have a Close message
+ if (msg instanceof CloseWebsocketMessage) {
+ isClosing = true;
+ }
+
+ if (isSendingMessage) {
+ // Check if the buffered messages exceed
+ // a specific amount - in that case, disconnect the client
+ // to prevent DoS.
+ // In this case we check if there are >= 1000 messages
+ // or length(of all messages) >= 1000000 bytes.
+ if (messagesToSend.size() >= 1000
+ || messagesToSendLength >= 1000000) {
+ isClosing = true;
+
+ // Discard the new message and close the session immediately.
+ CloseReason cr = new CloseReason(
+ CloseCodes.VIOLATED_POLICY,
+ "Send Buffer exceeded");
+ try {
+ // TODO: close() may block if the remote endpoint doesn't read the data
+ // (eventually there will be a TimeoutException). However, this method
+ // (sendMessage) is intended to run asynchronous code and shouldn't
+ // block. Otherwise it would temporarily stop processing of messages
+ // from other clients.
+ // Maybe call this method on another thread.
+ // Note that when this method is called, the RemoteEndpoint.Async
+ // is still in the process of sending data, so there probably should
+ // be another way to abort the Websocket connection.
+ // Ideally, there should be some abort() method that cancels the
+ // connection immediately...
+ session.close(cr);
+ } catch (IOException e) {
+ // Ignore
+ }
+
+ } else {
+
+ // Check if the last message and the new message are
+ // String messages - in that case we concatenate them
+ // to reduce TCP overhead (using ";" as separator).
+ if (msg instanceof StringWebsocketMessage
+ && !messagesToSend.isEmpty()
+ && messagesToSend.getLast()
+ instanceof StringWebsocketMessage) {
+
+ StringWebsocketMessage ms =
+ (StringWebsocketMessage) messagesToSend.removeLast();
+ messagesToSendLength -= calculateMessageLength(ms);
+
+ String concatenated = ms.getString() + ";" +
+ ((StringWebsocketMessage) msg).getString();
+ msg = new StringWebsocketMessage(concatenated);
+ }
+
+ messagesToSend.add(msg);
+ messagesToSendLength += calculateMessageLength(msg);
+ }
+ } else {
+ isSendingMessage = true;
+ internalSendMessageAsync(msg);
+ }
+ }
+
+ }
+ }
+
+ private long calculateMessageLength(AbstractWebsocketMessage msg) {
+ if (msg instanceof BinaryWebsocketMessage) {
+ return ((BinaryWebsocketMessage) msg).getBytes().capacity();
+ } else if (msg instanceof StringWebsocketMessage) {
+ return ((StringWebsocketMessage) msg).getString().length() * 2;
+ }
+
+ return 0;
+ }
+
+ /**
+ * Internally sends the messages asynchronously.
+ * @param msg
+ */
+ private void internalSendMessageAsync(AbstractWebsocketMessage msg) {
+ try {
+ if (msg instanceof StringWebsocketMessage) {
+ StringWebsocketMessage sMsg = (StringWebsocketMessage) msg;
+ async.sendText(sMsg.getString(), sendHandler);
+
+ } else if (msg instanceof BinaryWebsocketMessage) {
+ BinaryWebsocketMessage bMsg = (BinaryWebsocketMessage) msg;
+ async.sendBinary(bMsg.getBytes(), sendHandler);
+
+ } else if (msg instanceof CloseWebsocketMessage) {
+ // Close the session.
+ session.close();
+ }
+ } catch (IllegalStateException ex) {
+ // Trying to write to the client when the session has
+ // already been closed.
+ // Ignore
+ } catch (IOException ex) {
+ // Trying to write to the client when the session has
+ // already been closed.
+ // Ignore
+ }
+ }
+
+
+
+ /**
+ * SendHandler that will continue to send buffered messages.
+ */
+ private final SendHandler sendHandler = new SendHandler() {
+ @Override
+ public void onResult(SendResult result) {
+ if (!result.isOK()) {
+ // Message could not be sent. In this case, we don't
+ // set isSendingMessage to false because we must assume the connection
+ // broke (and onClose will be called), so we don't try to send
+ // other messages.
+ // As a precaution, we close the session (e.g. if a send timeout occured).
+ // TODO: session.close() blocks, while this handler shouldn't block.
+ // Ideally, there should be some abort() method that cancels the
+ // connection immediately...
+ try {
+ session.close();
+ } catch (IOException ex) {
+ // Ignore
+ }
+ }
+ synchronized (messagesToSend) {
+
+ if (!messagesToSend.isEmpty()) {
+ AbstractWebsocketMessage msg = messagesToSend.remove();
+ messagesToSendLength -= calculateMessageLength(msg);
+
+ internalSendMessageAsync(msg);
+
+ } else {
+ isSendingMessage = false;
+ }
+
+ }
+ }
+ };
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage$ParseException.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage$ParseException.class
new file mode 100644
index 0000000..51943a6
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage$ParseException.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.class
new file mode 100644
index 0000000..f37e237
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
new file mode 100644
index 0000000..c218cc8
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
@@ -0,0 +1,270 @@
+/*
+ * 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 websocket.drawboard;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.geom.Arc2D;
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * A message that represents a drawing action.
+ * Note that we use primitive types instead of Point, Color etc.
+ * to reduce object allocation.<br><br>
+ *
+ * TODO: But a Color objects needs to be created anyway for drawing this
+ * onto a Graphics2D object, so this probably does not save much.
+ */
+public final class DrawMessage {
+
+ private int type;
+ private byte colorR, colorG, colorB, colorA;
+ private double thickness;
+ private double x1, y1, x2, y2;
+ private boolean lastInChain;
+
+ /**
+ * The type.<br>
+ * 1: Brush<br>
+ * 2: Line<br>
+ * 3: Rectangle<br>
+ * 4: Ellipse
+ */
+ public int getType() {
+ return type;
+ }
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public double getThickness() {
+ return thickness;
+ }
+ public void setThickness(double thickness) {
+ this.thickness = thickness;
+ }
+
+ public byte getColorR() {
+ return colorR;
+ }
+ public void setColorR(byte colorR) {
+ this.colorR = colorR;
+ }
+ public byte getColorG() {
+ return colorG;
+ }
+ public void setColorG(byte colorG) {
+ this.colorG = colorG;
+ }
+ public byte getColorB() {
+ return colorB;
+ }
+ public void setColorB(byte colorB) {
+ this.colorB = colorB;
+ }
+ public byte getColorA() {
+ return colorA;
+ }
+ public void setColorA(byte colorA) {
+ this.colorA = colorA;
+ }
+
+ public double getX1() {
+ return x1;
+ }
+ public void setX1(double x1) {
+ this.x1 = x1;
+ }
+ public double getX2() {
+ return x2;
+ }
+ public void setX2(double x2) {
+ this.x2 = x2;
+ }
+ public double getY1() {
+ return y1;
+ }
+ public void setY1(double y1) {
+ this.y1 = y1;
+ }
+ public double getY2() {
+ return y2;
+ }
+ public void setY2(double y2) {
+ this.y2 = y2;
+ }
+
+ /**
+ * Specifies if this DrawMessage is the last one in a chain
+ * (e.g. a chain of brush paths).<br>
+ * Currently it is unused.
+ */
+ public boolean isLastInChain() {
+ return lastInChain;
+ }
+ public void setLastInChain(boolean lastInChain) {
+ this.lastInChain = lastInChain;
+ }
+
+
+
+ public DrawMessage(int type, byte colorR, byte colorG, byte colorB,
+ byte colorA, double thickness, double x1, double x2, double y1,
+ double y2, boolean lastInChain) {
+
+ this.type = type;
+ this.colorR = colorR;
+ this.colorG = colorG;
+ this.colorB = colorB;
+ this.colorA = colorA;
+ this.thickness = thickness;
+ this.x1 = x1;
+ this.x2 = x2;
+ this.y1 = y1;
+ this.y2 = y2;
+ this.lastInChain = lastInChain;
+ }
+
+
+ /**
+ * Draws this DrawMessage onto the given Graphics2D.
+ * @param g
+ */
+ public void draw(Graphics2D g) {
+
+ g.setStroke(new BasicStroke((float) thickness,
+ BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
+ g.setColor(new Color(colorR & 0xFF, colorG & 0xFF, colorB & 0xFF,
+ colorA & 0xFF));
+
+ if (x1 == x2 && y1 == y2) {
+ // Always draw as arc to meet the behavior in the HTML5 Canvas.
+ Arc2D arc = new Arc2D.Double(x1, y1, 0, 0,
+ 0d, 360d, Arc2D.OPEN);
+ g.draw(arc);
+
+ } else if (type == 1 || type == 2) {
+ // Draw a line.
+ Line2D line = new Line2D.Double(x1, y1, x2, y2);
+ g.draw(line);
+
+ } else if (type == 3 || type == 4) {
+ double x1 = this.x1, x2 = this.x2,
+ y1 = this.y1, y2 = this.y2;
+ if (x1 > x2) {
+ x1 = this.x2;
+ x2 = this.x1;
+ }
+ if (y1 > y2) {
+ y1 = this.y2;
+ y2 = this.y1;
+ }
+
+ // TODO: If (x1 == x2 || y1 == y2) draw as line.
+
+ if (type == 3) {
+ // Draw a rectangle.
+ Rectangle2D rect = new Rectangle2D.Double(x1, y1,
+ x2 - x1, y2 - y1);
+ g.draw(rect);
+
+ } else if (type == 4) {
+ // Draw an ellipse.
+ Arc2D arc = new Arc2D.Double(x1, y1, x2 - x1, y2 - y1,
+ 0d, 360d, Arc2D.OPEN);
+ g.draw(arc);
+
+ }
+ }
+ }
+
+ /**
+ * Converts this message into a String representation that
+ * can be sent over WebSocket.<br>
+ * Since a DrawMessage consists only of numbers,
+ * we concatenate those numbers with a ",".
+ */
+ @Override
+ public String toString() {
+
+ return type + "," + (colorR & 0xFF) + "," + (colorG & 0xFF) + ","
+ + (colorB & 0xFF) + "," + (colorA & 0xFF) + "," + thickness
+ + "," + x1 + "," + y1 + "," + x2 + "," + y2 + ","
+ + (lastInChain ? "1" : "0");
+ }
+
+ public static DrawMessage parseFromString(String str)
+ throws ParseException {
+
+ int type;
+ byte[] colors = new byte[4];
+ double thickness;
+ double[] coords = new double[4];
+ boolean last;
+
+ try {
+ String[] elements = str.split(",");
+
+ type = Integer.parseInt(elements[0]);
+ if (!(type >= 1 && type <= 4))
+ throw new ParseException("Invalid type: " + type);
+
+ for (int i = 0; i < colors.length; i++) {
+ colors[i] = (byte) Integer.parseInt(elements[1 + i]);
+ }
+
+ thickness = Double.parseDouble(elements[5]);
+ if (Double.isNaN(thickness) || thickness < 0 || thickness > 100)
+ throw new ParseException("Invalid thickness: " + thickness);
+
+ for (int i = 0; i < coords.length; i++) {
+ coords[i] = Double.parseDouble(elements[6 + i]);
+ if (Double.isNaN(coords[i]))
+ throw new ParseException("Invalid coordinate: "
+ + coords[i]);
+ }
+
+ last = !"0".equals(elements[10]);
+
+ } catch (RuntimeException ex) {
+ throw new ParseException(ex);
+ }
+
+ DrawMessage m = new DrawMessage(type, colors[0], colors[1],
+ colors[2], colors[3], thickness, coords[0], coords[2],
+ coords[1], coords[3], last);
+
+ return m;
+ }
+
+ public static class ParseException extends Exception {
+ private static final long serialVersionUID = -6651972769789842960L;
+
+ public ParseException(Throwable root) {
+ super(root);
+ }
+
+ public ParseException(String message) {
+ super(message);
+ }
+ }
+
+
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.class
new file mode 100644
index 0000000..f6724e6
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java
new file mode 100644
index 0000000..4ba2b38
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardContextListener.java
@@ -0,0 +1,37 @@
+/*
+ * 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 websocket.drawboard;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public final class DrawboardContextListener implements ServletContextListener {
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+ // NO-OP
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ // Shutdown our room.
+ Room room = DrawboardEndpoint.getRoom(false);
+ if (room != null) {
+ room.shutdown();
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$1.class
new file mode 100644
index 0000000..3add6a1
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$2.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$2.class
new file mode 100644
index 0000000..ee2f923
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$2.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$3$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$3$1.class
new file mode 100644
index 0000000..86ff72e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$3$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$3.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$3.class
new file mode 100644
index 0000000..9a9499e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint$3.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.class
new file mode 100644
index 0000000..5f35890
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java
new file mode 100644
index 0000000..75d86f3
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawboardEndpoint.java
@@ -0,0 +1,236 @@
+/*
+ * 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 websocket.drawboard;
+
+import java.io.EOFException;
+import java.io.IOException;
+
+import javax.websocket.CloseReason;
+import javax.websocket.Endpoint;
+import javax.websocket.EndpointConfig;
+import javax.websocket.MessageHandler;
+import javax.websocket.Session;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+import websocket.drawboard.DrawMessage.ParseException;
+import websocket.drawboard.wsmessages.StringWebsocketMessage;
+
+
+public final class DrawboardEndpoint extends Endpoint {
+
+ private static final Log log =
+ LogFactory.getLog(DrawboardEndpoint.class);
+
+
+ /**
+ * Our room where players can join.
+ */
+ private static volatile Room room = null;
+ private static final Object roomLock = new Object();
+
+ public static Room getRoom(boolean create) {
+ if (create) {
+ if (room == null) {
+ synchronized (roomLock) {
+ if (room == null) {
+ room = new Room();
+ }
+ }
+ }
+ return room;
+ } else {
+ return room;
+ }
+ }
+
+ /**
+ * The player that is associated with this Endpoint and the current room.
+ * Note that this variable is only accessed from the Room Thread.<br><br>
+ *
+ * TODO: Currently, Tomcat uses an Endpoint instance once - however
+ * the java doc of endpoint says:
+ * "Each instance of a websocket endpoint is guaranteed not to be called by
+ * more than one thread at a time per active connection."
+ * This could mean that after calling onClose(), the instance
+ * could be reused for another connection so onOpen() will get called
+ * (possibly from another thread).<br>
+ * If this is the case, we would need a variable holder for the variables
+ * that are accessed by the Room thread, and read the reference to the holder
+ * at the beginning of onOpen, onMessage, onClose methods to ensure the room
+ * thread always gets the correct instance of the variable holder.
+ */
+ private Room.Player player;
+
+
+ @Override
+ public void onOpen(Session session, EndpointConfig config) {
+ // Set maximum messages size to 10.000 bytes.
+ session.setMaxTextMessageBufferSize(10000);
+ session.addMessageHandler(stringHandler);
+ final Client client = new Client(session);
+
+ final Room room = getRoom(true);
+ room.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ try {
+
+ // Create a new Player and add it to the room.
+ try {
+ player = room.createAndAddPlayer(client);
+ } catch (IllegalStateException ex) {
+ // Probably the max. number of players has been
+ // reached.
+ client.sendMessage(new StringWebsocketMessage(
+ "0" + ex.getLocalizedMessage()));
+ // Close the connection.
+ client.close();
+ }
+
+ } catch (RuntimeException ex) {
+ log.error("Unexpected exception: " + ex.toString(), ex);
+ }
+ }
+ });
+
+ }
+
+
+ @Override
+ public void onClose(Session session, CloseReason closeReason) {
+ Room room = getRoom(false);
+ if (room != null) {
+ room.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ // Player can be null if it couldn't enter the room
+ if (player != null) {
+ // Remove this player from the room.
+ player.removeFromRoom();
+
+ // Set player to null to prevent NPEs when onMessage events
+ // are processed (from other threads) after onClose has been
+ // called from different thread which closed the Websocket session.
+ player = null;
+ }
+ } catch (RuntimeException ex) {
+ log.error("Unexpected exception: " + ex.toString(), ex);
+ }
+ }
+ });
+ }
+ }
+
+
+
+ @Override
+ public void onError(Session session, Throwable t) {
+ // Most likely cause is a user closing their browser. Check to see if
+ // the root cause is EOF and if it is ignore it.
+ // Protect against infinite loops.
+ int count = 0;
+ Throwable root = t;
+ while (root.getCause() != null && count < 20) {
+ root = root.getCause();
+ count ++;
+ }
+ if (root instanceof EOFException) {
+ // Assume this is triggered by the user closing their browser and
+ // ignore it.
+ } else if (!session.isOpen() && root instanceof IOException) {
+ // IOException after close. Assume this is a variation of the user
+ // closing their browser (or refreshing very quickly) and ignore it.
+ } else {
+ log.error("onError: " + t.toString(), t);
+ }
+ }
+
+
+
+ private final MessageHandler.Whole<String> stringHandler =
+ new MessageHandler.Whole<String>() {
+
+ @Override
+ public void onMessage(final String message) {
+ // Invoke handling of the message in the room.
+ room.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ try {
+
+ // Currently, the only types of messages the client will send
+ // are draw messages prefixed by a Message ID
+ // (starting with char '1'), and pong messages (starting
+ // with char '0').
+ // Draw messages should look like this:
+ // ID|type,colR,colB,colG,colA,thickness,x1,y1,x2,y2,lastInChain
+
+ boolean dontSwallowException = false;
+ try {
+ char messageType = message.charAt(0);
+ String messageContent = message.substring(1);
+ switch (messageType) {
+ case '0':
+ // Pong message.
+ // Do nothing.
+ break;
+
+ case '1':
+ // Draw message
+ int indexOfChar = messageContent.indexOf('|');
+ long msgId = Long.parseLong(
+ messageContent.substring(0, indexOfChar));
+
+ DrawMessage msg = DrawMessage.parseFromString(
+ messageContent.substring(indexOfChar + 1));
+
+ // Don't ignore RuntimeExceptions thrown by
+ // this method
+ // TODO: Find a better solution than this variable
+ dontSwallowException = true;
+ if (player != null) {
+ player.handleDrawMessage(msg, msgId);
+ }
+ dontSwallowException = false;
+
+ break;
+ }
+
+ } catch (RuntimeException ex) {
+ // Client sent invalid data.
+ // Ignore, TODO: maybe close connection
+ if (dontSwallowException) {
+ throw ex;
+ }
+ } catch (ParseException ex) {
+ // Client sent invalid data.
+ // Ignore, TODO: maybe close connection
+ }
+ } catch (RuntimeException ex) {
+ log.error("Unexpected exception: " + ex.toString(), ex);
+ }
+ }
+ });
+
+ }
+ };
+
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$1$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$1$1.class
new file mode 100644
index 0000000..604acea
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$1$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$1.class
new file mode 100644
index 0000000..ba034ac
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$2.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$2.class
new file mode 100644
index 0000000..6ef92d7
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$2.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$MessageType.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$MessageType.class
new file mode 100644
index 0000000..1e5b6bc
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$MessageType.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$Player.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$Player.class
new file mode 100644
index 0000000..bf50834
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room$Player.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.class
new file mode 100644
index 0000000..7c9e605
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
new file mode 100644
index 0000000..9e3b361
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
@@ -0,0 +1,490 @@
+/*
+ * 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 websocket.drawboard;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.imageio.ImageIO;
+
+import websocket.drawboard.wsmessages.BinaryWebsocketMessage;
+import websocket.drawboard.wsmessages.StringWebsocketMessage;
+
+/**
+ * A Room represents a drawboard where a number of
+ * users participate.<br><br>
+ *
+ * Note: Instance methods should only be invoked by calling
+ * {@link #invokeAndWait(Runnable)} to ensure access is correctly synchronized.
+ */
+public final class Room {
+
+ /**
+ * Specifies the type of a room message that is sent to a client.<br>
+ * Note: Currently we are sending simple string messages - for production
+ * apps, a JSON lib should be used for object-level messages.<br><br>
+ *
+ * The number (single char) will be prefixed to the string when sending
+ * the message.
+ */
+ public static enum MessageType {
+ /**
+ * '0': Error: contains error message.
+ */
+ ERROR('0'),
+ /**
+ * '1': DrawMessage: contains serialized DrawMessage(s) prefixed
+ * with the current Player's {@link Player#lastReceivedMessageId}
+ * and ",".<br>
+ * Multiple draw messages are concatenated with "|" as separator.
+ */
+ DRAW_MESSAGE('1'),
+ /**
+ * '2': ImageMessage: Contains number of current players in this room.
+ * After this message a Binary Websocket message will follow,
+ * containing the current Room image as PNG.<br>
+ * This is the first message that a Room sends to a new Player.
+ */
+ IMAGE_MESSAGE('2'),
+ /**
+ * '3': PlayerChanged: contains "+" or "-" which indicate a player
+ * was added or removed to this Room.
+ */
+ PLAYER_CHANGED('3');
+
+ private final char flag;
+
+ private MessageType(char flag) {
+ this.flag = flag;
+ }
+
+ }
+
+
+ /**
+ * The lock used to synchronize access to this Room.
+ */
+ private final ReentrantLock roomLock = new ReentrantLock();
+
+ /**
+ * Indicates if this room has already been shutdown.
+ */
+ private volatile boolean closed = false;
+
+ /**
+ * If <code>true</code>, outgoing DrawMessages will be buffered until the
+ * drawmessageBroadcastTimer ticks. Otherwise they will be sent
+ * immediately.
+ */
+ private static final boolean BUFFER_DRAW_MESSAGES = true;
+
+ /**
+ * A timer which sends buffered drawmessages to the client at once
+ * at a regular interval, to avoid sending a lot of very small
+ * messages which would cause TCP overhead and high CPU usage.
+ */
+ private final Timer drawmessageBroadcastTimer = new Timer();
+
+ private static final int TIMER_DELAY = 30;
+
+ /**
+ * The current active broadcast timer task. If null, then no Broadcast task is scheduled.
+ * The Task will be scheduled if the first player enters the Room, and
+ * cancelled if the last player exits the Room, to avoid unnecessary timer executions.
+ */
+ private TimerTask activeBroadcastTimerTask;
+
+
+ /**
+ * The current image of the room drawboard. DrawMessages that are
+ * received from Players will be drawn onto this image.
+ */
+ private final BufferedImage roomImage =
+ new BufferedImage(900, 600, BufferedImage.TYPE_INT_RGB);
+ private final Graphics2D roomGraphics = roomImage.createGraphics();
+
+
+ /**
+ * The maximum number of players that can join this room.
+ */
+ private static final int MAX_PLAYER_COUNT = 100;
+
+ /**
+ * List of all currently joined players.
+ */
+ private final List<Player> players = new ArrayList<Player>();
+
+
+
+ public Room() {
+ roomGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // Clear the image with white background.
+ roomGraphics.setBackground(Color.WHITE);
+ roomGraphics.clearRect(0, 0, roomImage.getWidth(),
+ roomImage.getHeight());
+ }
+
+ private TimerTask createBroadcastTimerTask() {
+ return new TimerTask() {
+ @Override
+ public void run() {
+ invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ broadcastTimerTick();
+ }
+ });
+ }
+ };
+ }
+
+ /**
+ * Creates a Player from the given Client and adds it to this room.
+ * @param client the client
+ */
+ public Player createAndAddPlayer(Client client) {
+ if (players.size() >= MAX_PLAYER_COUNT) {
+ throw new IllegalStateException("Maximum player count ("
+ + MAX_PLAYER_COUNT + ") has been reached.");
+ }
+
+ Player p = new Player(this, client);
+
+ // Broadcast to the other players that one player joined.
+ broadcastRoomMessage(MessageType.PLAYER_CHANGED, "+");
+
+ // Add the new player to the list.
+ players.add(p);
+
+ // If currently no Broadcast Timer Task is scheduled, then we need to create one.
+ if (activeBroadcastTimerTask == null) {
+ activeBroadcastTimerTask = createBroadcastTimerTask();
+ drawmessageBroadcastTimer.schedule(activeBroadcastTimerTask,
+ TIMER_DELAY, TIMER_DELAY);
+ }
+
+ // Send him the current number of players and the current room image.
+ String content = String.valueOf(players.size());
+ p.sendRoomMessage(MessageType.IMAGE_MESSAGE, content);
+
+ // Store image as PNG
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ try {
+ ImageIO.write(roomImage, "PNG", bout);
+ } catch (IOException e) { /* Should never happen */ }
+
+
+ // Send the image as binary message.
+ BinaryWebsocketMessage msg = new BinaryWebsocketMessage(
+ ByteBuffer.wrap(bout.toByteArray()));
+ p.getClient().sendMessage(msg);
+
+ return p;
+
+ }
+
+ /**
+ * @see Player#removeFromRoom()
+ * @param p
+ */
+ private void internalRemovePlayer(Player p) {
+ boolean removed = players.remove(p);
+ assert removed;
+
+ // If the last player left the Room, we need to cancel the Broadcast Timer Task.
+ if (players.size() == 0) {
+ // Cancel the task.
+ // Note that it can happen that the TimerTask is just about to execute (from
+ // the Timer thread) but waits until all players are gone (or even until a new
+ // player is added to the list), and then executes. This is OK. To prevent it,
+ // a TimerTask subclass would need to have some boolean "cancel" instance variable and
+ // query it in the invocation of Room#invokeAndWait.
+ activeBroadcastTimerTask.cancel();
+ activeBroadcastTimerTask = null;
+ }
+
+ // Broadcast that one player is removed.
+ broadcastRoomMessage(MessageType.PLAYER_CHANGED, "-");
+ }
+
+ /**
+ * @see Player#handleDrawMessage(DrawMessage, long)
+ * @param p
+ * @param msg
+ * @param msgId
+ */
+ private void internalHandleDrawMessage(Player p, DrawMessage msg,
+ long msgId) {
+ p.setLastReceivedMessageId(msgId);
+
+ // Draw the RoomMessage onto our Room Image.
+ msg.draw(roomGraphics);
+
+ // Broadcast the Draw Message.
+ broadcastDrawMessage(msg);
+ }
+
+
+ /**
+ * Broadcasts the given drawboard message to all connected players.<br>
+ * Note: For DrawMessages, please use
+ * {@link #broadcastDrawMessage(DrawMessage)}
+ * as this method will buffer them and prefix them with the correct
+ * last received Message ID.
+ * @param type
+ * @param content
+ */
+ private void broadcastRoomMessage(MessageType type, String content) {
+ for (Player p : players) {
+ p.sendRoomMessage(type, content);
+ }
+ }
+
+
+ /**
+ * Broadcast the given DrawMessage. This will buffer the message
+ * and the {@link #drawmessageBroadcastTimer} will broadcast them
+ * at a regular interval, prefixing them with the player's current
+ * {@link Player#lastReceivedMessageId}.
+ * @param msg
+ */
+ private void broadcastDrawMessage(DrawMessage msg) {
+ if (!BUFFER_DRAW_MESSAGES) {
+ String msgStr = msg.toString();
+
+ for (Player p : players) {
+ String s = String.valueOf(p.getLastReceivedMessageId())
+ + "," + msgStr;
+ p.sendRoomMessage(MessageType.DRAW_MESSAGE, s);
+ }
+ } else {
+ for (Player p : players) {
+ p.getBufferedDrawMessages().add(msg);
+ }
+ }
+ }
+
+
+ /**
+ * Tick handler for the broadcastTimer.
+ */
+ private void broadcastTimerTick() {
+ // For each Player, send all per Player buffered
+ // DrawMessages, prefixing each DrawMessage with the player's
+ // lastReceivedMessageId.
+ // Multiple messages are concatenated with "|".
+
+ for (Player p : players) {
+
+ StringBuilder sb = new StringBuilder();
+ List<DrawMessage> drawMessages = p.getBufferedDrawMessages();
+
+ if (drawMessages.size() > 0) {
+ for (int i = 0; i < drawMessages.size(); i++) {
+ DrawMessage msg = drawMessages.get(i);
+
+ String s = String.valueOf(p.getLastReceivedMessageId())
+ + "," + msg.toString();
+ if (i > 0)
+ sb.append("|");
+
+ sb.append(s);
+ }
+ drawMessages.clear();
+
+ p.sendRoomMessage(MessageType.DRAW_MESSAGE, sb.toString());
+ }
+ }
+ }
+
+ /**
+ * A list of cached {@link Runnable}s to prevent recursive invocation of Runnables
+ * by one thread. This variable is only used by one thread at a time and then
+ * set to <code>null</code>.
+ */
+ private List<Runnable> cachedRunnables = null;
+
+ /**
+ * Submits the given Runnable to the Room Executor and waits until it
+ * has been executed. Currently, this simply means that the Runnable
+ * will be run directly inside of a synchronized() block.<br>
+ * Note that if a runnable recursively calls invokeAndWait() with another
+ * runnable on this Room, it will not be executed recursively, but instead
+ * cached until the original runnable is finished, to keep the behavior of
+ * using a Executor.
+ * @param task
+ */
+ public void invokeAndWait(Runnable task) {
+
+ // Check if the current thread already holds a lock on this room.
+ // If yes, then we must not directly execute the Runnable but instead
+ // cache it until the original invokeAndWait() has finished.
+ if (roomLock.isHeldByCurrentThread()) {
+
+ if (cachedRunnables == null) {
+ cachedRunnables = new ArrayList<Runnable>();
+ }
+ cachedRunnables.add(task);
+
+ } else {
+
+ roomLock.lock();
+ try {
+ // Explicitly overwrite value to ensure data consistency in
+ // current thread
+ cachedRunnables = null;
+
+ if (!closed) {
+ task.run();
+ }
+
+ // Run the cached runnables.
+ if (cachedRunnables != null) {
+ for (int i = 0; i < cachedRunnables.size(); i++) {
+ if (!closed) {
+ cachedRunnables.get(i).run();
+ }
+ }
+ cachedRunnables = null;
+ }
+
+ } finally {
+ roomLock.unlock();
+ }
+
+ }
+
+ }
+
+ /**
+ * Shuts down the roomExecutor and the drawmessageBroadcastTimer.
+ */
+ public void shutdown() {
+ invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ closed = true;
+ drawmessageBroadcastTimer.cancel();
+ roomGraphics.dispose();
+ }
+ });
+ }
+
+
+ /**
+ * A Player participates in a Room. It is the interface between the
+ * {@link Room} and the {@link Client}.<br><br>
+ *
+ * Note: This means a player object is actually a join between Room and
+ * Client.
+ */
+ public final class Player {
+
+ /**
+ * The room to which this player belongs.
+ */
+ private Room room;
+
+ /**
+ * The room buffers the last draw message ID that was received from
+ * this player.
+ */
+ private long lastReceivedMessageId = 0;
+
+ private final Client client;
+
+ /**
+ * Buffered DrawMessages that will be sent by a Timer.
+ */
+ private final List<DrawMessage> bufferedDrawMessages =
+ new ArrayList<DrawMessage>();
+
+ private List<DrawMessage> getBufferedDrawMessages() {
+ return bufferedDrawMessages;
+ }
+
+ private Player(Room room, Client client) {
+ this.room = room;
+ this.client = client;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public Client getClient() {
+ return client;
+ }
+
+ /**
+ * Removes this player from its room, e.g. when
+ * the client disconnects.
+ */
+ public void removeFromRoom() {
+ if (room != null) {
+ room.internalRemovePlayer(this);
+ room = null;
+ }
+ }
+
+
+ private long getLastReceivedMessageId() {
+ return lastReceivedMessageId;
+ }
+ private void setLastReceivedMessageId(long value) {
+ lastReceivedMessageId = value;
+ }
+
+
+ /**
+ * Handles the given DrawMessage by drawing it onto this Room's
+ * image and by broadcasting it to the connected players.
+ * @param msg
+ * @param msgId
+ */
+ public void handleDrawMessage(DrawMessage msg, long msgId) {
+ room.internalHandleDrawMessage(this, msg, msgId);
+ }
+
+
+ /**
+ * Sends the given room message.
+ * @param type
+ * @param content
+ */
+ private void sendRoomMessage(MessageType type, String content) {
+ if (content == null || type == null)
+ throw new NullPointerException();
+
+ String completeMsg = String.valueOf(type.flag) + content;
+
+ client.sendMessage(new StringWebsocketMessage(completeMsg));
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/AbstractWebsocketMessage.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/AbstractWebsocketMessage.class
new file mode 100644
index 0000000..3f4846b
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/AbstractWebsocketMessage.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/AbstractWebsocketMessage.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/AbstractWebsocketMessage.java
new file mode 100644
index 0000000..b1945fc
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/AbstractWebsocketMessage.java
@@ -0,0 +1,25 @@
+/*
+ * 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 websocket.drawboard.wsmessages;
+
+/**
+ * Abstract base class for Websocket Messages (binary or string)
+ * that can be buffered.
+ */
+public abstract class AbstractWebsocketMessage {
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/BinaryWebsocketMessage.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/BinaryWebsocketMessage.class
new file mode 100644
index 0000000..fe5a3f4
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/BinaryWebsocketMessage.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/BinaryWebsocketMessage.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/BinaryWebsocketMessage.java
new file mode 100644
index 0000000..0a28f64
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/BinaryWebsocketMessage.java
@@ -0,0 +1,34 @@
+/*
+ * 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 websocket.drawboard.wsmessages;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Represents a binary websocket message.
+ */
+public final class BinaryWebsocketMessage extends AbstractWebsocketMessage {
+ private final ByteBuffer bytes;
+
+ public BinaryWebsocketMessage(ByteBuffer bytes) {
+ this.bytes = bytes;
+ }
+
+ public ByteBuffer getBytes() {
+ return bytes;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/CloseWebsocketMessage.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/CloseWebsocketMessage.class
new file mode 100644
index 0000000..bad57e0
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/CloseWebsocketMessage.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/CloseWebsocketMessage.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/CloseWebsocketMessage.java
new file mode 100644
index 0000000..898117f
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/CloseWebsocketMessage.java
@@ -0,0 +1,24 @@
+/*
+ * 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 websocket.drawboard.wsmessages;
+
+/**
+ * Represents a "close" message that closes the session.
+ */
+public class CloseWebsocketMessage extends AbstractWebsocketMessage {
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/StringWebsocketMessage.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/StringWebsocketMessage.class
new file mode 100644
index 0000000..acf3928
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/StringWebsocketMessage.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/StringWebsocketMessage.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/StringWebsocketMessage.java
new file mode 100644
index 0000000..8646ea7
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/drawboard/wsmessages/StringWebsocketMessage.java
@@ -0,0 +1,34 @@
+/*
+ * 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 websocket.drawboard.wsmessages;
+
+/**
+ * Represents a string websocket message.
+ *
+ */
+public final class StringWebsocketMessage extends AbstractWebsocketMessage {
+ private final String string;
+
+ public StringWebsocketMessage(String string) {
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.class
new file mode 100644
index 0000000..8c03f33
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
new file mode 100644
index 0000000..b592153
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
@@ -0,0 +1,70 @@
+/*
+ * 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 websocket.echo;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import javax.websocket.OnMessage;
+import javax.websocket.PongMessage;
+import javax.websocket.Session;
+import javax.websocket.server.ServerEndpoint;
+
+@ServerEndpoint("/websocket/echoAnnotation")
+public class EchoAnnotation {
+
+ @OnMessage
+ public void echoTextMessage(Session session, String msg, boolean last) {
+ try {
+ if (session.isOpen()) {
+ session.getBasicRemote().sendText(msg, last);
+ }
+ } catch (IOException e) {
+ try {
+ session.close();
+ } catch (IOException e1) {
+ // Ignore
+ }
+ }
+ }
+
+ @OnMessage
+ public void echoBinaryMessage(Session session, ByteBuffer bb,
+ boolean last) {
+ try {
+ if (session.isOpen()) {
+ session.getBasicRemote().sendBinary(bb, last);
+ }
+ } catch (IOException e) {
+ try {
+ session.close();
+ } catch (IOException e1) {
+ // Ignore
+ }
+ }
+ }
+
+ /**
+ * Process a received pong. This is a NO-OP.
+ *
+ * @param pm Ignored.
+ */
+ @OnMessage
+ public void echoPongMessage(PongMessage pm) {
+ // NO-OP
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$1.class
new file mode 100644
index 0000000..18684e5
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$EchoMessageHandlerBinary.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$EchoMessageHandlerBinary.class
new file mode 100644
index 0000000..62bf22d
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$EchoMessageHandlerBinary.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$EchoMessageHandlerText.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$EchoMessageHandlerText.class
new file mode 100644
index 0000000..c7ca81c
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint$EchoMessageHandlerText.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.class
new file mode 100644
index 0000000..4a304db
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
new file mode 100644
index 0000000..d503994
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
@@ -0,0 +1,80 @@
+/*
+ * 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 websocket.echo;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import javax.websocket.Endpoint;
+import javax.websocket.EndpointConfig;
+import javax.websocket.MessageHandler;
+import javax.websocket.RemoteEndpoint;
+import javax.websocket.Session;
+
+public class EchoEndpoint extends Endpoint {
+
+ @Override
+ public void onOpen(Session session, EndpointConfig endpointConfig) {
+ RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
+ session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
+ session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
+ }
+
+ private static class EchoMessageHandlerText
+ implements MessageHandler.Partial<String> {
+
+ private final RemoteEndpoint.Basic remoteEndpointBasic;
+
+ private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) {
+ this.remoteEndpointBasic = remoteEndpointBasic;
+ }
+
+ @Override
+ public void onMessage(String message, boolean last) {
+ try {
+ if (remoteEndpointBasic != null) {
+ remoteEndpointBasic.sendText(message, last);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static class EchoMessageHandlerBinary
+ implements MessageHandler.Partial<ByteBuffer> {
+
+ private final RemoteEndpoint.Basic remoteEndpointBasic;
+
+ private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) {
+ this.remoteEndpointBasic = remoteEndpointBasic;
+ }
+
+ @Override
+ public void onMessage(ByteBuffer message, boolean last) {
+ try {
+ if (remoteEndpointBasic != null) {
+ remoteEndpointBasic.sendBinary(message, last);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Direction.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Direction.class
new file mode 100644
index 0000000..b6f4494
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Direction.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Direction.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Direction.java
new file mode 100644
index 0000000..b36c7a2
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Direction.java
@@ -0,0 +1,21 @@
+/*
+ * 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 websocket.snake;
+
+public enum Direction {
+ NONE, NORTH, SOUTH, EAST, WEST
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location$1.class
new file mode 100644
index 0000000..2b42186
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location.class
new file mode 100644
index 0000000..e9db638
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location.java
new file mode 100644
index 0000000..d5c0007
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Location.java
@@ -0,0 +1,65 @@
+/*
+ * 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 websocket.snake;
+
+public class Location {
+
+ public int x;
+ public int y;
+
+ public Location(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public Location getAdjacentLocation(Direction direction) {
+ switch (direction) {
+ case NORTH:
+ return new Location(x, y - SnakeAnnotation.GRID_SIZE);
+ case SOUTH:
+ return new Location(x, y + SnakeAnnotation.GRID_SIZE);
+ case EAST:
+ return new Location(x + SnakeAnnotation.GRID_SIZE, y);
+ case WEST:
+ return new Location(x - SnakeAnnotation.GRID_SIZE, y);
+ case NONE:
+ // fall through
+ default:
+ return this;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Location location = (Location) o;
+
+ if (x != location.x) return false;
+ if (y != location.y) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = x;
+ result = 31 * result + y;
+ return result;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Snake.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Snake.class
new file mode 100644
index 0000000..1449f3c
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Snake.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java
new file mode 100644
index 0000000..f2c9c4c
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java
@@ -0,0 +1,150 @@
+/*
+ * 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 websocket.snake;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Deque;
+
+import javax.websocket.CloseReason;
+import javax.websocket.CloseReason.CloseCodes;
+import javax.websocket.Session;
+
+public class Snake {
+
+ private static final int DEFAULT_LENGTH = 5;
+
+ private final int id;
+ private final Session session;
+
+ private Direction direction;
+ private int length = DEFAULT_LENGTH;
+ private Location head;
+ private final Deque<Location> tail = new ArrayDeque<Location>();
+ private final String hexColor;
+
+ public Snake(int id, Session session) {
+ this.id = id;
+ this.session = session;
+ this.hexColor = SnakeAnnotation.getRandomHexColor();
+ resetState();
+ }
+
+ private void resetState() {
+ this.direction = Direction.NONE;
+ this.head = SnakeAnnotation.getRandomLocation();
+ this.tail.clear();
+ this.length = DEFAULT_LENGTH;
+ }
+
+ private synchronized void kill() {
+ resetState();
+ sendMessage("{'type': 'dead'}");
+ }
+
+ private synchronized void reward() {
+ length++;
+ sendMessage("{'type': 'kill'}");
+ }
+
+
+ protected void sendMessage(String msg) {
+ try {
+ session.getBasicRemote().sendText(msg);
+ } catch (IOException ioe) {
+ CloseReason cr =
+ new CloseReason(CloseCodes.CLOSED_ABNORMALLY, ioe.getMessage());
+ try {
+ session.close(cr);
+ } catch (IOException ioe2) {
+ // Ignore
+ }
+ }
+ }
+
+ public synchronized void update(Collection<Snake> snakes) {
+ Location nextLocation = head.getAdjacentLocation(direction);
+ if (nextLocation.x >= SnakeAnnotation.PLAYFIELD_WIDTH) {
+ nextLocation.x = 0;
+ }
+ if (nextLocation.y >= SnakeAnnotation.PLAYFIELD_HEIGHT) {
+ nextLocation.y = 0;
+ }
+ if (nextLocation.x < 0) {
+ nextLocation.x = SnakeAnnotation.PLAYFIELD_WIDTH;
+ }
+ if (nextLocation.y < 0) {
+ nextLocation.y = SnakeAnnotation.PLAYFIELD_HEIGHT;
+ }
+ if (direction != Direction.NONE) {
+ tail.addFirst(head);
+ if (tail.size() > length) {
+ tail.removeLast();
+ }
+ head = nextLocation;
+ }
+
+ handleCollisions(snakes);
+ }
+
+ private void handleCollisions(Collection<Snake> snakes) {
+ for (Snake snake : snakes) {
+ boolean headCollision = id != snake.id && snake.getHead().equals(head);
+ boolean tailCollision = snake.getTail().contains(head);
+ if (headCollision || tailCollision) {
+ kill();
+ if (id != snake.id) {
+ snake.reward();
+ }
+ }
+ }
+ }
+
+ public synchronized Location getHead() {
+ return head;
+ }
+
+ public synchronized Collection<Location> getTail() {
+ return tail;
+ }
+
+ public synchronized void setDirection(Direction direction) {
+ this.direction = direction;
+ }
+
+ public synchronized String getLocationsJson() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(String.format("{x: %d, y: %d}",
+ Integer.valueOf(head.x), Integer.valueOf(head.y)));
+ for (Location location : tail) {
+ sb.append(',');
+ sb.append(String.format("{x: %d, y: %d}",
+ Integer.valueOf(location.x), Integer.valueOf(location.y)));
+ }
+ return String.format("{'id':%d,'body':[%s]}",
+ Integer.valueOf(id), sb.toString());
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getHexColor() {
+ return hexColor;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.class
new file mode 100644
index 0000000..57b9447
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
new file mode 100644
index 0000000..519a304
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
@@ -0,0 +1,135 @@
+/*
+ * 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 websocket.snake;
+
+import java.awt.Color;
+import java.io.EOFException;
+import java.util.Iterator;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.websocket.OnClose;
+import javax.websocket.OnError;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.ServerEndpoint;
+
+@ServerEndpoint(value = "/websocket/snake")
+public class SnakeAnnotation {
+
+ public static final int PLAYFIELD_WIDTH = 640;
+ public static final int PLAYFIELD_HEIGHT = 480;
+ public static final int GRID_SIZE = 10;
+
+ private static final AtomicInteger snakeIds = new AtomicInteger(0);
+ private static final Random random = new Random();
+
+
+ private final int id;
+ private Snake snake;
+
+ public static String getRandomHexColor() {
+ float hue = random.nextFloat();
+ // sat between 0.1 and 0.3
+ float saturation = (random.nextInt(2000) + 1000) / 10000f;
+ float luminance = 0.9f;
+ Color color = Color.getHSBColor(hue, saturation, luminance);
+ return '#' + Integer.toHexString(
+ (color.getRGB() & 0xffffff) | 0x1000000).substring(1);
+ }
+
+
+ public static Location getRandomLocation() {
+ int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH));
+ int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT));
+ return new Location(x, y);
+ }
+
+
+ private static int roundByGridSize(int value) {
+ value = value + (GRID_SIZE / 2);
+ value = value / GRID_SIZE;
+ value = value * GRID_SIZE;
+ return value;
+ }
+
+ public SnakeAnnotation() {
+ this.id = snakeIds.getAndIncrement();
+ }
+
+
+ @OnOpen
+ public void onOpen(Session session) {
+ this.snake = new Snake(id, session);
+ SnakeTimer.addSnake(snake);
+ StringBuilder sb = new StringBuilder();
+ for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator();
+ iterator.hasNext();) {
+ Snake snake = iterator.next();
+ sb.append(String.format("{id: %d, color: '%s'}",
+ Integer.valueOf(snake.getId()), snake.getHexColor()));
+ if (iterator.hasNext()) {
+ sb.append(',');
+ }
+ }
+ SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}",
+ sb.toString()));
+ }
+
+
+ @OnMessage
+ public void onTextMessage(String message) {
+ if ("west".equals(message)) {
+ snake.setDirection(Direction.WEST);
+ } else if ("north".equals(message)) {
+ snake.setDirection(Direction.NORTH);
+ } else if ("east".equals(message)) {
+ snake.setDirection(Direction.EAST);
+ } else if ("south".equals(message)) {
+ snake.setDirection(Direction.SOUTH);
+ }
+ }
+
+
+ @OnClose
+ public void onClose() {
+ SnakeTimer.removeSnake(snake);
+ SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}",
+ Integer.valueOf(id)));
+ }
+
+
+ @OnError
+ public void onError(Throwable t) throws Throwable {
+ // Most likely cause is a user closing their browser. Check to see if
+ // the root cause is EOF and if it is ignore it.
+ // Protect against infinite loops.
+ int count = 0;
+ Throwable root = t;
+ while (root.getCause() != null && count < 20) {
+ root = root.getCause();
+ count ++;
+ }
+ if (root instanceof EOFException) {
+ // Assume this is triggered by the user closing their browser and
+ // ignore it.
+ } else {
+ throw t;
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer$1.class
new file mode 100644
index 0000000..1fb6005
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer.class
new file mode 100644
index 0000000..14693fc
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer.java
new file mode 100644
index 0000000..abc4991
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/snake/SnakeTimer.java
@@ -0,0 +1,115 @@
+/*
+ * 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 websocket.snake;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ * Sets up the timer for the multi-player snake game WebSocket example.
+ */
+public class SnakeTimer {
+
+ private static final Log log =
+ LogFactory.getLog(SnakeTimer.class);
+
+ private static Timer gameTimer = null;
+
+ private static final long TICK_DELAY = 100;
+
+ private static final ConcurrentHashMap<Integer, Snake> snakes =
+ new ConcurrentHashMap<Integer, Snake>();
+
+ protected static synchronized void addSnake(Snake snake) {
+ if (snakes.size() == 0) {
+ startTimer();
+ }
+ snakes.put(Integer.valueOf(snake.getId()), snake);
+ }
+
+
+ protected static Collection<Snake> getSnakes() {
+ return Collections.unmodifiableCollection(snakes.values());
+ }
+
+
+ protected static synchronized void removeSnake(Snake snake) {
+ snakes.remove(Integer.valueOf(snake.getId()));
+ if (snakes.size() == 0) {
+ stopTimer();
+ }
+ }
+
+
+ protected static void tick() {
+ StringBuilder sb = new StringBuilder();
+ for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator();
+ iterator.hasNext();) {
+ Snake snake = iterator.next();
+ snake.update(SnakeTimer.getSnakes());
+ sb.append(snake.getLocationsJson());
+ if (iterator.hasNext()) {
+ sb.append(',');
+ }
+ }
+ broadcast(String.format("{'type': 'update', 'data' : [%s]}",
+ sb.toString()));
+ }
+
+ protected static void broadcast(String message) {
+ for (Snake snake : SnakeTimer.getSnakes()) {
+ try {
+ snake.sendMessage(message);
+ } catch (IllegalStateException ise) {
+ // An ISE can occur if an attempt is made to write to a
+ // WebSocket connection after it has been closed. The
+ // alternative to catching this exception is to synchronise
+ // the writes to the clients along with the addSnake() and
+ // removeSnake() methods that are already synchronised.
+ }
+ }
+ }
+
+
+ public static void startTimer() {
+ gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer");
+ gameTimer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ tick();
+ } catch (RuntimeException e) {
+ log.error("Caught to prevent timer from shutting down", e);
+ }
+ }
+ }, TICK_DELAY, TICK_DELAY);
+ }
+
+
+ public static void stopTimer() {
+ if (gameTimer != null) {
+ gameTimer.cancel();
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet$1.class
new file mode 100644
index 0000000..9bbb179
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet$ChatMessageInbound.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet$ChatMessageInbound.class
new file mode 100644
index 0000000..3eecb9e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet$ChatMessageInbound.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet.class
new file mode 100644
index 0000000..edf666f
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet.java
new file mode 100644
index 0000000..12d5419
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/chat/ChatWebSocketServlet.java
@@ -0,0 +1,105 @@
+/*
+ * 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 websocket.tc7.chat;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.catalina.websocket.MessageInbound;
+import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.WebSocketServlet;
+import org.apache.catalina.websocket.WsOutbound;
+
+import util.HTMLFilter;
+
+/**
+ * Example web socket servlet for chat.
+ * @deprecated See {@link websocket.chat.ChatAnnotation}
+ */
+@Deprecated
+public class ChatWebSocketServlet extends WebSocketServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String GUEST_PREFIX = "Guest";
+
+ private final AtomicInteger connectionIds = new AtomicInteger(0);
+ private final Set<ChatMessageInbound> connections =
+ new CopyOnWriteArraySet<ChatMessageInbound>();
+
+ @Override
+ protected StreamInbound createWebSocketInbound(String subProtocol,
+ HttpServletRequest request) {
+ return new ChatMessageInbound(connectionIds.incrementAndGet());
+ }
+
+ private final class ChatMessageInbound extends MessageInbound {
+
+ private final String nickname;
+
+ private ChatMessageInbound(int id) {
+ this.nickname = GUEST_PREFIX + id;
+ }
+
+ @Override
+ protected void onOpen(WsOutbound outbound) {
+ connections.add(this);
+ String message = String.format("* %s %s",
+ nickname, "has joined.");
+ broadcast(message);
+ }
+
+ @Override
+ protected void onClose(int status) {
+ connections.remove(this);
+ String message = String.format("* %s %s",
+ nickname, "has disconnected.");
+ broadcast(message);
+ }
+
+ @Override
+ protected void onBinaryMessage(ByteBuffer message) throws IOException {
+ throw new UnsupportedOperationException(
+ "Binary message not supported.");
+ }
+
+ @Override
+ protected void onTextMessage(CharBuffer message) throws IOException {
+ // Never trust the client
+ String filteredMessage = String.format("%s: %s",
+ nickname, HTMLFilter.filter(message.toString()));
+ broadcast(filteredMessage);
+ }
+
+ private void broadcast(String message) {
+ for (ChatMessageInbound connection : connections) {
+ try {
+ CharBuffer buffer = CharBuffer.wrap(message);
+ connection.getWsOutbound().writeTextMessage(buffer);
+ } catch (IOException ignore) {
+ // Ignore
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage$EchoMessageInbound.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage$EchoMessageInbound.class
new file mode 100644
index 0000000..ddb9dc4
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage$EchoMessageInbound.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage.class
new file mode 100644
index 0000000..d600882
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage.java
new file mode 100644
index 0000000..4073306
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoMessage.java
@@ -0,0 +1,88 @@
+/*
+ * 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 websocket.tc7.echo;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.catalina.websocket.MessageInbound;
+import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.WebSocketServlet;
+/**
+ * @deprecated See {@link websocket.echo.EchoAnnotation}
+ */
+@Deprecated
+public class EchoMessage extends WebSocketServlet {
+
+ private static final long serialVersionUID = 1L;
+ private volatile int byteBufSize;
+ private volatile int charBufSize;
+
+ @Override
+ public void init() throws ServletException {
+ super.init();
+ byteBufSize = getInitParameterIntValue("byteBufferMaxSize", 2097152);
+ charBufSize = getInitParameterIntValue("charBufferMaxSize", 2097152);
+ }
+
+ public int getInitParameterIntValue(String name, int defaultValue) {
+ String val = this.getInitParameter(name);
+ int result;
+ if(null != val) {
+ try {
+ result = Integer.parseInt(val);
+ }catch (Exception x) {
+ result = defaultValue;
+ }
+ } else {
+ result = defaultValue;
+ }
+
+ return result;
+ }
+
+
+
+ @Override
+ protected StreamInbound createWebSocketInbound(String subProtocol,
+ HttpServletRequest request) {
+ return new EchoMessageInbound(byteBufSize,charBufSize);
+ }
+
+ private static final class EchoMessageInbound extends MessageInbound {
+
+ public EchoMessageInbound(int byteBufferMaxSize, int charBufferMaxSize) {
+ super();
+ setByteBufferMaxSize(byteBufferMaxSize);
+ setCharBufferMaxSize(charBufferMaxSize);
+ }
+
+ @Override
+ protected void onBinaryMessage(ByteBuffer message) throws IOException {
+ getWsOutbound().writeBinaryMessage(message);
+ }
+
+ @Override
+ protected void onTextMessage(CharBuffer message) throws IOException {
+ getWsOutbound().writeTextMessage(message);
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream$1.class
new file mode 100644
index 0000000..b770d79
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream$EchoStreamInbound.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream$EchoStreamInbound.class
new file mode 100644
index 0000000..478607d
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream$EchoStreamInbound.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream.class
new file mode 100644
index 0000000..f3d819d
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream.java
new file mode 100644
index 0000000..9b34302
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/echo/EchoStream.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package websocket.tc7.echo;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.WebSocketServlet;
+import org.apache.catalina.websocket.WsOutbound;
+
+/**
+ * @deprecated See {@link websocket.echo.EchoAnnotation}
+ */
+@Deprecated
+public class EchoStream extends WebSocketServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected StreamInbound createWebSocketInbound(String subProtocol,
+ HttpServletRequest request) {
+ return new EchoStreamInbound();
+ }
+
+ private static final class EchoStreamInbound extends StreamInbound {
+
+ @Override
+ protected void onBinaryData(InputStream is) throws IOException {
+ // Simply echo the data to back to the client.
+ WsOutbound outbound = getWsOutbound();
+
+ int i = is.read();
+ while (i != -1) {
+ outbound.writeBinaryData(i);
+ i = is.read();
+ }
+
+ outbound.flush();
+ }
+
+ @Override
+ protected void onTextData(Reader r) throws IOException {
+ // Simply echo the data to back to the client.
+ WsOutbound outbound = getWsOutbound();
+
+ int c = r.read();
+ while (c != -1) {
+ outbound.writeTextData((char) c);
+ c = r.read();
+ }
+
+ outbound.flush();
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Direction.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Direction.class
new file mode 100644
index 0000000..7db9c55
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Direction.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Direction.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Direction.java
new file mode 100644
index 0000000..4e375e7
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Direction.java
@@ -0,0 +1,25 @@
+/*
+ * 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 websocket.tc7.snake;
+
+/**
+ * @deprecated See {@link websocket.snake.Direction}
+ */
+@Deprecated
+public enum Direction {
+ NONE, NORTH, SOUTH, EAST, WEST
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location$1.class
new file mode 100644
index 0000000..7e71c10
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location.class
new file mode 100644
index 0000000..b052a15
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location.java
new file mode 100644
index 0000000..257752e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Location.java
@@ -0,0 +1,69 @@
+/*
+ * 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 websocket.tc7.snake;
+
+/**
+ * @deprecated See {@link websocket.snake.Location}
+ */
+@Deprecated
+public class Location {
+
+ public int x;
+ public int y;
+
+ public Location(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public Location getAdjacentLocation(Direction direction) {
+ switch (direction) {
+ case NORTH:
+ return new Location(x, y - SnakeWebSocketServlet.GRID_SIZE);
+ case SOUTH:
+ return new Location(x, y + SnakeWebSocketServlet.GRID_SIZE);
+ case EAST:
+ return new Location(x + SnakeWebSocketServlet.GRID_SIZE, y);
+ case WEST:
+ return new Location(x - SnakeWebSocketServlet.GRID_SIZE, y);
+ case NONE:
+ // fall through
+ default:
+ return this;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Location location = (Location) o;
+
+ if (x != location.x) return false;
+ if (y != location.y) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = x;
+ result = 31 * result + y;
+ return result;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Snake.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Snake.class
new file mode 100644
index 0000000..336a9c3
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Snake.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Snake.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Snake.java
new file mode 100644
index 0000000..df36332
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/Snake.java
@@ -0,0 +1,148 @@
+/*
+ * 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 websocket.tc7.snake;
+
+import java.io.IOException;
+import java.nio.CharBuffer;
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Deque;
+
+import org.apache.catalina.websocket.WsOutbound;
+
+/**
+ * @deprecated See {@link websocket.snake.Snake}
+ */
+@Deprecated
+public class Snake {
+
+ private static final int DEFAULT_LENGTH = 5;
+
+ private final int id;
+ private final WsOutbound outbound;
+
+ private Direction direction;
+ private int length = DEFAULT_LENGTH;
+ private Location head;
+ private Deque<Location> tail = new ArrayDeque<Location>();
+ private String hexColor;
+
+ public Snake(int id, WsOutbound outbound) {
+ this.id = id;
+ this.outbound = outbound;
+ this.hexColor = SnakeWebSocketServlet.getRandomHexColor();
+ resetState();
+ }
+
+ private void resetState() {
+ this.direction = Direction.NONE;
+ this.head = SnakeWebSocketServlet.getRandomLocation();
+ this.tail.clear();
+ this.length = DEFAULT_LENGTH;
+ }
+
+ private synchronized void kill() {
+ resetState();
+ try {
+ CharBuffer response = CharBuffer.wrap("{'type': 'dead'}");
+ outbound.writeTextMessage(response);
+ } catch (IOException ioe) {
+ // Ignore
+ }
+ }
+
+ private synchronized void reward() {
+ length++;
+ try {
+ CharBuffer response = CharBuffer.wrap("{'type': 'kill'}");
+ outbound.writeTextMessage(response);
+ } catch (IOException ioe) {
+ // Ignore
+ }
+ }
+
+ public synchronized void update(Collection<Snake> snakes) {
+ Location nextLocation = head.getAdjacentLocation(direction);
+ if (nextLocation.x >= SnakeWebSocketServlet.PLAYFIELD_WIDTH) {
+ nextLocation.x = 0;
+ }
+ if (nextLocation.y >= SnakeWebSocketServlet.PLAYFIELD_HEIGHT) {
+ nextLocation.y = 0;
+ }
+ if (nextLocation.x < 0) {
+ nextLocation.x = SnakeWebSocketServlet.PLAYFIELD_WIDTH;
+ }
+ if (nextLocation.y < 0) {
+ nextLocation.y = SnakeWebSocketServlet.PLAYFIELD_HEIGHT;
+ }
+ if (direction != Direction.NONE) {
+ tail.addFirst(head);
+ if (tail.size() > length) {
+ tail.removeLast();
+ }
+ head = nextLocation;
+ }
+
+ handleCollisions(snakes);
+ }
+
+ private void handleCollisions(Collection<Snake> snakes) {
+ for (Snake snake : snakes) {
+ boolean headCollision = id != snake.id && snake.getHead().equals(head);
+ boolean tailCollision = snake.getTail().contains(head);
+ if (headCollision || tailCollision) {
+ kill();
+ if (id != snake.id) {
+ snake.reward();
+ }
+ }
+ }
+ }
+
+ public synchronized Location getHead() {
+ return head;
+ }
+
+ public synchronized Collection<Location> getTail() {
+ return tail;
+ }
+
+ public synchronized void setDirection(Direction direction) {
+ this.direction = direction;
+ }
+
+ public synchronized String getLocationsJson() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(String.format("{x: %d, y: %d}",
+ Integer.valueOf(head.x), Integer.valueOf(head.y)));
+ for (Location location : tail) {
+ sb.append(',');
+ sb.append(String.format("{x: %d, y: %d}",
+ Integer.valueOf(location.x), Integer.valueOf(location.y)));
+ }
+ return String.format("{'id':%d,'body':[%s]}",
+ Integer.valueOf(id), sb.toString());
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getHexColor() {
+ return hexColor;
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet$1.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet$1.class
new file mode 100644
index 0000000..2707bb7
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet$1.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet$SnakeMessageInbound.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet$SnakeMessageInbound.class
new file mode 100644
index 0000000..2649169
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet$SnakeMessageInbound.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet.class b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet.class
new file mode 100644
index 0000000..f174143
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet.java b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet.java
new file mode 100644
index 0000000..0a8c353
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/classes/websocket/tc7/snake/SnakeWebSocketServlet.java
@@ -0,0 +1,215 @@
+/*
+ * 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 websocket.tc7.snake;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Random;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.catalina.websocket.MessageInbound;
+import org.apache.catalina.websocket.StreamInbound;
+import org.apache.catalina.websocket.WebSocketServlet;
+import org.apache.catalina.websocket.WsOutbound;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+/**
+ * Example web socket servlet for simple multi-player snake.
+ * @deprecated See {@link websocket.snake.SnakeAnnotation}
+ */
+@Deprecated
+public class SnakeWebSocketServlet extends WebSocketServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Log log =
+ LogFactory.getLog(SnakeWebSocketServlet.class);
+
+ public static final int PLAYFIELD_WIDTH = 640;
+ public static final int PLAYFIELD_HEIGHT = 480;
+ public static final int GRID_SIZE = 10;
+
+ private static final long TICK_DELAY = 100;
+
+ private static final Random random = new Random();
+
+ private final Timer gameTimer =
+ new Timer(SnakeWebSocketServlet.class.getSimpleName() + " Timer");
+
+ private final AtomicInteger connectionIds = new AtomicInteger(0);
+ private final ConcurrentHashMap<Integer, Snake> snakes =
+ new ConcurrentHashMap<Integer, Snake>();
+ private final ConcurrentHashMap<Integer, SnakeMessageInbound> connections =
+ new ConcurrentHashMap<Integer, SnakeMessageInbound>();
+
+ @Override
+ public void init() throws ServletException {
+ super.init();
+ gameTimer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ tick();
+ } catch (RuntimeException e) {
+ log.error("Caught to prevent timer from shutting down", e);
+ }
+ }
+ }, TICK_DELAY, TICK_DELAY);
+ }
+
+ private void tick() {
+ StringBuilder sb = new StringBuilder();
+ for (Iterator<Snake> iterator = getSnakes().iterator();
+ iterator.hasNext();) {
+ Snake snake = iterator.next();
+ snake.update(getSnakes());
+ sb.append(snake.getLocationsJson());
+ if (iterator.hasNext()) {
+ sb.append(',');
+ }
+ }
+ broadcast(String.format("{'type': 'update', 'data' : [%s]}",
+ sb.toString()));
+ }
+
+ private void broadcast(String message) {
+ for (SnakeMessageInbound connection : getConnections()) {
+ try {
+ CharBuffer buffer = CharBuffer.wrap(message);
+ connection.getWsOutbound().writeTextMessage(buffer);
+ } catch (IOException ignore) {
+ // Ignore
+ }
+ }
+ }
+
+ private Collection<SnakeMessageInbound> getConnections() {
+ return Collections.unmodifiableCollection(connections.values());
+ }
+
+ private Collection<Snake> getSnakes() {
+ return Collections.unmodifiableCollection(snakes.values());
+ }
+
+ public static String getRandomHexColor() {
+ float hue = random.nextFloat();
+ // sat between 0.1 and 0.3
+ float saturation = (random.nextInt(2000) + 1000) / 10000f;
+ float luminance = 0.9f;
+ Color color = Color.getHSBColor(hue, saturation, luminance);
+ return '#' + Integer.toHexString(
+ (color.getRGB() & 0xffffff) | 0x1000000).substring(1);
+ }
+
+ public static Location getRandomLocation() {
+ int x = roundByGridSize(
+ random.nextInt(SnakeWebSocketServlet.PLAYFIELD_WIDTH));
+ int y = roundByGridSize(
+ random.nextInt(SnakeWebSocketServlet.PLAYFIELD_HEIGHT));
+ return new Location(x, y);
+ }
+
+ private static int roundByGridSize(int value) {
+ value = value + (SnakeWebSocketServlet.GRID_SIZE / 2);
+ value = value / SnakeWebSocketServlet.GRID_SIZE;
+ value = value * SnakeWebSocketServlet.GRID_SIZE;
+ return value;
+ }
+
+ @Override
+ public void destroy() {
+ super.destroy();
+ if (gameTimer != null) {
+ gameTimer.cancel();
+ }
+ }
+
+ @Override
+ protected StreamInbound createWebSocketInbound(String subProtocol,
+ HttpServletRequest request) {
+ return new SnakeMessageInbound(connectionIds.incrementAndGet());
+ }
+
+ private final class SnakeMessageInbound extends MessageInbound {
+
+ private final int id;
+ private Snake snake;
+
+ private SnakeMessageInbound(int id) {
+ this.id = id;
+ }
+
+ @Override
+ protected void onOpen(WsOutbound outbound) {
+ this.snake = new Snake(id, outbound);
+ snakes.put(Integer.valueOf(id), snake);
+ connections.put(Integer.valueOf(id), this);
+ StringBuilder sb = new StringBuilder();
+ for (Iterator<Snake> iterator = getSnakes().iterator();
+ iterator.hasNext();) {
+ Snake snake = iterator.next();
+ sb.append(String.format("{id: %d, color: '%s'}",
+ Integer.valueOf(snake.getId()), snake.getHexColor()));
+ if (iterator.hasNext()) {
+ sb.append(',');
+ }
+ }
+ broadcast(String.format("{'type': 'join','data':[%s]}",
+ sb.toString()));
+ }
+
+ @Override
+ protected void onClose(int status) {
+ connections.remove(Integer.valueOf(id));
+ snakes.remove(Integer.valueOf(id));
+ broadcast(String.format("{'type': 'leave', 'id': %d}",
+ Integer.valueOf(id)));
+ }
+
+ @Override
+ protected void onBinaryMessage(ByteBuffer message) throws IOException {
+ throw new UnsupportedOperationException(
+ "Binary message not supported.");
+ }
+
+ @Override
+ protected void onTextMessage(CharBuffer charBuffer) throws IOException {
+ String message = charBuffer.toString();
+ if ("west".equals(message)) {
+ snake.setDirection(Direction.WEST);
+ } else if ("north".equals(message)) {
+ snake.setDirection(Direction.NORTH);
+ } else if ("east".equals(message)) {
+ snake.setDirection(Direction.EAST);
+ } else if ("south".equals(message)) {
+ snake.setDirection(Direction.SOUTH);
+ }
+ }
+ }
+}
diff --git a/tomcat-cas/webapps/examples/WEB-INF/jsp/applet/Clock2.java b/tomcat-cas/webapps/examples/WEB-INF/jsp/applet/Clock2.java
index 16a8790..ccc96d1 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/jsp/applet/Clock2.java
+++ b/tomcat-cas/webapps/examples/WEB-INF/jsp/applet/Clock2.java
@@ -14,10 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import java.util.*;
-import java.awt.*;
-import java.applet.*;
-import java.text.*;
+
+import java.applet.Applet;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
/**
* Time!
@@ -26,9 +30,10 @@
*/
public class Clock2 extends Applet implements Runnable {
+ private static final long serialVersionUID = 1L;
Thread timer; // The thread that displays clock
int lastxs, lastys, lastxm,
- lastym, lastxh, lastyh; // Dimensions used to draw hands
+ lastym, lastxh, lastyh; // Dimensions used to draw hands
SimpleDateFormat formatter; // Formats the date displayed
String lastdate; // String to hold date displayed
Font clockFaceFont; // Font for number display on clock
@@ -36,8 +41,8 @@
Color handColor; // Color of main hands and dial
Color numberColor; // Color of second hand and numbers
+ @Override
public void init() {
- int x,y;
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
currentDate = new Date();
@@ -95,6 +100,7 @@
}
// Paint is the main part of the program
+ @Override
public void paint(Graphics g) {
int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xcenter, ycenter;
String today;
@@ -111,7 +117,7 @@
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 10;
- }
+ }
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
@@ -122,30 +128,30 @@
today = formatter.format(currentDate);
xcenter=80;
ycenter=55;
-
+
// a= s* pi/2 - pi/2 (to switch 0,0 from 3:00 to 12:00)
// x = r(cos a) + xcenter, y = r(sin a) + ycenter
-
+
xs = (int)(Math.cos(s * 3.14f/30 - 3.14f/2) * 45 + xcenter);
ys = (int)(Math.sin(s * 3.14f/30 - 3.14f/2) * 45 + ycenter);
xm = (int)(Math.cos(m * 3.14f/30 - 3.14f/2) * 40 + xcenter);
ym = (int)(Math.sin(m * 3.14f/30 - 3.14f/2) * 40 + ycenter);
xh = (int)(Math.cos((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + xcenter);
yh = (int)(Math.sin((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + ycenter);
-
+
// Draw the circle and numbers
-
+
g.setFont(clockFaceFont);
g.setColor(handColor);
circle(xcenter,ycenter,50,g);
g.setColor(numberColor);
- g.drawString("9",xcenter-45,ycenter+3);
+ g.drawString("9",xcenter-45,ycenter+3);
g.drawString("3",xcenter+40,ycenter+3);
g.drawString("12",xcenter-5,ycenter-37);
g.drawString("6",xcenter-3,ycenter+45);
// Erase if necessary, and redraw
-
+
g.setColor(getBackground());
if (xs != lastxs || ys != lastys) {
g.drawLine(xcenter, ycenter, lastxs, lastys);
@@ -159,7 +165,7 @@
g.drawLine(xcenter-1, ycenter, lastxh, lastyh); }
g.setColor(numberColor);
g.drawString("", 5, 125);
- g.drawString(today, 5, 125);
+ g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, xm, ym);
@@ -173,34 +179,40 @@
currentDate=null;
}
+ @Override
public void start() {
timer = new Thread(this);
timer.start();
}
+ @Override
public void stop() {
timer = null;
}
+ @Override
public void run() {
Thread me = Thread.currentThread();
while (timer == me) {
try {
- Thread.currentThread().sleep(100);
+ Thread.sleep(100);
} catch (InterruptedException e) {
}
repaint();
}
}
+ @Override
public void update(Graphics g) {
paint(g);
}
+ @Override
public String getAppletInfo() {
return "Title: A Clock \nAuthor: Rachel Gollub, 1995 \nAn analog clock.";
}
-
+
+ @Override
public String[][] getParameterInfo() {
String[][] info = {
{"bgcolor", "hexadecimal RGB number", "The background color. Default is the color of your browser."},
diff --git a/tomcat-cas/webapps/examples/WEB-INF/jsp/debug-taglib.tld b/tomcat-cas/webapps/examples/WEB-INF/jsp/debug-taglib.tld
index 8deea3e..d56027c 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/jsp/debug-taglib.tld
+++ b/tomcat-cas/webapps/examples/WEB-INF/jsp/debug-taglib.tld
@@ -17,7 +17,7 @@
-->
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
- "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
+ "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<!-- a tag library descriptor -->
@@ -36,19 +36,19 @@
<validator-class>validators.DebugValidator</validator-class>
</validator>
- <!-- This is a dummy tag solely to satisfy DTD requirements -->
+ <!-- This is a dummy tag solely to satisfy DTD requirements -->
<tag>
<name>log</name>
<tag-class>examples.LogTag</tag-class>
<body-content>TAGDEPENDENT</body-content>
<description>
- Perform a server side action; Log the message.
+ Perform a server side action; Log the message.
</description>
<attribute>
- <name>toBrowser</name>
- <required>false</required>
+ <name>toBrowser</name>
+ <required>false</required>
</attribute>
</tag>
-
+
</taglib>
diff --git a/tomcat-cas/webapps/examples/WEB-INF/jsp/example-taglib.tld b/tomcat-cas/webapps/examples/WEB-INF/jsp/example-taglib.tld
index 0739c5c..906ba00 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/jsp/example-taglib.tld
+++ b/tomcat-cas/webapps/examples/WEB-INF/jsp/example-taglib.tld
@@ -17,7 +17,7 @@
-->
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
- "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
+ "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
@@ -26,7 +26,7 @@
<short-name>simple</short-name>
<uri>http://tomcat.apache.org/example-taglib</uri>
<description>
- A simple tab library for the examples
+ A simple tab library for the examples
</description>
<tag>
@@ -38,7 +38,7 @@
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
- </tag>
+ </tag>
<!-- A simple Tag -->
<!-- foo tag -->
@@ -48,7 +48,7 @@
<tei-class>examples.FooTagExtraInfo</tei-class>
<body-content>JSP</body-content>
<description>
- Perform a server side action; uses 3 mandatory attributes
+ Perform a server side action; uses 3 mandatory attributes
</description>
<attribute>
@@ -72,12 +72,47 @@
<tag-class>examples.LogTag</tag-class>
<body-content>TAGDEPENDENT</body-content>
<description>
- Perform a server side action; Log the message.
+ Perform a server side action; Log the message.
</description>
<attribute>
- <name>toBrowser</name>
- <required>false</required>
+ <name>toBrowser</name>
+ <required>false</required>
</attribute>
</tag>
-
+
+ <!-- Another simple Tag -->
+ <!-- values tag -->
+ <tag>
+ <name>values</name>
+ <tag-class>examples.ValuesTag</tag-class>
+ <body-content>empty</body-content>
+ <description>
+ Accept and return values of different types. This tag is used
+ to illustrate type coercions.
+ </description>
+ <attribute>
+ <name>object</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <type>java.lang.Object</type>
+ </attribute>
+ <attribute>
+ <name>string</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <type>java.lang.String</type>
+ </attribute>
+ <attribute>
+ <name>long</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <type>long</type>
+ </attribute>
+ <attribute>
+ <name>double</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <type>double</type>
+ </attribute>
+ </tag>
</taglib>
diff --git a/tomcat-cas/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld b/tomcat-cas/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld
index 39f56f5..d3a2563 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld
+++ b/tomcat-cas/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld
@@ -23,12 +23,12 @@
<description>A tag library exercising SimpleTag handlers.</description>
<tlib-version>1.0</tlib-version>
<short-name>SimpleTagLibrary</short-name>
- <uri>/SimpleTagLibrary</uri>
+ <uri>http://tomcat.apache.org/jsp2-example-taglib</uri>
<tag>
- <description>Outputs Hello, World</description>
+ <description>Outputs Hello, World</description>
<name>helloWorld</name>
- <tag-class>jsp2.examples.simpletag.HelloWorldSimpleTag</tag-class>
- <body-content>empty</body-content>
+ <tag-class>jsp2.examples.simpletag.HelloWorldSimpleTag</tag-class>
+ <body-content>empty</body-content>
</tag>
<tag>
<description>Repeats the body of the tag 'num' times</description>
@@ -46,15 +46,15 @@
</attribute>
</tag>
<tag>
- <description>Populates the page context with a BookBean</description>
+ <description>Populates the page context with a BookBean</description>
<name>findBook</name>
- <tag-class>jsp2.examples.simpletag.FindBookSimpleTag</tag-class>
- <body-content>empty</body-content>
- <attribute>
- <name>var</name>
- <required>true</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
+ <tag-class>jsp2.examples.simpletag.FindBookSimpleTag</tag-class>
+ <body-content>empty</body-content>
+ <attribute>
+ <name>var</name>
+ <required>true</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
</tag>
<tag>
<description>
@@ -66,17 +66,17 @@
<attribute>
<name>fragment1</name>
<required>true</required>
- <fragment>true</fragment>
+ <fragment>true</fragment>
</attribute>
<attribute>
<name>fragment2</name>
<required>true</required>
- <fragment>true</fragment>
+ <fragment>true</fragment>
</attribute>
<attribute>
<name>fragment3</name>
<required>true</required>
- <fragment>true</fragment>
+ <fragment>true</fragment>
</attribute>
</tag>
<tag>
@@ -94,31 +94,31 @@
</attribute>
</tag>
<tag>
- <description>
- Tag that echoes all its attributes and body content
- </description>
- <name>echoAttributes</name>
- <tag-class>jsp2.examples.simpletag.EchoAttributesTag</tag-class>
- <body-content>empty</body-content>
- <dynamic-attributes>true</dynamic-attributes>
+ <description>
+ Tag that echoes all its attributes and body content
+ </description>
+ <name>echoAttributes</name>
+ <tag-class>jsp2.examples.simpletag.EchoAttributesTag</tag-class>
+ <body-content>empty</body-content>
+ <dynamic-attributes>true</dynamic-attributes>
</tag>
<function>
<description>Reverses the characters in the given String</description>
<name>reverse</name>
- <function-class>jsp2.examples.el.Functions</function-class>
- <function-signature>java.lang.String reverse( java.lang.String )</function-signature>
+ <function-class>jsp2.examples.el.Functions</function-class>
+ <function-signature>java.lang.String reverse( java.lang.String )</function-signature>
</function>
<function>
<description>Counts the number of vowels (a,e,i,o,u) in the given String</description>
<name>countVowels</name>
- <function-class>jsp2.examples.el.Functions</function-class>
- <function-signature>java.lang.String numVowels( java.lang.String )</function-signature>
+ <function-class>jsp2.examples.el.Functions</function-class>
+ <function-signature>java.lang.String numVowels( java.lang.String )</function-signature>
</function>
<function>
- <description>Converts the string to all caps</description>
+ <description>Converts the string to all caps</description>
<name>caps</name>
- <function-class>jsp2.examples.el.Functions</function-class>
- <function-signature>java.lang.String caps( java.lang.String )</function-signature>
+ <function-class>jsp2.examples.el.Functions</function-class>
+ <function-signature>java.lang.String caps( java.lang.String )</function-signature>
</function>
</taglib>
diff --git a/tomcat-cas/webapps/examples/WEB-INF/lib/jstl.jar b/tomcat-cas/webapps/examples/WEB-INF/lib/jstl.jar
deleted file mode 100644
index a02abec..0000000
--- a/tomcat-cas/webapps/examples/WEB-INF/lib/jstl.jar
+++ /dev/null
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/lib/standard.jar b/tomcat-cas/webapps/examples/WEB-INF/lib/standard.jar
deleted file mode 100644
index bc528ac..0000000
--- a/tomcat-cas/webapps/examples/WEB-INF/lib/standard.jar
+++ /dev/null
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/lib/taglibs-standard-impl-1.2.5.jar b/tomcat-cas/webapps/examples/WEB-INF/lib/taglibs-standard-impl-1.2.5.jar
new file mode 100644
index 0000000..9176777
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/lib/taglibs-standard-impl-1.2.5.jar
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/lib/taglibs-standard-spec-1.2.5.jar b/tomcat-cas/webapps/examples/WEB-INF/lib/taglibs-standard-spec-1.2.5.jar
new file mode 100644
index 0000000..d547867
--- /dev/null
+++ b/tomcat-cas/webapps/examples/WEB-INF/lib/taglibs-standard-spec-1.2.5.jar
Binary files differ
diff --git a/tomcat-cas/webapps/examples/WEB-INF/tags/displayProducts.tag b/tomcat-cas/webapps/examples/WEB-INF/tags/displayProducts.tag
index 508852e..b2702a3 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/tags/displayProducts.tag
+++ b/tomcat-cas/webapps/examples/WEB-INF/tags/displayProducts.tag
@@ -24,28 +24,28 @@
<table border="1">
<tr>
- <td>
+ <td>
<c:set var="name" value="Hand-held Color PDA"/>
<c:set var="price" value="$298.86"/>
<jsp:invoke fragment="normalPrice"/>
</td>
- <td>
+ <td>
<c:set var="name" value="4-Pack 150 Watt Light Bulbs"/>
<c:set var="origPrice" value="$2.98"/>
<c:set var="salePrice" value="$2.32"/>
<jsp:invoke fragment="onSale"/>
</td>
- <td>
+ <td>
<c:set var="name" value="Digital Cellular Phone"/>
<c:set var="price" value="$68.74"/>
<jsp:invoke fragment="normalPrice"/>
</td>
- <td>
+ <td>
<c:set var="name" value="Baby Grand Piano"/>
<c:set var="price" value="$10,800.00"/>
<jsp:invoke fragment="normalPrice"/>
</td>
- <td>
+ <td>
<c:set var="name" value="Luxury Car w/ Leather Seats"/>
<c:set var="origPrice" value="$23,980.00"/>
<c:set var="salePrice" value="$21,070.00"/>
diff --git a/tomcat-cas/webapps/examples/WEB-INF/web.xml b/tomcat-cas/webapps/examples/WEB-INF/web.xml
index 955179e..0c8fe38 100644
--- a/tomcat-cas/webapps/examples/WEB-INF/web.xml
+++ b/tomcat-cas/webapps/examples/WEB-INF/web.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
+ 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
@@ -15,57 +15,61 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- version="2.5">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0"
+ metadata-complete="true">
<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>
+ <!-- Define example filters -->
+ <filter>
+ <filter-name>Timing filter</filter-name>
+ <filter-class>filters.ExampleFilter</filter-class>
+ <init-param>
+ <param-name>attribute</param-name>
+ <param-value>filters.ExampleFilter</param-value>
+ </init-param>
+ </filter>
- <!-- Define servlet-mapped and path-mapped example filters -->
- <filter>
- <filter-name>Servlet Mapped Filter</filter-name>
- <filter-class>filters.ExampleFilter</filter-class>
- <init-param>
- <param-name>attribute</param-name>
- <param-value>filters.ExampleFilter.SERVLET_MAPPED</param-value>
- </init-param>
- </filter>
- <filter>
- <filter-name>Path Mapped Filter</filter-name>
- <filter-class>filters.ExampleFilter</filter-class>
- <init-param>
- <param-name>attribute</param-name>
- <param-value>filters.ExampleFilter.PATH_MAPPED</param-value>
- </init-param>
- </filter>
<filter>
<filter-name>Request Dumper Filter</filter-name>
- <filter-class>filters.RequestDumperFilter</filter-class>
+ <filter-class>org.apache.catalina.filters.RequestDumperFilter</filter-class>
</filter>
<!-- Example filter to set character encoding on each request -->
<filter>
<filter-name>Set Character Encoding</filter-name>
- <filter-class>filters.SetCharacterEncodingFilter</filter-class>
+ <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>EUC_JP</param-value>
</init-param>
+ <init-param>
+ <param-name>ignore</param-name>
+ <param-value>true</param-value>
+ </init-param>
</filter>
<filter>
<filter-name>Compression Filter</filter-name>
<filter-class>compressionFilters.CompressionFilter</filter-class>
-
<init-param>
- <param-name>compressionThreshold</param-name>
- <param-value>10</param-value>
+ <param-name>compressionThreshold</param-name>
+ <param-value>128</param-value>
+ </init-param>
+ <init-param>
+ <param-name>compressionBuffer</param-name>
+ <param-value>8192</param-value>
+ </init-param>
+ <init-param>
+ <param-name>compressionMimeTypes</param-name>
+ <param-value>text/html,text/plain,text/xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
@@ -73,15 +77,13 @@
</init-param>
</filter>
- <!-- Define filter mappings for the defined filters -->
+ <!-- Define filter mappings for the timing filters -->
+ <!--
<filter-mapping>
- <filter-name>Servlet Mapped Filter</filter-name>
- <servlet-name>invoker</servlet-name>
+ <filter-name>Timing Filter</filter-name>
+ <url-pattern>/*</url-pattern>
</filter-mapping>
- <filter-mapping>
- <filter-name>Path Mapped Filter</filter-name>
- <url-pattern>/servlet/*</url-pattern>
- </filter-mapping>
+ -->
<!-- Example filter mapping to apply the "Set Character Encoding" filter
to *all* requests processed by this web application -->
@@ -117,8 +119,8 @@
<!-- Define servlets that are included in the example application -->
<servlet>
- <servlet-name>servletToJsp</servlet-name>
- <servlet-class>servletToJsp</servlet-class>
+ <servlet-name>ServletToJsp</servlet-name>
+ <servlet-class>ServletToJsp</servlet-class>
</servlet>
<servlet>
<servlet-name>ChatServlet</servlet-name>
@@ -155,7 +157,7 @@
<servlet-mapping>
<servlet-name>ChatServlet</servlet-name>
- <url-pattern>/jsp/chat/chat</url-pattern>
+ <url-pattern>/servlets/chat/chat</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CompressionFilterTestServlet</servlet-name>
@@ -186,68 +188,68 @@
<url-pattern>/servlets/servlet/SessionExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>servletToJsp</servlet-name>
+ <servlet-name>ServletToJsp</servlet-name>
<url-pattern>/servletToJsp</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
- <taglib-uri>
- http://tomcat.apache.org/debug-taglib
- </taglib-uri>
- <taglib-location>
- /WEB-INF/jsp/debug-taglib.tld
- </taglib-location>
- </taglib>
+ <taglib-uri>
+ http://tomcat.apache.org/debug-taglib
+ </taglib-uri>
+ <taglib-location>
+ /WEB-INF/jsp/debug-taglib.tld
+ </taglib-location>
+ </taglib>
- <taglib>
- <taglib-uri>
- http://tomcat.apache.org/examples-taglib
- </taglib-uri>
- <taglib-location>
- /WEB-INF/jsp/example-taglib.tld
- </taglib-location>
- </taglib>
+ <taglib>
+ <taglib-uri>
+ http://tomcat.apache.org/example-taglib
+ </taglib-uri>
+ <taglib-location>
+ /WEB-INF/jsp/example-taglib.tld
+ </taglib-location>
+ </taglib>
- <taglib>
- <taglib-uri>
- http://tomcat.apache.org/jsp2-example-taglib
- </taglib-uri>
- <taglib-location>
- /WEB-INF/jsp2/jsp2-example-taglib.tld
- </taglib-location>
- </taglib>
+ <taglib>
+ <taglib-uri>
+ http://tomcat.apache.org/jsp2-example-taglib
+ </taglib-uri>
+ <taglib-location>
+ /WEB-INF/jsp2/jsp2-example-taglib.tld
+ </taglib-location>
+ </taglib>
- <jsp-property-group>
- <description>
- Special property group for JSP Configuration JSP example.
- </description>
- <display-name>JSPConfiguration</display-name>
- <url-pattern>/jsp/jsp2/misc/config.jsp</url-pattern>
- <el-ignored>true</el-ignored>
- <page-encoding>ISO-8859-1</page-encoding>
- <scripting-invalid>true</scripting-invalid>
- <include-prelude>/jsp/jsp2/misc/prelude.jspf</include-prelude>
- <include-coda>/jsp/jsp2/misc/coda.jspf</include-coda>
- </jsp-property-group>
+ <jsp-property-group>
+ <description>
+ Special property group for JSP Configuration JSP example.
+ </description>
+ <display-name>JSPConfiguration</display-name>
+ <url-pattern>/jsp/jsp2/misc/config.jsp</url-pattern>
+ <el-ignored>true</el-ignored>
+ <page-encoding>ISO-8859-1</page-encoding>
+ <scripting-invalid>true</scripting-invalid>
+ <include-prelude>/jsp/jsp2/misc/prelude.jspf</include-prelude>
+ <include-coda>/jsp/jsp2/misc/coda.jspf</include-coda>
+ </jsp-property-group>
</jsp-config>
-
+
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
- <!-- Define the context-relative URL(s) to be protected -->
+ <!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/jsp/security/protected/*</url-pattern>
- <!-- If you list http methods, only those methods are protected -->
- <http-method>DELETE</http-method>
+ <!-- If you list http methods, only those methods are protected -->
+ <http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
- <http-method>PUT</http-method>
+ <http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>tomcat</role-name>
- <role-name>role1</role-name>
+ <role-name>role1</role-name>
</auth-constraint>
</security-constraint>
@@ -260,14 +262,14 @@
<form-error-page>/jsp/security/protected/error.jsp</form-error-page>
</form-login-config>
</login-config>
-
+
<!-- Security roles referenced by this web application -->
<security-role>
<role-name>role1</role-name>
</security-role>
<security-role>
<role-name>tomcat</role-name>
- </security-role>
+ </security-role>
<!-- Environment entry examples -->
<!--env-entry>
@@ -304,4 +306,109 @@
<env-entry-value>10</env-entry-value>
</env-entry>
+ <!-- Async examples -->
+ <servlet>
+ <servlet-name>async0</servlet-name>
+ <servlet-class>async.Async0</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>async0</servlet-name>
+ <url-pattern>/async/async0</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>async1</servlet-name>
+ <servlet-class>async.Async1</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>async1</servlet-name>
+ <url-pattern>/async/async1</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>async2</servlet-name>
+ <servlet-class>async.Async2</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>async2</servlet-name>
+ <url-pattern>/async/async2</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>async3</servlet-name>
+ <servlet-class>async.Async3</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>async3</servlet-name>
+ <url-pattern>/async/async3</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>stock</servlet-name>
+ <servlet-class>async.AsyncStockServlet</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>stock</servlet-name>
+ <url-pattern>/async/stockticker</url-pattern>
+ </servlet-mapping>
+
+ <!-- WebSocket Examples using Deprecated Tomcat 7 API-->
+ <servlet>
+ <servlet-name>wsEchoStream</servlet-name>
+ <servlet-class>websocket.tc7.echo.EchoStream</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>wsEchoStream</servlet-name>
+ <url-pattern>/websocket/tc7/echoStream</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>wsEchoMessage</servlet-name>
+ <servlet-class>websocket.tc7.echo.EchoMessage</servlet-class>
+ <!-- Uncomment the following block to increase the default maximum
+ WebSocket buffer size from 2MB to 20MB which is required for the
+ Autobahn test suite to pass fully. -->
+ <!--
+ <init-param>
+ <param-name>byteBufferMaxSize</param-name>
+ <param-value>20971520</param-value>
+ </init-param>
+ <init-param>
+ <param-name>charBufferMaxSize</param-name>
+ <param-value>20971520</param-value>
+ </init-param>
+ -->
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>wsEchoMessage</servlet-name>
+ <url-pattern>/websocket/tc7/echoMessage</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>wsChat</servlet-name>
+ <servlet-class>websocket.tc7.chat.ChatWebSocketServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>wsChat</servlet-name>
+ <url-pattern>/websocket/tc7/chat</url-pattern>
+ </servlet-mapping>
+ <servlet>
+ <servlet-name>wsSnake</servlet-name>
+ <servlet-class>websocket.tc7.snake.SnakeWebSocketServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>wsSnake</servlet-name>
+ <url-pattern>/websocket/tc7/snake</url-pattern>
+ </servlet-mapping>
+ <!-- Websocket examples -->
+ <listener>
+ <listener-class>websocket.drawboard.DrawboardContextListener</listener-class>
+ </listener>
+
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ <welcome-file>index.xhtml</welcome-file>
+ <welcome-file>index.htm</welcome-file>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
</web-app>
diff --git a/tomcat-cas/webapps/examples/index.html b/tomcat-cas/webapps/examples/index.html
index 8dfea59..6bf9f79 100644
--- a/tomcat-cas/webapps/examples/index.html
+++ b/tomcat-cas/webapps/examples/index.html
@@ -14,16 +14,19 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<HTML><HEAD><TITLE>Apache Tomcat Examples</TITLE>
-<META http-equiv=Content-Type content="text/html">
-</HEAD>
-<BODY>
-<P>
-<H3>Apache Tomcat Examples</H3>
-<P></P>
+<!DOCTYPE HTML><html lang="en"><head>
+<meta charset="UTF-8">
+<title>Apache Tomcat Examples</title>
+</head>
+<body>
+<p>
+<h3>Apache Tomcat Examples</H3>
+<p></p>
<ul>
<li><a href="servlets">Servlets examples</a></li>
<li><a href="jsp">JSP Examples</a></li>
+<li><a href="websocket/index.xhtml">WebSocket (JSR356) Examples</a></li>
+<li><a href="websocket-deprecated">WebSocket Examples using the deprecated
+ Apache Tomcat proprietary API</a></li>
</ul>
-</BODY></HTML>
+</body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/login.jsp b/tomcat-cas/webapps/examples/jsp/async/async1.jsp
similarity index 63%
copy from tomcat-cas/webapps/examples/jsp/chat/login.jsp
copy to tomcat-cas/webapps/examples/jsp/async/async1.jsp
index e1c6496..fb6fa2d 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/login.jsp
+++ b/tomcat-cas/webapps/examples/jsp/async/async1.jsp
@@ -1,7 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<%--
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.
@@ -16,18 +13,14 @@
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.
--->
-<head>
- <title>JSP Chat</title>
-</head>
-
-<body bgcolor="#FFFFFF">
-
-<form method="POST" action='chat' target="_top" name="loginForm">
-<input type="hidden" name="action" value="login">
-Nickname: <input type="text" name="nickname">
-<input type="submit">
-</form>
-
-</body>
-</html>
+--%>
+<%@page session="false"%>
+Output from async1.jsp
+Type is <%=request.getDispatcherType()%>
+<%
+System.out.println("Inside Async 1");
+ if (request.isAsyncStarted()) {
+ request.getAsyncContext().complete();
+ }
+%>
+Completed async request at <%=new java.sql.Date(System.currentTimeMillis())%>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/jsp/chat/login.jsp b/tomcat-cas/webapps/examples/jsp/async/async1.jsp.html
similarity index 63%
copy from tomcat-cas/webapps/examples/jsp/chat/login.jsp
copy to tomcat-cas/webapps/examples/jsp/async/async1.jsp.html
index e1c6496..4c460b8 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/login.jsp
+++ b/tomcat-cas/webapps/examples/jsp/async/async1.jsp.html
@@ -1,7 +1,5 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<html><body><pre>
+<%--
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.
@@ -16,18 +14,15 @@
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.
--->
-<head>
- <title>JSP Chat</title>
-</head>
-
-<body bgcolor="#FFFFFF">
-
-<form method="POST" action='chat' target="_top" name="loginForm">
-<input type="hidden" name="action" value="login">
-Nickname: <input type="text" name="nickname">
-<input type="submit">
-</form>
-
-</body>
-</html>
+--%>
+<%@page session="false"%>
+Output from async1.jsp
+Type is <%=request.getDispatcherType()%>
+<%
+System.out.println("Inside Async 1");
+ if (request.isAsyncStarted()) {
+ request.getAsyncContext().complete();
+ }
+%>
+Completed async request at <%=new java.sql.Date(System.currentTimeMillis())%>
+</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/login.jsp b/tomcat-cas/webapps/examples/jsp/async/async3.jsp
similarity index 63%
copy from tomcat-cas/webapps/examples/jsp/chat/login.jsp
copy to tomcat-cas/webapps/examples/jsp/async/async3.jsp
index e1c6496..c16d5d7 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/login.jsp
+++ b/tomcat-cas/webapps/examples/jsp/async/async3.jsp
@@ -1,7 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<%--
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.
@@ -16,18 +13,8 @@
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.
--->
-<head>
- <title>JSP Chat</title>
-</head>
-
-<body bgcolor="#FFFFFF">
-
-<form method="POST" action='chat' target="_top" name="loginForm">
-<input type="hidden" name="action" value="login">
-Nickname: <input type="text" name="nickname">
-<input type="submit">
-</form>
-
-</body>
-</html>
+--%>
+<%@page session="false"%>
+Output from async3.jsp
+Type is <%=request.getDispatcherType()%>
+Completed async 3 request at <%=new java.sql.Date(System.currentTimeMillis())%>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/jsp/chat/login.jsp b/tomcat-cas/webapps/examples/jsp/async/async3.jsp.html
similarity index 63%
copy from tomcat-cas/webapps/examples/jsp/chat/login.jsp
copy to tomcat-cas/webapps/examples/jsp/async/async3.jsp.html
index e1c6496..ad77ae9 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/login.jsp
+++ b/tomcat-cas/webapps/examples/jsp/async/async3.jsp.html
@@ -1,7 +1,5 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<html><body><pre>
+<%--
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.
@@ -16,18 +14,9 @@
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.
--->
-<head>
- <title>JSP Chat</title>
-</head>
-
-<body bgcolor="#FFFFFF">
-
-<form method="POST" action='chat' target="_top" name="loginForm">
-<input type="hidden" name="action" value="login">
-Nickname: <input type="text" name="nickname">
-<input type="submit">
-</form>
-
-</body>
-</html>
+--%>
+<%@page session="false"%>
+Output from async3.jsp
+Type is <%=request.getDispatcherType()%>
+Completed async 3 request at <%=new java.sql.Date(System.currentTimeMillis())%>
+</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/async/index.jsp b/tomcat-cas/webapps/examples/jsp/async/index.jsp
new file mode 100644
index 0000000..28af9ac
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/async/index.jsp
@@ -0,0 +1,69 @@
+<%--
+ 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.
+--%>
+<%@page session="false"%>
+
+<pre>
+Use cases:
+
+1. Simple dispatch
+ - servlet does startAsync()
+ - background thread calls ctx.dispatch()
+ <a href="<%=response.encodeURL("/examples/async/async0")%>"> Async 0 </a>
+
+2. Simple dispatch
+ - servlet does startAsync()
+ - background thread calls dispatch(/path/to/jsp)
+ <a href="<%=response.encodeURL("/examples/async/async1")%>"> Async 1 </a>
+
+3. Simple dispatch
+ - servlet does startAsync()
+ - background thread calls writes and calls complete()
+ <a href="<%=response.encodeURL("/examples/async/async2")%>"> Async 2 </a>
+
+4. Simple dispatch
+ - servlet does a startAsync()
+ - servlet calls dispatch(/path/to/jsp)
+ - servlet calls complete()
+ <a href="<%=response.encodeURL("/examples/async/async3")%>"> Async 3 </a>
+
+3. Timeout s1
+ - servlet does a startAsync()
+ - servlet does a setAsyncTimeout
+ - returns - waits for timeout to happen should return error page
+
+4. Timeout s2
+ - servlet does a startAsync()
+ - servlet does a setAsyncTimeout
+ - servlet does a addAsyncListener
+ - returns - waits for timeout to happen and listener invoked
+
+5. Dispatch to asyncSupported=false servlet
+ - servlet1 does a startAsync()
+ - servlet1 dispatches to dispatch(/servlet2)
+ - the container calls complete() after servlet2 is complete
+ - TODO
+
+6. Chained dispatch
+ - servlet1 does a startAsync
+ - servlet1 does a dispatch to servlet2 (asyncsupported=true)
+ - servlet2 does a dispatch to servlet3 (asyncsupported=true)
+ - servlet3 does a dispatch to servlet4 (asyncsupported=false)
+
+
+7. Stock ticker
+ <a href="<%=response.encodeURL("/examples/async/stockticker")%>"> StockTicker </a>
+</pre>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/jsp/async/index.jsp.html b/tomcat-cas/webapps/examples/jsp/async/index.jsp.html
new file mode 100644
index 0000000..6f124b5
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/async/index.jsp.html
@@ -0,0 +1,71 @@
+<html><body><pre>
+<%--
+ 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.
+--%>
+<%@page session="false"%>
+
+<pre>
+Use cases:
+
+1. Simple dispatch
+ - servlet does startAsync()
+ - background thread calls ctx.dispatch()
+ <a href="<%=response.encodeURL("/examples/async/async0")%>"> Async 0 </a>
+
+2. Simple dispatch
+ - servlet does startAsync()
+ - background thread calls dispatch(/path/to/jsp)
+ <a href="<%=response.encodeURL("/examples/async/async1")%>"> Async 1 </a>
+
+3. Simple dispatch
+ - servlet does startAsync()
+ - background thread calls writes and calls complete()
+ <a href="<%=response.encodeURL("/examples/async/async2")%>"> Async 2 </a>
+
+4. Simple dispatch
+ - servlet does a startAsync()
+ - servlet calls dispatch(/path/to/jsp)
+ - servlet calls complete()
+ <a href="<%=response.encodeURL("/examples/async/async3")%>"> Async 3 </a>
+
+3. Timeout s1
+ - servlet does a startAsync()
+ - servlet does a setAsyncTimeout
+ - returns - waits for timeout to happen should return error page
+
+4. Timeout s2
+ - servlet does a startAsync()
+ - servlet does a setAsyncTimeout
+ - servlet does a addAsyncListener
+ - returns - waits for timeout to happen and listener invoked
+
+5. Dispatch to asyncSupported=false servlet
+ - servlet1 does a startAsync()
+ - servlet1 dispatches to dispatch(/servlet2)
+ - the container calls complete() after servlet2 is complete
+ - TODO
+
+6. Chained dispatch
+ - servlet1 does a startAsync
+ - servlet1 does a dispatch to servlet2 (asyncsupported=true)
+ - servlet2 does a dispatch to servlet3 (asyncsupported=true)
+ - servlet3 does a dispatch to servlet4 (asyncsupported=false)
+
+
+7. Stock ticker
+ <a href="<%=response.encodeURL("/examples/async/stockticker")%>"> StockTicker </a>
+</pre>
+</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/Entries.java.html b/tomcat-cas/webapps/examples/jsp/cal/Entries.java.html
index 6093d31..289363b 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/Entries.java.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/Entries.java.html
@@ -1,74 +1,62 @@
<html><body><pre>
/*
-* 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.
-*/
+ * 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 cal;
import java.util.Hashtable;
-import javax.servlet.http.*;
+
+import javax.servlet.http.HttpServletRequest;
public class Entries {
- private Hashtable entries;
- private static final String[] time = {"8am", "9am", "10am", "11am", "12pm",
- "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
- "7pm", "8pm" };
- public static final int rows = 12;
+ private Hashtable<String, Entry> entries;
+ private static final String[] time = { "8am", "9am", "10am", "11am",
+ "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", "7pm", "8pm" };
+ public static final int rows = 12;
- public Entries () {
- entries = new Hashtable (rows);
- for (int i=0; i < rows; i++) {
- entries.put (time[i], new Entry(time[i]));
- }
- }
-
- public int getRows () {
- return rows;
- }
-
- public Entry getEntry (int index) {
- return (Entry)this.entries.get(time[index]);
- }
-
- public int getIndex (String tm) {
- for (int i=0; i<rows; i++)
- if(tm.equals(time[i])) return i;
- return -1;
- }
-
- public void processRequest (HttpServletRequest request, String tm) {
- int index = getIndex (tm);
- if (index >= 0) {
- String descr = request.getParameter ("description");
- ((Entry)entries.get(time[index])).setDescription (descr);
+ public Entries() {
+ entries = new Hashtable<String, Entry>(rows);
+ for (int i = 0; i < rows; i++) {
+ entries.put(time[i], new Entry(time[i]));
+ }
}
- }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public Entry getEntry(int index) {
+ return this.entries.get(time[index]);
+ }
+
+ public int getIndex(String tm) {
+ for (int i = 0; i < rows; i++)
+ if (tm.equals(time[i]))
+ return i;
+ return -1;
+ }
+
+ public void processRequest(HttpServletRequest request, String tm) {
+ int index = getIndex(tm);
+ if (index >= 0) {
+ String descr = request.getParameter("description");
+ entries.get(time[index]).setDescription(descr);
+ }
+ }
}
-
-
-
-
-
-
-
-
-
-
-
-
-
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/Entry.java.html b/tomcat-cas/webapps/examples/jsp/cal/Entry.java.html
index f982750..4e97bc1 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/Entry.java.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/Entry.java.html
@@ -1,57 +1,55 @@
<html><body><pre>
/*
-* 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.
-*/
+ * 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 cal;
public class Entry {
- String hour;
- String description;
- String color;
+ String hour;
+ String description;
- public Entry (String hour) {
- this.hour = hour;
- this.description = "";
+ public Entry(String hour) {
+ this.hour = hour;
+ this.description = "";
- }
+ }
- public String getHour () {
- return this.hour;
- }
+ public String getHour() {
+ return this.hour;
+ }
- public String getColor () {
- if (description.equals("")) return "lightblue";
- else return "red";
- }
+ public String getColor() {
+ if (description.equals("")) {
+ return "lightblue";
+ }
+ return "red";
+ }
- public String getDescription () {
- if (description.equals("")) return "None";
- else return this.description;
- }
+ public String getDescription() {
+ if (description.equals("")) {
+ return "None";
+ }
+ return this.description;
+ }
- public void setDescription (String descr) {
- description = descr;
- }
-
+ public void setDescription(String descr) {
+ description = descr;
+ }
+
}
-
-
-
-
-
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/JspCalendar.java.html b/tomcat-cas/webapps/examples/jsp/cal/JspCalendar.java.html
index e1b4b83..3c04fd1 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/JspCalendar.java.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/JspCalendar.java.html
@@ -18,139 +18,136 @@
package cal;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Date;
public class JspCalendar {
Calendar calendar = null;
- Date currentDate;
public JspCalendar() {
- calendar = Calendar.getInstance();
- Date trialTime = new Date();
- calendar.setTime(trialTime);
+ calendar = Calendar.getInstance();
+ Date trialTime = new Date();
+ calendar.setTime(trialTime);
}
public int getYear() {
- return calendar.get(Calendar.YEAR);
+ return calendar.get(Calendar.YEAR);
}
-
+
public String getMonth() {
- int m = getMonthInt();
- String[] months = new String [] { "January", "February", "March",
- "April", "May", "June",
- "July", "August", "September",
- "October", "November", "December" };
- if (m > 12)
- return "Unknown to Man";
-
- return months[m - 1];
+ int m = getMonthInt();
+ String[] months = new String [] { "January", "February", "March",
+ "April", "May", "June",
+ "July", "August", "September",
+ "October", "November", "December" };
+ if (m > 12)
+ return "Unknown to Man";
+
+ return months[m - 1];
}
public String getDay() {
- int x = getDayOfWeek();
- String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday"};
+ int x = getDayOfWeek();
+ String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"};
- if (x > 7)
- return "Unknown to Man";
+ if (x > 7)
+ return "Unknown to Man";
- return days[x - 1];
+ return days[x - 1];
}
-
+
public int getMonthInt() {
- return 1 + calendar.get(Calendar.MONTH);
+ return 1 + calendar.get(Calendar.MONTH);
}
public String getDate() {
- return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
+ return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getCurrentDate() {
Date dt = new Date ();
- calendar.setTime (dt);
- return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
+ calendar.setTime (dt);
+ return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getNextDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
- return getDate ();
+ return getDate ();
}
public String getPrevDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
- return getDate ();
+ return getDate ();
}
public String getTime() {
- return getHour() + ":" + getMinute() + ":" + getSecond();
+ return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth() {
- return calendar.get(Calendar.DAY_OF_MONTH);
+ return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear() {
- return calendar.get(Calendar.DAY_OF_YEAR);
+ return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear() {
- return calendar.get(Calendar.WEEK_OF_YEAR);
+ return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth() {
- return calendar.get(Calendar.WEEK_OF_MONTH);
+ return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek() {
- return calendar.get(Calendar.DAY_OF_WEEK);
+ return calendar.get(Calendar.DAY_OF_WEEK);
}
-
+
public int getHour() {
- return calendar.get(Calendar.HOUR_OF_DAY);
+ return calendar.get(Calendar.HOUR_OF_DAY);
}
-
+
public int getMinute() {
- return calendar.get(Calendar.MINUTE);
+ return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
- return calendar.get(Calendar.SECOND);
+ return calendar.get(Calendar.SECOND);
}
-
+
public int getEra() {
- return calendar.get(Calendar.ERA);
+ return calendar.get(Calendar.ERA);
}
public String getUSTimeZone() {
- String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
- "Mountain", "Central", "Eastern"};
-
- return zones[10 + getZoneOffset()];
+ String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
+ "Mountain", "Central", "Eastern"};
+
+ return zones[10 + getZoneOffset()];
}
public int getZoneOffset() {
- return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
+ return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
}
public int getDSTOffset() {
- return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
+ return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
}
-
+
public int getAMPM() {
- return calendar.get(Calendar.AM_PM);
+ return calendar.get(Calendar.AM_PM);
}
}
-
-
-
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/TableBean.java.html b/tomcat-cas/webapps/examples/jsp/cal/TableBean.java.html
index a81a66b..78c0e7f 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/TableBean.java.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/TableBean.java.html
@@ -1,102 +1,103 @@
<html><body><pre>
/*
-* 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.
-*/
+ * 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 cal;
-import javax.servlet.http.*;
import java.util.Hashtable;
+import javax.servlet.http.HttpServletRequest;
+
public class TableBean {
- Hashtable table;
- JspCalendar JspCal;
- Entries entries;
- String date;
- String name = null;
- String email = null;
- boolean processError = false;
+ Hashtable<String, Entries> table;
+ JspCalendar JspCal;
+ Entries entries;
+ String date;
+ String name = null;
+ String email = null;
+ boolean processError = false;
- public TableBean () {
- this.table = new Hashtable (10);
- this.JspCal = new JspCalendar ();
- this.date = JspCal.getCurrentDate ();
- }
-
- public void setName (String nm) {
- this.name = nm;
- }
-
- public String getName () {
- return this.name;
- }
-
- public void setEmail (String mail) {
- this.email = mail;
- }
-
- public String getEmail () {
- return this.email;
- }
-
- public String getDate () {
- return this.date;
- }
-
- public Entries getEntries () {
- return this.entries;
- }
-
- public void processRequest (HttpServletRequest request) {
-
- // Get the name and e-mail.
- this.processError = false;
- if (name == null || name.equals("")) setName(request.getParameter ("name"));
- if (email == null || email.equals("")) setEmail(request.getParameter ("email"));
- if (name == null || email == null ||
- name.equals("") || email.equals("")) {
- this.processError = true;
- return;
+ public TableBean() {
+ this.table = new Hashtable<String, Entries>(10);
+ this.JspCal = new JspCalendar();
+ this.date = JspCal.getCurrentDate();
}
- // Get the date.
- String dateR = request.getParameter ("date");
- if (dateR == null) date = JspCal.getCurrentDate ();
- else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate ();
- else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate ();
-
- entries = (Entries) table.get (date);
- if (entries == null) {
- entries = new Entries ();
- table.put (date, entries);
+ public void setName(String nm) {
+ this.name = nm;
}
- // If time is provided add the event.
- String time = request.getParameter("time");
- if (time != null) entries.processRequest (request, time);
- }
+ public String getName() {
+ return this.name;
+ }
- public boolean getProcessError () {
- return this.processError;
- }
+ public void setEmail(String mail) {
+ this.email = mail;
+ }
+
+ public String getEmail() {
+ return this.email;
+ }
+
+ public String getDate() {
+ return this.date;
+ }
+
+ public Entries getEntries() {
+ return this.entries;
+ }
+
+ public void processRequest(HttpServletRequest request) {
+
+ // Get the name and e-mail.
+ this.processError = false;
+ if (name == null || name.equals(""))
+ setName(request.getParameter("name"));
+ if (email == null || email.equals(""))
+ setEmail(request.getParameter("email"));
+ if (name == null || email == null || name.equals("")
+ || email.equals("")) {
+ this.processError = true;
+ return;
+ }
+
+ // Get the date.
+ String dateR = request.getParameter("date");
+ if (dateR == null)
+ date = JspCal.getCurrentDate();
+ else if (dateR.equalsIgnoreCase("next"))
+ date = JspCal.getNextDate();
+ else if (dateR.equalsIgnoreCase("prev"))
+ date = JspCal.getPrevDate();
+
+ entries = table.get(date);
+ if (entries == null) {
+ entries = new Entries();
+ table.put(date, entries);
+ }
+
+ // If time is provided add the event.
+ String time = request.getParameter("time");
+ if (time != null)
+ entries.processRequest(request, time);
+ }
+
+ public boolean getProcessError() {
+ return this.processError;
+ }
}
-
-
-
-
-
-
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp b/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp
index a691df4..db78a03 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp
+++ b/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp
@@ -1,5 +1,4 @@
-<HTML>
-<!--
+<%--
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.
@@ -14,9 +13,10 @@
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.
--->
-<HEAD><TITLE>
- Calendar: A JSP APPLICATION
+--%>
+<HTML>
+<HEAD><TITLE>
+ Calendar: A JSP APPLICATION
</TITLE></HEAD>
@@ -26,8 +26,8 @@
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<%
- table.processRequest(request);
- if (table.getProcessError() == false) {
+ table.processRequest(request);
+ if (table.getProcessError() == false) {
%>
<!-- html table goes here -->
@@ -48,20 +48,20 @@
</TR>
<FORM METHOD=POST ACTION=cal1.jsp>
<%
- for(int i=0; i<table.getEntries().getRows(); i++) {
- cal.Entry entr = table.getEntries().getEntry(i);
+ for(int i=0; i<table.getEntries().getRows(); i++) {
+ cal.Entry entr = table.getEntries().getEntry(i);
%>
- <TR>
- <TD>
- <A HREF=cal2.jsp?time=<%= entr.getHour() %>>
- <%= entr.getHour() %> </A>
- </TD>
- <TD BGCOLOR=<%= entr.getColor() %>>
- <% out.print(util.HTMLFilter.filter(entr.getDescription())); %>
- </TD>
- </TR>
+ <TR>
+ <TD>
+ <A HREF=cal2.jsp?time=<%= entr.getHour() %>>
+ <%= entr.getHour() %> </A>
+ </TD>
+ <TD BGCOLOR=<%= entr.getColor() %>>
+ <% out.print(util.HTMLFilter.filter(entr.getDescription())); %>
+ </TD>
+ </TR>
<%
- }
+ }
%>
</FORM>
</TABLE>
@@ -70,20 +70,20 @@
<!-- footer -->
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
-<TD ALIGN=CENTER> <% out.print(util.HTMLFilter.filter(table.getName())); %> :
- <% out.print(util.HTMLFilter.filter(table.getEmail())); %> </TD>
+<TD ALIGN=CENTER> <% out.print(util.HTMLFilter.filter(table.getName())); %> :
+ <% out.print(util.HTMLFilter.filter(table.getEmail())); %> </TD>
</TR>
</TABLE>
</CENTER>
<%
- } else {
+ } else {
%>
<font size=5>
- You must enter your name and email address correctly.
+ You must enter your name and email address correctly.
</font>
<%
- }
+ }
%>
@@ -91,5 +91,3 @@
</HTML>
-
-
diff --git a/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp.html b/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp.html
index f9c3689..e83627c 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/cal1.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<HTML>
-<!--
+<%--
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.
@@ -15,9 +14,10 @@
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.
--->
-<HEAD><TITLE>
- Calendar: A JSP APPLICATION
+--%>
+<HTML>
+<HEAD><TITLE>
+ Calendar: A JSP APPLICATION
</TITLE></HEAD>
@@ -27,8 +27,8 @@
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<%
- table.processRequest(request);
- if (table.getProcessError() == false) {
+ table.processRequest(request);
+ if (table.getProcessError() == false) {
%>
<!-- html table goes here -->
@@ -49,20 +49,20 @@
</TR>
<FORM METHOD=POST ACTION=cal1.jsp>
<%
- for(int i=0; i<table.getEntries().getRows(); i++) {
- cal.Entry entr = table.getEntries().getEntry(i);
+ for(int i=0; i<table.getEntries().getRows(); i++) {
+ cal.Entry entr = table.getEntries().getEntry(i);
%>
- <TR>
- <TD>
- <A HREF=cal2.jsp?time=<%= entr.getHour() %>>
- <%= entr.getHour() %> </A>
- </TD>
- <TD BGCOLOR=<%= entr.getColor() %>>
- <% out.print(util.HTMLFilter.filter(entr.getDescription())); %>
- </TD>
- </TR>
+ <TR>
+ <TD>
+ <A HREF=cal2.jsp?time=<%= entr.getHour() %>>
+ <%= entr.getHour() %> </A>
+ </TD>
+ <TD BGCOLOR=<%= entr.getColor() %>>
+ <% out.print(util.HTMLFilter.filter(entr.getDescription())); %>
+ </TD>
+ </TR>
<%
- }
+ }
%>
</FORM>
</TABLE>
@@ -71,20 +71,20 @@
<!-- footer -->
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
-<TD ALIGN=CENTER> <% out.print(util.HTMLFilter.filter(table.getName())); %> :
- <% out.print(util.HTMLFilter.filter(table.getEmail())); %> </TD>
+<TD ALIGN=CENTER> <% out.print(util.HTMLFilter.filter(table.getName())); %> :
+ <% out.print(util.HTMLFilter.filter(table.getEmail())); %> </TD>
</TR>
</TABLE>
</CENTER>
<%
- } else {
+ } else {
%>
<font size=5>
- You must enter your name and email address correctly.
+ You must enter your name and email address correctly.
</font>
<%
- }
+ }
%>
@@ -92,6 +92,4 @@
</HTML>
-
-
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp b/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp
index b6d435b..b508870 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp
+++ b/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp
@@ -1,5 +1,4 @@
-<HTML>
-<!--
+<%--
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.
@@ -14,18 +13,18 @@
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.
--->
-
-<HEAD><TITLE>
- Calendar: A JSP APPLICATION
+--%>
+<HTML>
+<HEAD><TITLE>
+ Calendar: A JSP APPLICATION
</TITLE></HEAD>
<BODY BGCOLOR="white">
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
-<%
- String time = request.getParameter ("time");
+<%
+ String time = request.getParameter ("time");
%>
<FONT SIZE=5> Please add the following event:
@@ -33,7 +32,7 @@
<BR> Time <%= util.HTMLFilter.filter(time) %> </h3>
</FONT>
<FORM METHOD=POST ACTION=cal1.jsp>
-<BR>
+<BR>
<BR> <INPUT NAME="date" TYPE=HIDDEN VALUE="current">
<BR> <INPUT NAME="time" TYPE=HIDDEN VALUE="<%= util.HTMLFilter.filter(time) %>">
<BR> <h2> Description of the event <INPUT NAME="description" TYPE=TEXT SIZE=20> </h2>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp.html b/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp.html
index 2548ce7..270c8b0 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/cal2.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<HTML>
-<!--
+<%--
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.
@@ -15,18 +14,18 @@
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.
--->
-
-<HEAD><TITLE>
- Calendar: A JSP APPLICATION
+--%>
+<HTML>
+<HEAD><TITLE>
+ Calendar: A JSP APPLICATION
</TITLE></HEAD>
<BODY BGCOLOR="white">
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
-<%
- String time = request.getParameter ("time");
+<%
+ String time = request.getParameter ("time");
%>
<FONT SIZE=5> Please add the following event:
@@ -34,7 +33,7 @@
<BR> Time <%= util.HTMLFilter.filter(time) %> </h3>
</FONT>
<FORM METHOD=POST ACTION=cal1.jsp>
-<BR>
+<BR>
<BR> <INPUT NAME="date" TYPE=HIDDEN VALUE="current">
<BR> <INPUT NAME="time" TYPE=HIDDEN VALUE="<%= util.HTMLFilter.filter(time) %>">
<BR> <h2> Description of the event <INPUT NAME="description" TYPE=TEXT SIZE=20> </h2>
diff --git a/tomcat-cas/webapps/examples/jsp/cal/login.html b/tomcat-cas/webapps/examples/jsp/cal/login.html
index 398b39b..b1105d5 100644
--- a/tomcat-cas/webapps/examples/jsp/cal/login.html
+++ b/tomcat-cas/webapps/examples/jsp/cal/login.html
@@ -17,30 +17,30 @@
-->
<head>
- <title> Login page for the calendar. </title>
+ <title> Login page for the calendar. </title>
</head>
<body bgcolor="white">
<center>
- <font size=7 color="red"> Please Enter the following information: </font>
+ <font size=7 color="red"> Please Enter the following information: </font>
<br>
- <form method=GET action=cal1.jsp>
+ <form method=GET action=cal1.jsp>
- <font size=5> Name <input type=text name="name" size=20>
- </font>
- <br>
- <font size=5> Email <input type=text name="email" size=20>
- </font>
- <br>
- <input type=submit name=action value="Submit">
+ <font size=5> Name <input type=text name="name" size=20>
+ </font>
+ <br>
+ <font size=5> Email <input type=text name="email" size=20>
+ </font>
+ <br>
+ <input type=submit name=action value="Submit">
- </form>
+ </form>
<hr>
-<font size=3 color="red"> Note: This application does not implement the complete
-functionality of a typical calendar application. It demonstrates a way JSP can be
-used with html tables and forms.</font>
+<font size=3 color="red"> Note: This application does not implement the complete
+functionality of a typical calendar application. It demonstrates a way JSP can
+be used with html tables and forms.</font>
</center>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp b/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp
index db87ca1..5df7b66 100644
--- a/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp
+++ b/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,8 +13,8 @@
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.
--->
-
+--%>
+<html>
<body bgcolor="white">
<font size=5 color="red">
<%! String[] fruits; %>
@@ -24,19 +23,19 @@
<jsp:setProperty name="foo" property="fruit" param="fruit" />
<hr>
The checked fruits (got using request) are: <br>
-<%
- fruits = request.getParameterValues("fruit");
+<%
+ fruits = request.getParameterValues("fruit");
%>
<ul>
<%
if (fruits != null) {
- for (int i = 0; i < fruits.length; i++) {
+ for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
- out.println (util.HTMLFilter.filter(fruits[i]));
- }
- } else out.println ("none selected");
+ out.println (util.HTMLFilter.filter(fruits[i]));
+ }
+ } else out.println ("none selected");
%>
</ul>
<br>
@@ -44,19 +43,19 @@
The checked fruits (got using beans) are <br>
-<%
- fruits = foo.getFruit();
+<%
+ fruits = foo.getFruit();
%>
<ul>
<%
if (!fruits[0].equals("1")) {
- for (int i = 0; i < fruits.length; i++) {
+ for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
- out.println (util.HTMLFilter.filter(fruits[i]));
- }
- } else out.println ("none selected");
+ out.println (util.HTMLFilter.filter(fruits[i]));
+ }
+ } else out.println ("none selected");
%>
</ul>
</font>
diff --git a/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp.html b/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp.html
index d5442d1..5daab63 100644
--- a/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/checkbox/checkresult.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,8 +14,8 @@
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.
--->
-
+--%>
+<html>
<body bgcolor="white">
<font size=5 color="red">
<%! String[] fruits; %>
@@ -25,19 +24,19 @@
<jsp:setProperty name="foo" property="fruit" param="fruit" />
<hr>
The checked fruits (got using request) are: <br>
-<%
- fruits = request.getParameterValues("fruit");
+<%
+ fruits = request.getParameterValues("fruit");
%>
<ul>
<%
if (fruits != null) {
- for (int i = 0; i < fruits.length; i++) {
+ for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
- out.println (util.HTMLFilter.filter(fruits[i]));
- }
- } else out.println ("none selected");
+ out.println (util.HTMLFilter.filter(fruits[i]));
+ }
+ } else out.println ("none selected");
%>
</ul>
<br>
@@ -45,19 +44,19 @@
The checked fruits (got using beans) are <br>
-<%
- fruits = foo.getFruit();
+<%
+ fruits = foo.getFruit();
%>
<ul>
<%
if (!fruits[0].equals("1")) {
- for (int i = 0; i < fruits.length; i++) {
+ for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
- out.println (util.HTMLFilter.filter(fruits[i]));
- }
- } else out.println ("none selected");
+ out.println (util.HTMLFilter.filter(fruits[i]));
+ }
+ } else out.println ("none selected");
%>
</ul>
</font>
diff --git a/tomcat-cas/webapps/examples/jsp/colors/colors.html b/tomcat-cas/webapps/examples/jsp/colors/colors.html
index 086738d..76ec2b9 100644
--- a/tomcat-cas/webapps/examples/jsp/colors/colors.html
+++ b/tomcat-cas/webapps/examples/jsp/colors/colors.html
@@ -20,16 +20,16 @@
<font size=6 color=red>
<hr>
-This web page is an example using JSP and BEANs.
+This web page is an example using JSP and BEANs.
<p>
-Guess my favorite two colors
+Guess my favorite two colors
<p> If you fail to guess both of them - you get yellow on red.
-<p> If you guess one of them right, either your foreground or
+<p> If you guess one of them right, either your foreground or
your background will change to the color that was guessed right.
-<p> Guess them both right and your browser foreground/background
+<p> Guess them both right and your browser foreground/background
will change to my two favorite colors to display this page.
<hr>
diff --git a/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp b/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp
index e433bbd..90e1afe 100644
--- a/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp
+++ b/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,13 +13,14 @@
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.
--->
+--%>
+<html>
<jsp:useBean id="cb" scope="session" class="colors.ColorGameBean" />
<jsp:setProperty name="cb" property="*" />
<%
- cb.processRequest(request);
+ cb.processRequest();
%>
<body bgcolor=<%= cb.getColor1() %>>
@@ -28,20 +28,20 @@
<p>
<% if (cb.getHint()==true) { %>
-
- <p> Hint #1: Vampires prey at night!
- <p> <p> Hint #2: Nancy without the n.
+
+ <p> Hint #1: Vampires prey at night!
+ <p> <p> Hint #2: Nancy without the n.
<% } %>
<% if (cb.getSuccess()==true) { %>
<p> CONGRATULATIONS!!
- <% if (cb.getHintTaken()==true) { %>
-
+ <% if (cb.getHintTaken()==true) { %>
+
<p> ( although I know you cheated and peeked into the hints)
- <% } %>
+ <% } %>
<% } %>
diff --git a/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp.html b/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp.html
index 41af88b..fda1bd7 100644
--- a/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/colors/colrs.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,13 +14,14 @@
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.
--->
+--%>
+<html>
<jsp:useBean id="cb" scope="session" class="colors.ColorGameBean" />
<jsp:setProperty name="cb" property="*" />
<%
- cb.processRequest(request);
+ cb.processRequest();
%>
<body bgcolor=<%= cb.getColor1() %>>
@@ -29,20 +29,20 @@
<p>
<% if (cb.getHint()==true) { %>
-
- <p> Hint #1: Vampires prey at night!
- <p> <p> Hint #2: Nancy without the n.
+
+ <p> Hint #1: Vampires prey at night!
+ <p> <p> Hint #2: Nancy without the n.
<% } %>
<% if (cb.getSuccess()==true) { %>
<p> CONGRATULATIONS!!
- <% if (cb.getHintTaken()==true) { %>
-
+ <% if (cb.getHintTaken()==true) { %>
+
<p> ( although I know you cheated and peeked into the hints)
- <% } %>
+ <% } %>
<% } %>
diff --git a/tomcat-cas/webapps/examples/jsp/dates/date.jsp b/tomcat-cas/webapps/examples/jsp/dates/date.jsp
index 9c40d78..7f47dc9 100644
--- a/tomcat-cas/webapps/examples/jsp/dates/date.jsp
+++ b/tomcat-cas/webapps/examples/jsp/dates/date.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,7 +13,8 @@
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.
--->
+--%>
+<html>
<%@ page session="false"%>
@@ -23,17 +23,17 @@
<font size=4>
<ul>
-<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
-<li> Year: is <jsp:getProperty name="clock" property="year"/>
-<li> Month: is <jsp:getProperty name="clock" property="month"/>
-<li> Time: is <jsp:getProperty name="clock" property="time"/>
-<li> Date: is <jsp:getProperty name="clock" property="date"/>
-<li> Day: is <jsp:getProperty name="clock" property="day"/>
-<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
-<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
-<li> era: is <jsp:getProperty name="clock" property="era"/>
-<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
-<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
+<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
+<li> Year: is <jsp:getProperty name="clock" property="year"/>
+<li> Month: is <jsp:getProperty name="clock" property="month"/>
+<li> Time: is <jsp:getProperty name="clock" property="time"/>
+<li> Date: is <jsp:getProperty name="clock" property="date"/>
+<li> Day: is <jsp:getProperty name="clock" property="day"/>
+<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
+<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
+<li> era: is <jsp:getProperty name="clock" property="era"/>
+<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
+<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
</ul>
</font>
diff --git a/tomcat-cas/webapps/examples/jsp/dates/date.jsp.html b/tomcat-cas/webapps/examples/jsp/dates/date.jsp.html
index 4a8f1e9..c7eb8d5 100644
--- a/tomcat-cas/webapps/examples/jsp/dates/date.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/dates/date.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,7 +14,8 @@
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.
--->
+--%>
+<html>
<%@ page session="false"%>
@@ -24,17 +24,17 @@
<font size=4>
<ul>
-<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
-<li> Year: is <jsp:getProperty name="clock" property="year"/>
-<li> Month: is <jsp:getProperty name="clock" property="month"/>
-<li> Time: is <jsp:getProperty name="clock" property="time"/>
-<li> Date: is <jsp:getProperty name="clock" property="date"/>
-<li> Day: is <jsp:getProperty name="clock" property="day"/>
-<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
-<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
-<li> era: is <jsp:getProperty name="clock" property="era"/>
-<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
-<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
+<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
+<li> Year: is <jsp:getProperty name="clock" property="year"/>
+<li> Month: is <jsp:getProperty name="clock" property="month"/>
+<li> Time: is <jsp:getProperty name="clock" property="time"/>
+<li> Date: is <jsp:getProperty name="clock" property="date"/>
+<li> Day: is <jsp:getProperty name="clock" property="day"/>
+<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
+<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
+<li> era: is <jsp:getProperty name="clock" property="era"/>
+<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
+<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
</ul>
</font>
diff --git a/tomcat-cas/webapps/examples/jsp/error/err.jsp b/tomcat-cas/webapps/examples/jsp/error/err.jsp
index 08030b0..956da8e 100644
--- a/tomcat-cas/webapps/examples/jsp/error/err.jsp
+++ b/tomcat-cas/webapps/examples/jsp/error/err.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,31 +13,32 @@
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.
--->
+--%>
+<html>
<body bgcolor="lightblue">
- <%@ page errorPage="errorpge.jsp" %>
- <jsp:useBean id="foo" scope="request" class="error.Smart" />
- <%
- String name = null;
+ <%@ page errorPage="errorpge.jsp" %>
+ <jsp:useBean id="foo" scope="request" class="error.Smart" />
+ <%
+ String name = null;
- if (request.getParameter("name") == null) {
- %>
- <%@ include file="error.html" %>
- <%
- } else {
- foo.setName(request.getParameter("name"));
- if (foo.getName().equalsIgnoreCase("integra"))
- name = "acura";
- if (name.equalsIgnoreCase("acura")) {
- %>
+ if (request.getParameter("name") == null) {
+ %>
+ <%@ include file="error.html" %>
+ <%
+ } else {
+ foo.setName(request.getParameter("name"));
+ if (foo.getName().equalsIgnoreCase("integra"))
+ name = "acura";
+ if (name.equalsIgnoreCase("acura")) {
+ %>
- <H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
+ <H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
- <%
- }
- }
- %>
+ <%
+ }
+ }
+ %>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/error/err.jsp.html b/tomcat-cas/webapps/examples/jsp/error/err.jsp.html
index 65b5654..8f0727d 100644
--- a/tomcat-cas/webapps/examples/jsp/error/err.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/error/err.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,31 +14,32 @@
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.
--->
+--%>
+<html>
<body bgcolor="lightblue">
- <%@ page errorPage="errorpge.jsp" %>
- <jsp:useBean id="foo" scope="request" class="error.Smart" />
- <%
- String name = null;
+ <%@ page errorPage="errorpge.jsp" %>
+ <jsp:useBean id="foo" scope="request" class="error.Smart" />
+ <%
+ String name = null;
- if (request.getParameter("name") == null) {
- %>
- <%@ include file="error.html" %>
- <%
- } else {
- foo.setName(request.getParameter("name"));
- if (foo.getName().equalsIgnoreCase("integra"))
- name = "acura";
- if (name.equalsIgnoreCase("acura")) {
- %>
+ if (request.getParameter("name") == null) {
+ %>
+ <%@ include file="error.html" %>
+ <%
+ } else {
+ foo.setName(request.getParameter("name"));
+ if (foo.getName().equalsIgnoreCase("integra"))
+ name = "acura";
+ if (name.equalsIgnoreCase("acura")) {
+ %>
- <H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
+ <H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
- <%
- }
- }
- %>
+ <%
+ }
+ }
+ %>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp b/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp
index 113c204..dda6fbd 100644
--- a/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp
+++ b/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,12 +13,13 @@
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.
--->
+--%>
+<html>
<body bgcolor="red">
- <%@ page isErrorPage="true" %>
- <h1> The exception <%= exception.getMessage() %> tells me you
- made a wrong choice.
+ <%@ page isErrorPage="true" %>
+ <h1> The exception <%= exception.getMessage() %> tells me you
+ made a wrong choice.
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp.html b/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp.html
index 69bf244..cfb6fcf 100644
--- a/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/error/errorpge.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,13 +14,14 @@
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.
--->
+--%>
+<html>
<body bgcolor="red">
- <%@ page isErrorPage="true" %>
- <h1> The exception <%= exception.getMessage() %> tells me you
- made a wrong choice.
+ <%@ page isErrorPage="true" %>
+ <h1> The exception <%= exception.getMessage() %> tells me you
+ made a wrong choice.
</body>
</html>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/forward/forward.jsp b/tomcat-cas/webapps/examples/jsp/forward/forward.jsp
index 8e2ceab..4ee56a2 100644
--- a/tomcat-cas/webapps/examples/jsp/forward/forward.jsp
+++ b/tomcat-cas/webapps/examples/jsp/forward/forward.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,13 +13,13 @@
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.
--->
-
-<%
+--%>
+<html>
+<%
double freeMem = Runtime.getRuntime().freeMemory();
double totlMem = Runtime.getRuntime().totalMemory();
double percent = freeMem/totlMem;
- if (percent < 0.5) {
+ if (percent < 0.5) {
%>
<jsp:forward page="one.jsp"/>
diff --git a/tomcat-cas/webapps/examples/jsp/forward/forward.jsp.html b/tomcat-cas/webapps/examples/jsp/forward/forward.jsp.html
index 9f0a563..904ea8a 100644
--- a/tomcat-cas/webapps/examples/jsp/forward/forward.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/forward/forward.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,13 +14,13 @@
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.
--->
-
-<%
+--%>
+<html>
+<%
double freeMem = Runtime.getRuntime().freeMemory();
double totlMem = Runtime.getRuntime().totalMemory();
double percent = freeMem/totlMem;
- if (percent < 0.5) {
+ if (percent < 0.5) {
%>
<jsp:forward page="one.jsp"/>
diff --git a/tomcat-cas/webapps/examples/jsp/forward/one.jsp b/tomcat-cas/webapps/examples/jsp/forward/one.jsp
index 90297b7..41cb8b8 100644
--- a/tomcat-cas/webapps/examples/jsp/forward/one.jsp
+++ b/tomcat-cas/webapps/examples/jsp/forward/one.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,10 +13,11 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
<font color="red">
-VM Memory usage < 50%.
+VM Memory usage < 50%.
</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/jsp/forward/one.jsp.html b/tomcat-cas/webapps/examples/jsp/forward/one.jsp.html
index 7cb77a0..2d6d4e4 100644
--- a/tomcat-cas/webapps/examples/jsp/forward/one.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/forward/one.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,11 +14,12 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
<font color="red">
-VM Memory usage < 50%.
+VM Memory usage &lt; 50%.
</html>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/forward/two.html b/tomcat-cas/webapps/examples/jsp/forward/two.html
index 4bc9402..b6ea4f9 100644
--- a/tomcat-cas/webapps/examples/jsp/forward/two.html
+++ b/tomcat-cas/webapps/examples/jsp/forward/two.html
@@ -19,5 +19,5 @@
<body bgcolor="white">
<font color="red">
-VM Memory usage > 50%.
+VM Memory usage > 50%.
</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/jsp/include/foo.jsp b/tomcat-cas/webapps/examples/jsp/include/foo.jsp
index ce4101b..f909fa3 100644
--- a/tomcat-cas/webapps/examples/jsp/include/foo.jsp
+++ b/tomcat-cas/webapps/examples/jsp/include/foo.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,9 +13,5 @@
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.
--->
-<body bgcolor="white">
-<font color="red">
-
-<%= System.currentTimeMillis() %>
+--%><%= System.currentTimeMillis() %>
diff --git a/tomcat-cas/webapps/examples/jsp/include/foo.jsp.html b/tomcat-cas/webapps/examples/jsp/include/foo.jsp.html
index 638d41d..4bbaeb3 100644
--- a/tomcat-cas/webapps/examples/jsp/include/foo.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/include/foo.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,10 +14,6 @@
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.
--->
-<body bgcolor="white">
-<font color="red">
-
-<%= System.currentTimeMillis() %>
+--%><%= System.currentTimeMillis() %>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/include/include.jsp b/tomcat-cas/webapps/examples/jsp/include/include.jsp
index 34fd6c3..92655d1 100644
--- a/tomcat-cas/webapps/examples/jsp/include/include.jsp
+++ b/tomcat-cas/webapps/examples/jsp/include/include.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,7 +13,8 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
@@ -22,14 +22,9 @@
<%@ page buffer="5kb" autoFlush="false" %>
-<p>In place evaluation of another JSP which gives you the current time:
+<p>In place evaluation of another JSP which gives you the current time: <%@ include file="foo.jsp" %>
-<%@ include file="foo.jsp" %>
-
-<p> <jsp:include page="foo.html" flush="true"/> by including the output of another JSP:
-
-<jsp:include page="foo.jsp" flush="true"/>
-
-:-)
+<p> <jsp:include page="foo.html" flush="true"/> by including the output of another JSP: <jsp:include page="foo.jsp" flush="true"/>
+:-)
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/include/include.jsp.html b/tomcat-cas/webapps/examples/jsp/include/include.jsp.html
index f45c300..035b57a 100644
--- a/tomcat-cas/webapps/examples/jsp/include/include.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/include/include.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,7 +14,8 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
@@ -23,15 +23,10 @@
<%@ page buffer="5kb" autoFlush="false" %>
-<p>In place evaluation of another JSP which gives you the current time:
+<p>In place evaluation of another JSP which gives you the current time: <%@ include file="foo.jsp" %>
-<%@ include file="foo.jsp" %>
-
-<p> <jsp:include page="foo.html" flush="true"/> by including the output of another JSP:
-
-<jsp:include page="foo.jsp" flush="true"/>
-
-:-)
+<p> <jsp:include page="foo.html" flush="true"/> by including the output of another JSP: <jsp:include page="foo.jsp" flush="true"/>
+:-)
</html>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/index.html b/tomcat-cas/webapps/examples/jsp/index.html
index c41acf2..c6b1c43 100644
--- a/tomcat-cas/webapps/examples/jsp/index.html
+++ b/tomcat-cas/webapps/examples/jsp/index.html
@@ -103,6 +103,14 @@
</tr>
<tr valign=TOP>
+<td>Composite Expressions</td>
+<td valign=TOP width="30%"><a href="jsp2/el/composite.jsp"><img src="images/execute.gif" hspace=4 border=0 align=top></a><a href="jsp2/el/composite.jsp">Execute</a></td>
+
+<td width="30%"><a href="jsp2/el/composite.html"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="jsp2/el/composite.html">Source</a></td>
+</tr>
+
+
+<tr valign=TOP>
<td><br><b>SimpleTag Handlers and JSP Fragments</b></td>
</tr>
@@ -327,7 +335,7 @@
<tr VALIGN=TOP>
<td>If </td>
<td VALIGN=TOP WIDTH="30%">
- <a href="tagplugin/if.jsp"><img SRC="images/execute.gif" HSPACE=4 BORDER=0
+ <a href="tagplugin/if.jsp"><img SRC="images/execute.gif" HSPACE=4 BORDER=0
align=TOP></a>
<a href="tagplugin/if.jsp">Execute</a>
</td>
@@ -341,7 +349,7 @@
<tr VALIGN=TOP>
<td>ForEach </td>
<td VALIGN=TOP WIDTH="30%">
- <a href="tagplugin/foreach.jsp"><img SRC="images/execute.gif" HSPACE=4 BORDER=0
+ <a href="tagplugin/foreach.jsp"><img SRC="images/execute.gif" HSPACE=4 BORDER=0
align=TOP></a>
<a href="tagplugin/foreach.jsp">Execute</a>
</td>
@@ -366,5 +374,24 @@
</table>
+<br/>
+<b><u><font size="+1">Other Examples</font></u></b><br>
+<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
+
+<tr VALIGN=TOP>
+ <td>FORM Authentication </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="security/protected/index.jsp"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+<tr>
+ <td colspan="3">Example that demonstrates protecting a resource and
+ using Form-Based authentication. To access the page the user must
+ have role of either "tomcat" or "role1". By default no user
+ is configured to have these roles.</td>
+</tr>
+
+</table>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/Functions.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/Functions.java.html
index 350fce6..91abc75 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/Functions.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/Functions.java.html
@@ -17,29 +17,31 @@
*/
package jsp2.examples.el;
+import java.util.Locale;
+
/**
* Defines the functions for the jsp2 example tag library.
- *
+ *
* <p>Each function is defined as a static method.</p>
*/
public class Functions {
public static String reverse( String text ) {
- return new StringBuffer( text ).reverse().toString();
+ return new StringBuilder( text ).reverse().toString();
}
public static int numVowels( String text ) {
String vowels = "aeiouAEIOU";
- int result = 0;
+ int result = 0;
for( int i = 0; i < text.length(); i++ ) {
- if( vowels.indexOf( text.charAt( i ) ) != -1 ) {
- result++;
- }
- }
- return result;
+ if( vowels.indexOf( text.charAt( i ) ) != -1 ) {
+ result++;
+ }
+ }
+ return result;
}
public static String caps( String text ) {
- return text.toUpperCase();
+ return text.toUpperCase(Locale.ENGLISH);
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/ValuesBean.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/ValuesBean.java.html
new file mode 100644
index 0000000..beadf72
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/ValuesBean.java.html
@@ -0,0 +1,54 @@
+<html><body><pre>
+/*
+* 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 jsp2.examples;
+
+/**
+ * Accept and display a value.
+ */
+public class ValuesBean {
+ private String string;
+ private double doubleValue;
+ private long longValue;
+
+ public String getStringValue() {
+ return this.string;
+ }
+
+ public void setStringValue(String string) {
+ this.string = string;
+ }
+
+ public double getDoubleValue() {
+ return doubleValue;
+ }
+
+ public void setDoubleValue(double doubleValue) {
+ this.doubleValue = doubleValue;
+ }
+
+ public long getLongValue() {
+ return longValue;
+ }
+
+ public void setLongValue(long longValue) {
+ this.longValue = longValue;
+ }
+}
+</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/ValuesTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/ValuesTag.java.html
new file mode 100644
index 0000000..16f62ab
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/ValuesTag.java.html
@@ -0,0 +1,81 @@
+<html><body><pre>
+/*
+ * 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 examples;
+
+import java.io.IOException;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.TagSupport;
+
+/**
+ * Accept and display a value.
+ */
+public class ValuesTag extends TagSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ // Using "-1" as the default value,
+ // in the assumption that it won't be used as the value.
+ // Cannot use null here, because null is an important case
+ // that should be present in the tests.
+ private Object objectValue = "-1";
+ private String stringValue = "-1";
+ private long longValue = -1;
+ private double doubleValue = -1;
+
+ public void setObject(Object objectValue) {
+ this.objectValue = objectValue;
+ }
+
+ public void setString(String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+ public void setLong(long longValue) {
+ this.longValue = longValue;
+ }
+
+ public void setDouble(double doubleValue) {
+ this.doubleValue = doubleValue;
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ JspWriter out = pageContext.getOut();
+
+ try {
+ if (!"-1".equals(objectValue)) {
+ out.print(objectValue);
+ } else if (!"-1".equals(stringValue)) {
+ out.print(stringValue);
+ } else if (longValue != -1) {
+ out.print(longValue);
+ } else if (doubleValue != -1) {
+ out.print(doubleValue);
+ } else {
+ out.print("-1");
+ }
+ } catch (IOException ex) {
+ throw new JspTagException("IOException: " + ex.toString(), ex);
+ }
+ return super.doEndTag();
+ }
+}
+</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp
index e2ec74c..a3b3e7a 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>JSP 2.0 Expression Language - Basic Arithmetic</title>
@@ -22,7 +22,7 @@
<h1>JSP 2.0 Expression Language - Basic Arithmetic</h1>
<hr>
This example illustrates basic Expression Language arithmetic.
- Addition (+), subtraction (-), multiplication (*), division (/ or div),
+ Addition (+), subtraction (-), multiplication (*), division (/ or div),
and modulus (% or mod) are all supported. Error conditions, like
division by zero, are handled gracefully.
<br>
@@ -30,58 +30,58 @@
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${1}</td>
- <td>${1}</td>
- </tr>
- <tr>
- <td>\${1 + 2}</td>
- <td>${1 + 2}</td>
- </tr>
- <tr>
- <td>\${1.2 + 2.3}</td>
- <td>${1.2 + 2.3}</td>
- </tr>
- <tr>
- <td>\${1.2E4 + 1.4}</td>
- <td>${1.2E4 + 1.4}</td>
- </tr>
- <tr>
- <td>\${-4 - 2}</td>
- <td>${-4 - 2}</td>
- </tr>
- <tr>
- <td>\${21 * 2}</td>
- <td>${21 * 2}</td>
- </tr>
- <tr>
- <td>\${3/4}</td>
- <td>${3/4}</td>
- </tr>
- <tr>
- <td>\${3 div 4}</td>
- <td>${3 div 4}</td>
- </tr>
- <tr>
- <td>\${3/0}</td>
- <td>${3/0}</td>
- </tr>
- <tr>
- <td>\${10%4}</td>
- <td>${10%4}</td>
- </tr>
- <tr>
- <td>\${10 mod 4}</td>
- <td>${10 mod 4}</td>
- </tr>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${1}</td>
+ <td>${1}</td>
+ </tr>
+ <tr>
+ <td>\${1 + 2}</td>
+ <td>${1 + 2}</td>
+ </tr>
+ <tr>
+ <td>\${1.2 + 2.3}</td>
+ <td>${1.2 + 2.3}</td>
+ </tr>
+ <tr>
+ <td>\${1.2E4 + 1.4}</td>
+ <td>${1.2E4 + 1.4}</td>
+ </tr>
+ <tr>
+ <td>\${-4 - 2}</td>
+ <td>${-4 - 2}</td>
+ </tr>
+ <tr>
+ <td>\${21 * 2}</td>
+ <td>${21 * 2}</td>
+ </tr>
+ <tr>
+ <td>\${3/4}</td>
+ <td>${3/4}</td>
+ </tr>
+ <tr>
+ <td>\${3 div 4}</td>
+ <td>${3 div 4}</td>
+ </tr>
+ <tr>
+ <td>\${3/0}</td>
+ <td>${3/0}</td>
+ </tr>
+ <tr>
+ <td>\${10%4}</td>
+ <td>${10%4}</td>
+ </tr>
+ <tr>
+ <td>\${10 mod 4}</td>
+ <td>${10 mod 4}</td>
+ </tr>
<tr>
<td>\${(1==2) ? 3 : 4}</td>
<td>${(1==2) ? 3 : 4}</td>
</tr>
- </table>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp.html
index 4aa05c8..e703cde 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>JSP 2.0 Expression Language - Basic Arithmetic</title>
@@ -23,7 +23,7 @@
<h1>JSP 2.0 Expression Language - Basic Arithmetic</h1>
<hr>
This example illustrates basic Expression Language arithmetic.
- Addition (+), subtraction (-), multiplication (*), division (/ or div),
+ Addition (+), subtraction (-), multiplication (*), division (/ or div),
and modulus (% or mod) are all supported. Error conditions, like
division by zero, are handled gracefully.
<br>
@@ -31,58 +31,58 @@
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${1}</td>
- <td>${1}</td>
- </tr>
- <tr>
- <td>\${1 + 2}</td>
- <td>${1 + 2}</td>
- </tr>
- <tr>
- <td>\${1.2 + 2.3}</td>
- <td>${1.2 + 2.3}</td>
- </tr>
- <tr>
- <td>\${1.2E4 + 1.4}</td>
- <td>${1.2E4 + 1.4}</td>
- </tr>
- <tr>
- <td>\${-4 - 2}</td>
- <td>${-4 - 2}</td>
- </tr>
- <tr>
- <td>\${21 * 2}</td>
- <td>${21 * 2}</td>
- </tr>
- <tr>
- <td>\${3/4}</td>
- <td>${3/4}</td>
- </tr>
- <tr>
- <td>\${3 div 4}</td>
- <td>${3 div 4}</td>
- </tr>
- <tr>
- <td>\${3/0}</td>
- <td>${3/0}</td>
- </tr>
- <tr>
- <td>\${10%4}</td>
- <td>${10%4}</td>
- </tr>
- <tr>
- <td>\${10 mod 4}</td>
- <td>${10 mod 4}</td>
- </tr>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${1}</td>
+ <td>${1}</td>
+ </tr>
+ <tr>
+ <td>\${1 + 2}</td>
+ <td>${1 + 2}</td>
+ </tr>
+ <tr>
+ <td>\${1.2 + 2.3}</td>
+ <td>${1.2 + 2.3}</td>
+ </tr>
+ <tr>
+ <td>\${1.2E4 + 1.4}</td>
+ <td>${1.2E4 + 1.4}</td>
+ </tr>
+ <tr>
+ <td>\${-4 - 2}</td>
+ <td>${-4 - 2}</td>
+ </tr>
+ <tr>
+ <td>\${21 * 2}</td>
+ <td>${21 * 2}</td>
+ </tr>
+ <tr>
+ <td>\${3/4}</td>
+ <td>${3/4}</td>
+ </tr>
+ <tr>
+ <td>\${3 div 4}</td>
+ <td>${3 div 4}</td>
+ </tr>
+ <tr>
+ <td>\${3/0}</td>
+ <td>${3/0}</td>
+ </tr>
+ <tr>
+ <td>\${10%4}</td>
+ <td>${10%4}</td>
+ </tr>
+ <tr>
+ <td>\${10 mod 4}</td>
+ <td>${10 mod 4}</td>
+ </tr>
<tr>
<td>\${(1==2) ? 3 : 4}</td>
<td>${(1==2) ? 3 : 4}</td>
</tr>
- </table>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp
index e01188a..ce63d5a 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>JSP 2.0 Expression Language - Basic Comparisons</title>
@@ -36,80 +36,80 @@
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${1 < 2}</td>
- <td>${1 < 2}</td>
- </tr>
- <tr>
- <td>\${1 lt 2}</td>
- <td>${1 lt 2}</td>
- </tr>
- <tr>
- <td>\${1 > (4/2)}</td>
- <td>${1 > (4/2)}</td>
- </tr>
- <tr>
- <td>\${1 gt (4/2)}</td>
- <td>${1 gt (4/2)}</td>
- </tr>
- <tr>
- <td>\${4.0 >= 3}</td>
- <td>${4.0 >= 3}</td>
- </tr>
- <tr>
- <td>\${4.0 ge 3}</td>
- <td>${4.0 ge 3}</td>
- </tr>
- <tr>
- <td>\${4 <= 3}</td>
- <td>${4 <= 3}</td>
- </tr>
- <tr>
- <td>\${4 le 3}</td>
- <td>${4 le 3}</td>
- </tr>
- <tr>
- <td>\${100.0 == 100}</td>
- <td>${100.0 == 100}</td>
- </tr>
- <tr>
- <td>\${100.0 eq 100}</td>
- <td>${100.0 eq 100}</td>
- </tr>
- <tr>
- <td>\${(10*10) != 100}</td>
- <td>${(10*10) != 100}</td>
- </tr>
- <tr>
- <td>\${(10*10) ne 100}</td>
- <td>${(10*10) ne 100}</td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${1 < 2}</td>
+ <td>${1 < 2}</td>
+ </tr>
+ <tr>
+ <td>\${1 lt 2}</td>
+ <td>${1 lt 2}</td>
+ </tr>
+ <tr>
+ <td>\${1 > (4/2)}</td>
+ <td>${1 > (4/2)}</td>
+ </tr>
+ <tr>
+ <td>\${1 gt (4/2)}</td>
+ <td>${1 gt (4/2)}</td>
+ </tr>
+ <tr>
+ <td>\${4.0 >= 3}</td>
+ <td>${4.0 >= 3}</td>
+ </tr>
+ <tr>
+ <td>\${4.0 ge 3}</td>
+ <td>${4.0 ge 3}</td>
+ </tr>
+ <tr>
+ <td>\${4 <= 3}</td>
+ <td>${4 <= 3}</td>
+ </tr>
+ <tr>
+ <td>\${4 le 3}</td>
+ <td>${4 le 3}</td>
+ </tr>
+ <tr>
+ <td>\${100.0 == 100}</td>
+ <td>${100.0 == 100}</td>
+ </tr>
+ <tr>
+ <td>\${100.0 eq 100}</td>
+ <td>${100.0 eq 100}</td>
+ </tr>
+ <tr>
+ <td>\${(10*10) != 100}</td>
+ <td>${(10*10) != 100}</td>
+ </tr>
+ <tr>
+ <td>\${(10*10) ne 100}</td>
+ <td>${(10*10) ne 100}</td>
+ </tr>
+ </table>
</code>
<br>
<u><b>Alphabetic</b></u>
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${'a' < 'b'}</td>
- <td>${'a' < 'b'}</td>
- </tr>
- <tr>
- <td>\${'hip' > 'hit'}</td>
- <td>${'hip' > 'hit'}</td>
- </tr>
- <tr>
- <td>\${'4' > 3}</td>
- <td>${'4' > 3}</td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${'a' < 'b'}</td>
+ <td>${'a' < 'b'}</td>
+ </tr>
+ <tr>
+ <td>\${'hip' > 'hit'}</td>
+ <td>${'hip' > 'hit'}</td>
+ </tr>
+ <tr>
+ <td>\${'4' > 3}</td>
+ <td>${'4' > 3}</td>
+ </tr>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp.html
index efc4da3..c5db858 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>JSP 2.0 Expression Language - Basic Comparisons</title>
@@ -37,80 +37,80 @@
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${1 &lt; 2}</td>
- <td>${1 < 2}</td>
- </tr>
- <tr>
- <td>\${1 lt 2}</td>
- <td>${1 lt 2}</td>
- </tr>
- <tr>
- <td>\${1 &gt; (4/2)}</td>
- <td>${1 > (4/2)}</td>
- </tr>
- <tr>
- <td>\${1 gt (4/2)}</td>
- <td>${1 gt (4/2)}</td>
- </tr>
- <tr>
- <td>\${4.0 &gt;= 3}</td>
- <td>${4.0 >= 3}</td>
- </tr>
- <tr>
- <td>\${4.0 ge 3}</td>
- <td>${4.0 ge 3}</td>
- </tr>
- <tr>
- <td>\${4 &lt;= 3}</td>
- <td>${4 <= 3}</td>
- </tr>
- <tr>
- <td>\${4 le 3}</td>
- <td>${4 le 3}</td>
- </tr>
- <tr>
- <td>\${100.0 == 100}</td>
- <td>${100.0 == 100}</td>
- </tr>
- <tr>
- <td>\${100.0 eq 100}</td>
- <td>${100.0 eq 100}</td>
- </tr>
- <tr>
- <td>\${(10*10) != 100}</td>
- <td>${(10*10) != 100}</td>
- </tr>
- <tr>
- <td>\${(10*10) ne 100}</td>
- <td>${(10*10) ne 100}</td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${1 &lt; 2}</td>
+ <td>${1 < 2}</td>
+ </tr>
+ <tr>
+ <td>\${1 lt 2}</td>
+ <td>${1 lt 2}</td>
+ </tr>
+ <tr>
+ <td>\${1 &gt; (4/2)}</td>
+ <td>${1 > (4/2)}</td>
+ </tr>
+ <tr>
+ <td>\${1 gt (4/2)}</td>
+ <td>${1 gt (4/2)}</td>
+ </tr>
+ <tr>
+ <td>\${4.0 &gt;= 3}</td>
+ <td>${4.0 >= 3}</td>
+ </tr>
+ <tr>
+ <td>\${4.0 ge 3}</td>
+ <td>${4.0 ge 3}</td>
+ </tr>
+ <tr>
+ <td>\${4 &lt;= 3}</td>
+ <td>${4 <= 3}</td>
+ </tr>
+ <tr>
+ <td>\${4 le 3}</td>
+ <td>${4 le 3}</td>
+ </tr>
+ <tr>
+ <td>\${100.0 == 100}</td>
+ <td>${100.0 == 100}</td>
+ </tr>
+ <tr>
+ <td>\${100.0 eq 100}</td>
+ <td>${100.0 eq 100}</td>
+ </tr>
+ <tr>
+ <td>\${(10*10) != 100}</td>
+ <td>${(10*10) != 100}</td>
+ </tr>
+ <tr>
+ <td>\${(10*10) ne 100}</td>
+ <td>${(10*10) ne 100}</td>
+ </tr>
+ </table>
</code>
<br>
<u><b>Alphabetic</b></u>
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${'a' &lt; 'b'}</td>
- <td>${'a' < 'b'}</td>
- </tr>
- <tr>
- <td>\${'hip' &gt; 'hit'}</td>
- <td>${'hip' > 'hit'}</td>
- </tr>
- <tr>
- <td>\${'4' &gt; 3}</td>
- <td>${'4' > 3}</td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${'a' &lt; 'b'}</td>
+ <td>${'a' < 'b'}</td>
+ </tr>
+ <tr>
+ <td>\${'hip' &gt; 'hit'}</td>
+ <td>${'hip' > 'hit'}</td>
+ </tr>
+ <tr>
+ <td>\${'4' &gt; 3}</td>
+ <td>${'4' > 3}</td>
+ </tr>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.html
new file mode 100644
index 0000000..b8bfa0e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.html
@@ -0,0 +1,31 @@
+<html>
+<!--
+ 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.
+-->
+<head>
+<title>View Source Code</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p><font color="#0000FF"><a href="composite.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
+
+<h3><a href="composite.jsp.html">Source Code for composite.jsp</a></h3>
+<h3><a href="ValuesTag.java.html">Source Code for ValuesTag.java</a></h3>
+<h3><a href="ValuesBean.java.html">Source Code for ValuesBean.java</a></h3>
+
+</body>
+</html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.jsp
new file mode 100644
index 0000000..c6fa113
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.jsp
@@ -0,0 +1,110 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--%>
+<%@ taglib prefix="my" uri="http://tomcat.apache.org/example-taglib" %>
+
+<html>
+ <head>
+ <title>JSP 2.0 Expression Language - Composite Expressions</title>
+ </head>
+ <body>
+ <h1>JSP 2.0 Expression Language - Composite Expressions</h1>
+ <hr>
+ This example illustrates EL composite expressions. Composite expressions
+ are formed by grouping together multiple EL expressions. Each of them is
+ evaluated from left to right, coerced to String, all those strings are
+ concatenated, and the result is coerced to the expected type.
+
+ <jsp:useBean id="values" class="jsp2.examples.ValuesBean" />
+
+ <blockquote>
+ <code>
+ <table border="1">
+ <thead>
+ <td><b>EL Expression</b></td>
+ <td><b>Type</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${'hello'} wo\${'rld'}</td>
+ <td>String</td>
+ <td><jsp:setProperty name="values" property="stringValue" value="${'hello'} wo${'rld'}"/>${values.stringValue}</td>
+ </tr>
+ <tr>
+ <td>\${'hello'} wo\${'rld'}</td>
+ <td>String</td>
+ <td><my:values string="${'hello'} wo${'rld'}"/></td>
+ </tr>
+ <tr>
+ <td>\${1+2}.\${220}</td>
+ <td>Double</td>
+ <td><jsp:setProperty name="values" property="doubleValue" value="${1+2}.${220}"/>${values.doubleValue}</td>
+ </tr>
+ <tr>
+ <td>\${1+2}.\${220}</td>
+ <td>Double</td>
+ <td><my:values double="${1+2}.${220}"/></td>
+ </tr>
+ <tr>
+ <td>000\${1}\${7}</td>
+ <td>Long</td>
+ <td><jsp:setProperty name="values" property="longValue" value="000${1}${7}"/>${values.longValue}</td>
+ </tr>
+ <tr>
+ <td>000\${1}\${7}</td>
+ <td>Long</td>
+ <td><my:values long="000${1}${7}"/></td>
+ </tr>
+ <!--
+ Undefined values are to be coerced to String, to be "",
+ https://bz.apache.org/bugzilla/show_bug.cgi?id=47413
+ -->
+ <tr>
+ <td>\${undefinedFoo}hello world\${undefinedBar}</td>
+ <td>String</td>
+ <td><jsp:setProperty name="values" property="stringValue" value="${undefinedFoo}hello world${undefinedBar}"/>${values.stringValue}</td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}hello world\${undefinedBar}</td>
+ <td>String</td>
+ <td><my:values string="${undefinedFoo}hello world${undefinedBar}"/></td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Double</td>
+ <td><jsp:setProperty name="values" property="doubleValue" value="${undefinedFoo}${undefinedBar}"/>${values.doubleValue}</td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Double</td>
+ <td><my:values double="${undefinedFoo}${undefinedBar}"/></td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Long</td>
+ <td><jsp:setProperty name="values" property="longValue" value="${undefinedFoo}${undefinedBar}"/>${values.longValue}</td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Long</td>
+ <td><my:values long="${undefinedFoo}${undefinedBar}"/></td>
+ </tr>
+ </table>
+ </code>
+ </blockquote>
+ </body>
+</html>
+
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.jsp.html
new file mode 100644
index 0000000..1d0014f
--- /dev/null
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/composite.jsp.html
@@ -0,0 +1,112 @@
+<html><body><pre>
+<%--
+ 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.
+--%>
+<%@ taglib prefix="my" uri="http://tomcat.apache.org/example-taglib" %>
+
+<html>
+ <head>
+ <title>JSP 2.0 Expression Language - Composite Expressions</title>
+ </head>
+ <body>
+ <h1>JSP 2.0 Expression Language - Composite Expressions</h1>
+ <hr>
+ This example illustrates EL composite expressions. Composite expressions
+ are formed by grouping together multiple EL expressions. Each of them is
+ evaluated from left to right, coerced to String, all those strings are
+ concatenated, and the result is coerced to the expected type.
+
+ <jsp:useBean id="values" class="jsp2.examples.ValuesBean" />
+
+ <blockquote>
+ <code>
+ <table border="1">
+ <thead>
+ <td><b>EL Expression</b></td>
+ <td><b>Type</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${'hello'} wo\${'rld'}</td>
+ <td>String</td>
+ <td><jsp:setProperty name="values" property="stringValue" value="${'hello'} wo${'rld'}"/>${values.stringValue}</td>
+ </tr>
+ <tr>
+ <td>\${'hello'} wo\${'rld'}</td>
+ <td>String</td>
+ <td><my:values string="${'hello'} wo${'rld'}"/></td>
+ </tr>
+ <tr>
+ <td>\${1+2}.\${220}</td>
+ <td>Double</td>
+ <td><jsp:setProperty name="values" property="doubleValue" value="${1+2}.${220}"/>${values.doubleValue}</td>
+ </tr>
+ <tr>
+ <td>\${1+2}.\${220}</td>
+ <td>Double</td>
+ <td><my:values double="${1+2}.${220}"/></td>
+ </tr>
+ <tr>
+ <td>000\${1}\${7}</td>
+ <td>Long</td>
+ <td><jsp:setProperty name="values" property="longValue" value="000${1}${7}"/>${values.longValue}</td>
+ </tr>
+ <tr>
+ <td>000\${1}\${7}</td>
+ <td>Long</td>
+ <td><my:values long="000${1}${7}"/></td>
+ </tr>
+ <!--
+ Undefined values are to be coerced to String, to be "",
+ https://bz.apache.org/bugzilla/show_bug.cgi?id=47413
+ -->
+ <tr>
+ <td>\${undefinedFoo}hello world\${undefinedBar}</td>
+ <td>String</td>
+ <td><jsp:setProperty name="values" property="stringValue" value="${undefinedFoo}hello world${undefinedBar}"/>${values.stringValue}</td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}hello world\${undefinedBar}</td>
+ <td>String</td>
+ <td><my:values string="${undefinedFoo}hello world${undefinedBar}"/></td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Double</td>
+ <td><jsp:setProperty name="values" property="doubleValue" value="${undefinedFoo}${undefinedBar}"/>${values.doubleValue}</td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Double</td>
+ <td><my:values double="${undefinedFoo}${undefinedBar}"/></td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Long</td>
+ <td><jsp:setProperty name="values" property="longValue" value="${undefinedFoo}${undefinedBar}"/>${values.longValue}</td>
+ </tr>
+ <tr>
+ <td>\${undefinedFoo}\${undefinedBar}</td>
+ <td>Long</td>
+ <td><my:values long="${undefinedFoo}${undefinedBar}"/></td>
+ </tr>
+ </table>
+ </code>
+ </blockquote>
+ </body>
+</html>
+
+</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp
index 66478c0..90895aa 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
@@ -26,39 +26,39 @@
<hr>
An upgrade from the JSTL expression language, the JSP 2.0 EL also
allows for simple function invocation. Functions are defined
- by tag libraries and are implemented by a Java programmer as
+ by tag libraries and are implemented by a Java programmer as
static methods.
<blockquote>
<u><b>Change Parameter</b></u>
<form action="functions.jsp" method="GET">
- foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
+ foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
<input type="submit">
</form>
<br>
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${param["foo"]}</td>
- <td>${fn:escapeXml(param["foo"])} </td>
- </tr>
- <tr>
- <td>\${my:reverse(param["foo"])}</td>
- <td>${my:reverse(fn:escapeXml(param["foo"]))} </td>
- </tr>
- <tr>
- <td>\${my:reverse(my:reverse(param["foo"]))}</td>
- <td>${my:reverse(my:reverse(fn:escapeXml(param["foo"])))} </td>
- </tr>
- <tr>
- <td>\${my:countVowels(param["foo"])}</td>
- <td>${my:countVowels(fn:escapeXml(param["foo"]))} </td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${param["foo"]}</td>
+ <td>${fn:escapeXml(param["foo"])} </td>
+ </tr>
+ <tr>
+ <td>\${my:reverse(param["foo"])}</td>
+ <td>${my:reverse(fn:escapeXml(param["foo"]))} </td>
+ </tr>
+ <tr>
+ <td>\${my:reverse(my:reverse(param["foo"]))}</td>
+ <td>${my:reverse(my:reverse(fn:escapeXml(param["foo"])))} </td>
+ </tr>
+ <tr>
+ <td>\${my:countVowels(param["foo"])}</td>
+ <td>${my:countVowels(fn:escapeXml(param["foo"]))} </td>
+ </tr>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp.html
index 9ac0c79..ecb761b 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/functions.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
@@ -27,39 +27,39 @@
<hr>
An upgrade from the JSTL expression language, the JSP 2.0 EL also
allows for simple function invocation. Functions are defined
- by tag libraries and are implemented by a Java programmer as
+ by tag libraries and are implemented by a Java programmer as
static methods.
<blockquote>
<u><b>Change Parameter</b></u>
<form action="functions.jsp" method="GET">
- foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
+ foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
<input type="submit">
</form>
<br>
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${param["foo"]}</td>
- <td>${fn:escapeXml(param["foo"])}&nbsp;</td>
- </tr>
- <tr>
- <td>\${my:reverse(param["foo"])}</td>
- <td>${my:reverse(fn:escapeXml(param["foo"]))}&nbsp;</td>
- </tr>
- <tr>
- <td>\${my:reverse(my:reverse(param["foo"]))}</td>
- <td>${my:reverse(my:reverse(fn:escapeXml(param["foo"])))}&nbsp;</td>
- </tr>
- <tr>
- <td>\${my:countVowels(param["foo"])}</td>
- <td>${my:countVowels(fn:escapeXml(param["foo"]))}&nbsp;</td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${param["foo"]}</td>
+ <td>${fn:escapeXml(param["foo"])}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${my:reverse(param["foo"])}</td>
+ <td>${my:reverse(fn:escapeXml(param["foo"]))}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${my:reverse(my:reverse(param["foo"]))}</td>
+ <td>${my:reverse(my:reverse(fn:escapeXml(param["foo"])))}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${my:countVowels(param["foo"])}</td>
+ <td>${my:countVowels(fn:escapeXml(param["foo"]))}&nbsp;</td>
+ </tr>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp
index 8d6841a..999ad13 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
@@ -23,28 +23,28 @@
<body>
<h1>JSP 2.0 Expression Language - Implicit Objects</h1>
<hr>
- This example illustrates some of the implicit objects available
- in the Expression Lanaguage. The following implicit objects are
+ This example illustrates some of the implicit objects available
+ in the Expression Language. The following implicit objects are
available (not all illustrated here):
<ul>
<li>pageContext - the PageContext object</li>
- <li>pageScope - a Map that maps page-scoped attribute names to
+ <li>pageScope - a Map that maps page-scoped attribute names to
their values</li>
- <li>requestScope - a Map that maps request-scoped attribute names
+ <li>requestScope - a Map that maps request-scoped attribute names
to their values</li>
- <li>sessionScope - a Map that maps session-scoped attribute names
+ <li>sessionScope - a Map that maps session-scoped attribute names
to their values</li>
- <li>applicationScope - a Map that maps application-scoped attribute
+ <li>applicationScope - a Map that maps application-scoped attribute
names to their values</li>
- <li>param - a Map that maps parameter names to a single String
+ <li>param - a Map that maps parameter names to a single String
parameter value</li>
- <li>paramValues - a Map that maps parameter names to a String[] of
+ <li>paramValues - a Map that maps parameter names to a String[] of
all values for that parameter</li>
- <li>header - a Map that maps header names to a single String
+ <li>header - a Map that maps header names to a single String
header value</li>
- <li>headerValues - a Map that maps header names to a String[] of
+ <li>headerValues - a Map that maps header names to a String[] of
all values for that header</li>
- <li>initParam - a Map that maps context initialization parameter
+ <li>initParam - a Map that maps context initialization parameter
names to their String parameter value</li>
<li>cookie - a Map that maps cookie names to a single Cookie object.</li>
</ul>
@@ -52,37 +52,37 @@
<blockquote>
<u><b>Change Parameter</b></u>
<form action="implicit-objects.jsp" method="GET">
- foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
+ foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
<input type="submit">
</form>
<br>
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${param.foo}</td>
- <td>${fn:escapeXml(param["foo"])} </td>
- </tr>
- <tr>
- <td>\${param["foo"]}</td>
- <td>${fn:escapeXml(param["foo"])} </td>
- </tr>
- <tr>
- <td>\${header["host"]}</td>
- <td>${fn:escapeXml(header["host"])} </td>
- </tr>
- <tr>
- <td>\${header["accept"]}</td>
- <td>${fn:escapeXml(header["accept"])} </td>
- </tr>
- <tr>
- <td>\${header["user-agent"]}</td>
- <td>${fn:escapeXml(header["user-agent"])} </td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${param.foo}</td>
+ <td>${fn:escapeXml(param["foo"])} </td>
+ </tr>
+ <tr>
+ <td>\${param["foo"]}</td>
+ <td>${fn:escapeXml(param["foo"])} </td>
+ </tr>
+ <tr>
+ <td>\${header["host"]}</td>
+ <td>${fn:escapeXml(header["host"])} </td>
+ </tr>
+ <tr>
+ <td>\${header["accept"]}</td>
+ <td>${fn:escapeXml(header["accept"])} </td>
+ </tr>
+ <tr>
+ <td>\${header["user-agent"]}</td>
+ <td>${fn:escapeXml(header["user-agent"])} </td>
+ </tr>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp.html
index a2d9bdc..a036a07 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/el/implicit-objects.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
@@ -24,28 +24,28 @@
<body>
<h1>JSP 2.0 Expression Language - Implicit Objects</h1>
<hr>
- This example illustrates some of the implicit objects available
- in the Expression Lanaguage. The following implicit objects are
+ This example illustrates some of the implicit objects available
+ in the Expression Language. The following implicit objects are
available (not all illustrated here):
<ul>
<li>pageContext - the PageContext object</li>
- <li>pageScope - a Map that maps page-scoped attribute names to
+ <li>pageScope - a Map that maps page-scoped attribute names to
their values</li>
- <li>requestScope - a Map that maps request-scoped attribute names
+ <li>requestScope - a Map that maps request-scoped attribute names
to their values</li>
- <li>sessionScope - a Map that maps session-scoped attribute names
+ <li>sessionScope - a Map that maps session-scoped attribute names
to their values</li>
- <li>applicationScope - a Map that maps application-scoped attribute
+ <li>applicationScope - a Map that maps application-scoped attribute
names to their values</li>
- <li>param - a Map that maps parameter names to a single String
+ <li>param - a Map that maps parameter names to a single String
parameter value</li>
- <li>paramValues - a Map that maps parameter names to a String[] of
+ <li>paramValues - a Map that maps parameter names to a String[] of
all values for that parameter</li>
- <li>header - a Map that maps header names to a single String
+ <li>header - a Map that maps header names to a single String
header value</li>
- <li>headerValues - a Map that maps header names to a String[] of
+ <li>headerValues - a Map that maps header names to a String[] of
all values for that header</li>
- <li>initParam - a Map that maps context initialization parameter
+ <li>initParam - a Map that maps context initialization parameter
names to their String parameter value</li>
<li>cookie - a Map that maps cookie names to a single Cookie object.</li>
</ul>
@@ -53,37 +53,37 @@
<blockquote>
<u><b>Change Parameter</b></u>
<form action="implicit-objects.jsp" method="GET">
- foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
+ foo = <input type="text" name="foo" value="${fn:escapeXml(param["foo"])}">
<input type="submit">
</form>
<br>
<code>
<table border="1">
<thead>
- <td><b>EL Expression</b></td>
- <td><b>Result</b></td>
- </thead>
- <tr>
- <td>\${param.foo}</td>
- <td>${fn:escapeXml(param["foo"])}&nbsp;</td>
- </tr>
- <tr>
- <td>\${param["foo"]}</td>
- <td>${fn:escapeXml(param["foo"])}&nbsp;</td>
- </tr>
- <tr>
- <td>\${header["host"]}</td>
- <td>${fn:escapeXml(header["host"])}&nbsp;</td>
- </tr>
- <tr>
- <td>\${header["accept"]}</td>
- <td>${fn:escapeXml(header["accept"])}&nbsp;</td>
- </tr>
- <tr>
- <td>\${header["user-agent"]}</td>
- <td>${fn:escapeXml(header["user-agent"])}&nbsp;</td>
- </tr>
- </table>
+ <td><b>EL Expression</b></td>
+ <td><b>Result</b></td>
+ </thead>
+ <tr>
+ <td>\${param.foo}</td>
+ <td>${fn:escapeXml(param["foo"])}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${param["foo"]}</td>
+ <td>${fn:escapeXml(param["foo"])}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${header["host"]}</td>
+ <td>${fn:escapeXml(header["host"])}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${header["accept"]}</td>
+ <td>${fn:escapeXml(header["accept"])}&nbsp;</td>
+ </tr>
+ <tr>
+ <td>\${header["user-agent"]}</td>
+ <td>${fn:escapeXml(header["user-agent"])}&nbsp;</td>
+ </tr>
+ </table>
</code>
</blockquote>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/FooBean.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/FooBean.java.html
index 0b15181..2711b30 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/FooBean.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/FooBean.java.html
@@ -21,18 +21,18 @@
public class FooBean {
private String bar;
-
+
public FooBean() {
bar = "Initial value";
}
-
+
public String getBar() {
return this.bar;
}
-
+
public void setBar(String bar) {
this.bar = bar;
}
-
+
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/HelloWorldSimpleTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/HelloWorldSimpleTag.java.html
index c409839..6fb9b0d 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/HelloWorldSimpleTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/HelloWorldSimpleTag.java.html
@@ -19,16 +19,18 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* SimpleTag handler that prints "Hello, world!"
*/
public class HelloWorldSimpleTag extends SimpleTagSupport {
+ @Override
public void doTag() throws JspException, IOException {
- getJspContext().getOut().write( "Hello, world!" );
+ getJspContext().getOut().write( "Hello, world!" );
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/ShuffleSimpleTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/ShuffleSimpleTag.java.html
index 1b66d06..806cf7b 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/ShuffleSimpleTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/ShuffleSimpleTag.java.html
@@ -19,22 +19,28 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+import java.util.Random;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* SimpleTag handler that accepts takes three attributes of type
* JspFragment and invokes then in a random order.
*/
public class ShuffleSimpleTag extends SimpleTagSupport {
+ // No need for this to use SecureRandom
+ private static Random random = new Random();
+
private JspFragment fragment1;
private JspFragment fragment2;
private JspFragment fragment3;
+ @Override
public void doTag() throws JspException, IOException {
- switch( (int)(Math.random() * 6) ) {
+ switch(random.nextInt(6)) {
case 0:
fragment1.invoke( null );
fragment2.invoke( null );
@@ -71,11 +77,11 @@
public void setFragment1( JspFragment fragment1 ) {
this.fragment1 = fragment1;
}
-
+
public void setFragment2( JspFragment fragment2 ) {
this.fragment2 = fragment2;
}
-
+
public void setFragment3( JspFragment fragment3 ) {
this.fragment3 = fragment3;
}
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/TileSimpleTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/TileSimpleTag.java.html
index 4453222..2cd454b 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/TileSimpleTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/TileSimpleTag.java.html
@@ -19,9 +19,10 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* Displays a tile as a single cell in a table.
@@ -30,17 +31,18 @@
private String color;
private String label;
+ @Override
public void doTag() throws JspException, IOException {
- getJspContext().getOut().write(
- "<td width=\"32\" height=\"32\" bgcolor=\"" + this.color +
- "\"><font color=\"#ffffff\"><center>" + this.label +
+ getJspContext().getOut().write(
+ "<td width=\"32\" height=\"32\" bgcolor=\"" + this.color +
+ "\"><font color=\"#ffffff\"><center>" + this.label +
"</center></font></td>" );
}
public void setColor( String color ) {
this.color = color;
}
-
+
public void setLabel( String label ) {
this.label = label;
}
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp
index 64b6d6e..02abbd1 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<html>
@@ -23,7 +23,7 @@
<body>
<h1>JSP 2.0 Examples - jsp:attribute and jsp:body</h1>
<hr>
- <p>The new <jsp:attribute> and <jsp:body>
+ <p>The new <jsp:attribute> and <jsp:body>
standard actions can be used to specify the value of any standard
action or custom action attribute.</p>
<p>This example uses the <jsp:attribute>
@@ -36,7 +36,7 @@
Bean created! Setting foo.bar...<br>
<jsp:setProperty name="foo" property="bar">
<jsp:attribute name="value">
- <my:helloWorld/>
+ <my:helloWorld/>
</jsp:attribute>
</jsp:setProperty>
</jsp:useBean>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp.html
index eb3a927..088ed20 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<html>
@@ -24,7 +24,7 @@
<body>
<h1>JSP 2.0 Examples - jsp:attribute and jsp:body</h1>
<hr>
- <p>The new &lt;jsp:attribute&gt; and &lt;jsp:body&gt;
+ <p>The new &lt;jsp:attribute&gt; and &lt;jsp:body&gt;
standard actions can be used to specify the value of any standard
action or custom action attribute.</p>
<p>This example uses the &lt;jsp:attribute&gt;
@@ -37,7 +37,7 @@
Bean created! Setting foo.bar...<br>
<jsp:setProperty name="foo" property="bar">
<jsp:attribute name="value">
- <my:helloWorld/>
+ <my:helloWorld/>
</jsp:attribute>
</jsp:setProperty>
</jsp:useBean>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp
index 2a318a7..424af35 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<html>
@@ -25,10 +25,10 @@
<hr>
<p>Try reloading the page a few times. Both the rows and the columns
are shuffled and appear different each time.</p>
- <p>Here's how the code works. The SimpleTag handler called
- <my:shuffle> accepts three attributes. Each attribute is a
+ <p>Here's how the code works. The SimpleTag handler called
+ <my:shuffle> accepts three attributes. Each attribute is a
JSP Fragment, meaning it is a fragment of JSP code that can be
- dynamically executed by the shuffle tag handler on demand. The
+ dynamically executed by the shuffle tag handler on demand. The
shuffle tag handler executes the three fragments in a random order.
To shuffle both the rows and the columns, the shuffle tag is used
with itself as a parameter.</p>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp.html
index 9329285..231eba6 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<html>
@@ -26,10 +26,10 @@
<hr>
<p>Try reloading the page a few times. Both the rows and the columns
are shuffled and appear different each time.</p>
- <p>Here's how the code works. The SimpleTag handler called
- &lt;my:shuffle&gt; accepts three attributes. Each attribute is a
+ <p>Here's how the code works. The SimpleTag handler called
+ &lt;my:shuffle&gt; accepts three attributes. Each attribute is a
JSP Fragment, meaning it is a fragment of JSP code that can be
- dynamically executed by the shuffle tag handler on demand. The
+ dynamically executed by the shuffle tag handler on demand. The
shuffle tag handler executes the three fragments in a random order.
To shuffle both the rows and the columns, the shuffle tag is used
with itself as a parameter.</p>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx
index 8a5b27d..ba53d8d 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx
@@ -17,7 +17,7 @@
<tags:xhtmlbasic xmlns:tags="urn:jsptagdir:/WEB-INF/tags"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
- xmlns="http://www.w3.org/1999/xhtml">
+ xmlns="http://www.w3.org/1999/xhtml">
<jsp:directive.page contentType="text/html" />
<head>
<title>JSPX - XHTML Basic Example</title>
@@ -26,7 +26,7 @@
<h1>JSPX - XHTML Basic Example</h1>
<hr/>
This example illustrates how to use JSPX to produce an XHTML basic
- document suitable for use with mobile phones, televisions,
+ document suitable for use with mobile phones, televisions,
PDAs, vending machines, pagers, car navigation systems,
mobile game machines, digital book readers, smart watches, etc.
<p/>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx.html
index f177334..2116538 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/basic.jspx.html
@@ -18,7 +18,7 @@
<tags:xhtmlbasic xmlns:tags="urn:jsptagdir:/WEB-INF/tags"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
- xmlns="http://www.w3.org/1999/xhtml">
+ xmlns="http://www.w3.org/1999/xhtml">
<jsp:directive.page contentType="text/html" />
<head>
<title>JSPX - XHTML Basic Example</title>
@@ -27,7 +27,7 @@
<h1>JSPX - XHTML Basic Example</h1>
<hr/>
This example illustrates how to use JSPX to produce an XHTML basic
- document suitable for use with mobile phones, televisions,
+ document suitable for use with mobile phones, televisions,
PDAs, vending machines, pagers, car navigation systems,
mobile game machines, digital book readers, smart watches, etc.
<p/>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/svgexample.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/svgexample.html
index 12bcd82..6ef1b44 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/svgexample.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/svgexample.html
@@ -23,7 +23,7 @@
<hr>
This example uses JSP 2.0's new, simplified JSPX syntax to render a
Scalable Vector Graphics (SVG) document. When you view the source,
- notice the lack of a <jsp:root> element! The text to be rendered
+ notice the lack of a <jsp:root> element! The text to be rendered
can be modified by changing the value of the name parameter.
<p>
SVG has many potential uses, such as searchable images, or images
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx
index ad97af2..2ade5d1 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!--
+<!--
- This example is based off the textRotate.svg example that comes
- with Apache Batik. The original example was written by Bill Haneman.
- This version by Mark Roth.
@@ -38,14 +38,14 @@
<jsp:text>
<![CDATA[<g opacity="0.95" transform="scale(1.05) rotate(15)">]]>
</jsp:text>
- <text x="0" y="0" transform="scale(1.6, 1.6)" fill="DarkSlateBlue"
- text-anchor="middle" font-size="40" font-family="Serif"
+ <text x="0" y="0" transform="scale(1.6, 1.6)" fill="DarkSlateBlue"
+ text-anchor="middle" font-size="40" font-family="Serif"
id="words">${name}</text>
</c:forEach>
<c:forEach var="i" begin="1" end="24">
<jsp:text><![CDATA[</g>]]></jsp:text>
</c:forEach>
- <text style="font-size:75;font-family:Serif;fill:white"
+ <text style="font-size:75;font-family:Serif;fill:white"
text-anchor="middle">${name}</text>
</g>
</g>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx.html b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx.html
index 5846a19..0313838 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/jspx/textRotate.jspx.html
@@ -15,7 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!--
+<!--
- This example is based off the textRotate.svg example that comes
- with Apache Batik. The original example was written by Bill Haneman.
- This version by Mark Roth.
@@ -39,14 +39,14 @@
<jsp:text>
<![CDATA[<g opacity="0.95" transform="scale(1.05) rotate(15)">]]>
</jsp:text>
- <text x="0" y="0" transform="scale(1.6, 1.6)" fill="DarkSlateBlue"
- text-anchor="middle" font-size="40" font-family="Serif"
+ <text x="0" y="0" transform="scale(1.6, 1.6)" fill="DarkSlateBlue"
+ text-anchor="middle" font-size="40" font-family="Serif"
id="words">${name}</text>
</c:forEach>
<c:forEach var="i" begin="1" end="24">
<jsp:text><![CDATA[</g>]]></jsp:text>
</c:forEach>
- <text style="font-size:75;font-family:Serif;fill:white"
+ <text style="font-size:75;font-family:Serif;fill:white"
text-anchor="middle">${name}</text>
</g>
</g>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/misc/EchoAttributesTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/misc/EchoAttributesTag.java.html
index 4e62250..9b25ba0 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/misc/EchoAttributesTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/misc/EchoAttributesTag.java.html
@@ -19,38 +19,41 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+import java.util.ArrayList;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.tagext.SimpleTagSupport;
import javax.servlet.jsp.tagext.DynamicAttributes;
-import java.util.ArrayList;
-import java.io.IOException;
+import javax.servlet.jsp.tagext.SimpleTagSupport;
/**
- * SimpleTag handler that echoes all its attributes
+ * SimpleTag handler that echoes all its attributes
*/
-public class EchoAttributesTag
+public class EchoAttributesTag
extends SimpleTagSupport
implements DynamicAttributes
{
- private ArrayList keys = new ArrayList();
- private ArrayList values = new ArrayList();
+ private ArrayList<String> keys = new ArrayList<String>();
+ private ArrayList<Object> values = new ArrayList<Object>();
+ @Override
public void doTag() throws JspException, IOException {
- JspWriter out = getJspContext().getOut();
- for( int i = 0; i < keys.size(); i++ ) {
- String key = (String)keys.get( i );
- Object value = values.get( i );
- out.println( "<li>" + key + " = " + value + "</li>" );
+ JspWriter out = getJspContext().getOut();
+ for( int i = 0; i < keys.size(); i++ ) {
+ String key = keys.get( i );
+ Object value = values.get( i );
+ out.println( "<li>" + key + " = " + value + "</li>" );
}
}
- public void setDynamicAttribute( String uri, String localName,
- Object value )
- throws JspException
+ @Override
+ public void setDynamicAttribute( String uri, String localName,
+ Object value )
+ throws JspException
{
- keys.add( localName );
- values.add( value );
+ keys.add( localName );
+ values.add( value );
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp
index 7ccf481..51608c7 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,18 +13,18 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<h1>JSP 2.0 Examples - JSP Configuration</h1>
<hr>
- <p>Using a <jsp-property-group> element in the web.xml
+ <p>Using a <jsp-property-group> element in the web.xml
deployment descriptor, this JSP page has been configured in the
following ways:</p>
<ul>
<li>Uses <include-prelude> to include the top banner.</li>
<li>Uses <include-coda> to include the bottom banner.</li>
- <li>Uses <scripting-invalid> true to disable
- <% scripting %> elements</li>
+ <li>Uses <scripting-invalid> true to disable
+ <% scripting %> elements</li>
<li>Uses <el-ignored> true to disable ${EL} elements</li>
<li>Uses <page-encoding> ISO-8859-1 to set the page encoding (though this is the default anyway)</li>
</ul>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp.html
index 033f2d2..dbfc450 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/misc/config.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,18 +14,18 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<h1>JSP 2.0 Examples - JSP Configuration</h1>
<hr>
- <p>Using a &lt;jsp-property-group&gt; element in the web.xml
+ <p>Using a &lt;jsp-property-group&gt; element in the web.xml
deployment descriptor, this JSP page has been configured in the
following ways:</p>
<ul>
<li>Uses &lt;include-prelude&gt; to include the top banner.</li>
<li>Uses &lt;include-coda&gt; to include the bottom banner.</li>
- <li>Uses &lt;scripting-invalid&gt; true to disable
- &lt;% scripting %&gt; elements</li>
+ <li>Uses &lt;scripting-invalid&gt; true to disable
+ &lt;% scripting %&gt; elements</li>
<li>Uses &lt;el-ignored&gt; true to disable ${EL} elements</li>
<li>Uses &lt;page-encoding&gt; ISO-8859-1 to set the page encoding (though this is the default anyway)</li>
</ul>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp
index 637dea9..b351741 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<html>
<head>
@@ -22,7 +22,7 @@
<body>
<h1>JSP 2.0 Examples - Dynamic Attributes</h1>
<hr>
- <p>This JSP page invokes a custom tag that accepts a dynamic set
+ <p>This JSP page invokes a custom tag that accepts a dynamic set
of attributes. The tag echoes the name and value of all attributes
passed to it.</p>
<hr>
@@ -36,9 +36,9 @@
</ul>
<h2>Invocation 3 (three attributes)</h2>
<ul>
- <my:echoAttributes dogName="Scruffy"
- catName="Fluffy"
- blowfishName="Puffy"/>
+ <my:echoAttributes dogName="Scruffy"
+ catName="Fluffy"
+ blowfishName="Puffy"/>
</ul>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp.html
index ec47c8c..1179f82 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="http://tomcat.apache.org/jsp2-example-taglib"%>
<html>
<head>
@@ -23,7 +23,7 @@
<body>
<h1>JSP 2.0 Examples - Dynamic Attributes</h1>
<hr>
- <p>This JSP page invokes a custom tag that accepts a dynamic set
+ <p>This JSP page invokes a custom tag that accepts a dynamic set
of attributes. The tag echoes the name and value of all attributes
passed to it.</p>
<hr>
@@ -37,9 +37,9 @@
</ul>
<h2>Invocation 3 (three attributes)</h2>
<ul>
- <my:echoAttributes dogName="Scruffy"
- catName="Fluffy"
- blowfishName="Puffy"/>
+ <my:echoAttributes dogName="Scruffy"
+ catName="Fluffy"
+ blowfishName="Puffy"/>
</ul>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/BookBean.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/BookBean.java.html
index a977a8c..143d754 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/BookBean.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/BookBean.java.html
@@ -23,7 +23,7 @@
private String title;
private String author;
private String isbn;
-
+
public BookBean( String title, String author, String isbn ) {
this.title = title;
this.author = author;
@@ -33,14 +33,14 @@
public String getTitle() {
return this.title;
}
-
+
public String getAuthor() {
return this.author;
}
-
+
public String getIsbn() {
return this.isbn;
}
-
+
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/FindBookSimpleTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/FindBookSimpleTag.java.html
index d010f0a..246df1f 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/FindBookSimpleTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/FindBookSimpleTag.java.html
@@ -21,6 +21,7 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
+
import jsp2.examples.BookBean;
/**
@@ -29,18 +30,19 @@
*/
public class FindBookSimpleTag extends SimpleTagSupport {
private String var;
-
+
private static final String BOOK_TITLE = "The Lord of the Rings";
private static final String BOOK_AUTHOR = "J. R. R. Tolkein";
private static final String BOOK_ISBN = "0618002251";
+ @Override
public void doTag() throws JspException {
BookBean book = new BookBean( BOOK_TITLE, BOOK_AUTHOR, BOOK_ISBN );
getJspContext().setAttribute( this.var, book );
}
public void setVar( String var ) {
- this.var = var;
+ this.var = var;
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/Functions.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/Functions.java.html
index 350fce6..91abc75 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/Functions.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/Functions.java.html
@@ -17,29 +17,31 @@
*/
package jsp2.examples.el;
+import java.util.Locale;
+
/**
* Defines the functions for the jsp2 example tag library.
- *
+ *
* <p>Each function is defined as a static method.</p>
*/
public class Functions {
public static String reverse( String text ) {
- return new StringBuffer( text ).reverse().toString();
+ return new StringBuilder( text ).reverse().toString();
}
public static int numVowels( String text ) {
String vowels = "aeiouAEIOU";
- int result = 0;
+ int result = 0;
for( int i = 0; i < text.length(); i++ ) {
- if( vowels.indexOf( text.charAt( i ) ) != -1 ) {
- result++;
- }
- }
- return result;
+ if( vowels.indexOf( text.charAt( i ) ) != -1 ) {
+ result++;
+ }
+ }
+ return result;
}
public static String caps( String text ) {
- return text.toUpperCase();
+ return text.toUpperCase(Locale.ENGLISH);
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/HelloWorldSimpleTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/HelloWorldSimpleTag.java.html
index c409839..6fb9b0d 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/HelloWorldSimpleTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/HelloWorldSimpleTag.java.html
@@ -19,16 +19,18 @@
package jsp2.examples.simpletag;
+import java.io.IOException;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
-import java.io.IOException;
/**
* SimpleTag handler that prints "Hello, world!"
*/
public class HelloWorldSimpleTag extends SimpleTagSupport {
+ @Override
public void doTag() throws JspException, IOException {
- getJspContext().getOut().write( "Hello, world!" );
+ getJspContext().getOut().write( "Hello, world!" );
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/RepeatSimpleTag.java.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/RepeatSimpleTag.java.html
index 2ad96eb..852ac2a 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/RepeatSimpleTag.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/RepeatSimpleTag.java.html
@@ -19,26 +19,28 @@
package jsp2.examples.simpletag;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.SimpleTagSupport;
+
/**
- * SimpleTag handler that accepts a num attribute and
+ * SimpleTag handler that accepts a num attribute and
* invokes its body 'num' times.
*/
public class RepeatSimpleTag extends SimpleTagSupport {
private int num;
+ @Override
public void doTag() throws JspException, IOException {
for (int i=0; i<num; i++) {
getJspContext().setAttribute("count", String.valueOf( i + 1 ) );
- getJspBody().invoke(null);
+ getJspBody().invoke(null);
}
}
public void setNum(int num) {
- this.num = num;
+ this.num = num;
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp
index 7a9a064..069bd37 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
@@ -22,34 +22,34 @@
<body>
<h1>JSP 2.0 Examples - Book SimpleTag Handler</h1>
<hr>
- <p>Illustrates a semi-realistic use of SimpleTag and the Expression
- Language. First, a <my:findBook> tag is invoked to populate
- the page context with a BookBean. Then, the books fields are printed
+ <p>Illustrates a semi-realistic use of SimpleTag and the Expression
+ Language. First, a <my:findBook> tag is invoked to populate
+ the page context with a BookBean. Then, the books fields are printed
in all caps.</p>
<br>
<b><u>Result:</u></b><br>
<my:findBook var="book"/>
<table border="1">
<thead>
- <td><b>Field</b></td>
- <td><b>Value</b></td>
- <td><b>Capitalized</b></td>
- </thead>
- <tr>
- <td>Title</td>
- <td>${book.title}</td>
- <td>${my:caps(book.title)}</td>
- </tr>
- <tr>
- <td>Author</td>
- <td>${book.author}</td>
- <td>${my:caps(book.author)}</td>
- </tr>
- <tr>
- <td>ISBN</td>
- <td>${book.isbn}</td>
- <td>${my:caps(book.isbn)}</td>
- </tr>
+ <td><b>Field</b></td>
+ <td><b>Value</b></td>
+ <td><b>Capitalized</b></td>
+ </thead>
+ <tr>
+ <td>Title</td>
+ <td>${book.title}</td>
+ <td>${my:caps(book.title)}</td>
+ </tr>
+ <tr>
+ <td>Author</td>
+ <td>${book.author}</td>
+ <td>${my:caps(book.author)}</td>
+ </tr>
+ <tr>
+ <td>ISBN</td>
+ <td>${book.isbn}</td>
+ <td>${my:caps(book.isbn)}</td>
+ </tr>
</table>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp.html
index 7ecfe3b..4d242ab 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/book.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="my" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
@@ -23,34 +23,34 @@
<body>
<h1>JSP 2.0 Examples - Book SimpleTag Handler</h1>
<hr>
- <p>Illustrates a semi-realistic use of SimpleTag and the Expression
- Language. First, a &lt;my:findBook&gt; tag is invoked to populate
- the page context with a BookBean. Then, the books fields are printed
+ <p>Illustrates a semi-realistic use of SimpleTag and the Expression
+ Language. First, a &lt;my:findBook&gt; tag is invoked to populate
+ the page context with a BookBean. Then, the books fields are printed
in all caps.</p>
<br>
<b><u>Result:</u></b><br>
<my:findBook var="book"/>
<table border="1">
<thead>
- <td><b>Field</b></td>
- <td><b>Value</b></td>
- <td><b>Capitalized</b></td>
- </thead>
- <tr>
- <td>Title</td>
- <td>${book.title}</td>
- <td>${my:caps(book.title)}</td>
- </tr>
- <tr>
- <td>Author</td>
- <td>${book.author}</td>
- <td>${my:caps(book.author)}</td>
- </tr>
- <tr>
- <td>ISBN</td>
- <td>${book.isbn}</td>
- <td>${my:caps(book.isbn)}</td>
- </tr>
+ <td><b>Field</b></td>
+ <td><b>Value</b></td>
+ <td><b>Capitalized</b></td>
+ </thead>
+ <tr>
+ <td>Title</td>
+ <td>${book.title}</td>
+ <td>${my:caps(book.title)}</td>
+ </tr>
+ <tr>
+ <td>Author</td>
+ <td>${book.author}</td>
+ <td>${my:caps(book.author)}</td>
+ </tr>
+ <tr>
+ <td>ISBN</td>
+ <td>${book.isbn}</td>
+ <td>${my:caps(book.isbn)}</td>
+ </tr>
</table>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp
index 4222b2e..d5ebf98 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp.html
index c363802..e43a05f 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/hello.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp
index 1f3d008..f66bdde 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
@@ -23,11 +23,11 @@
<h1>JSP 2.0 Examples - Repeat SimpleTag Handler</h1>
<hr>
<p>This tag handler accepts a "num" parameter and repeats the body of the
- tag "num" times. It's a simple example, but the implementation of
- such a tag in JSP 2.0 is substantially simpler than the equivalent
+ tag "num" times. It's a simple example, but the implementation of
+ such a tag in JSP 2.0 is substantially simpler than the equivalent
JSP 1.2-style classic tag handler.</p>
<p>The body of the tag is encapsulated in a "JSP Fragment" and passed
- to the tag handler, which then executes it five times, inside a
+ to the tag handler, which then executes it five times, inside a
for loop. The tag handler passes in the current invocation in a
scoped variable called count, which can be accessed using the EL.</p>
<br>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp.html
index e36b66c..a3bd71e 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/simpletag/repeat.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
@@ -24,11 +24,11 @@
<h1>JSP 2.0 Examples - Repeat SimpleTag Handler</h1>
<hr>
<p>This tag handler accepts a "num" parameter and repeats the body of the
- tag "num" times. It's a simple example, but the implementation of
- such a tag in JSP 2.0 is substantially simpler than the equivalent
+ tag "num" times. It's a simple example, but the implementation of
+ such a tag in JSP 2.0 is substantially simpler than the equivalent
JSP 1.2-style classic tag handler.</p>
<p>The body of the tag is encapsulated in a "JSP Fragment" and passed
- to the tag handler, which then executes it five times, inside a
+ to the tag handler, which then executes it five times, inside a
for loop. The tag handler passes in the current invocation in a
scoped variable called count, which can be accessed using the EL.</p>
<br>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/displayProducts.tag.html b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/displayProducts.tag.html
index 6388336..7898fe2 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/displayProducts.tag.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/displayProducts.tag.html
@@ -25,28 +25,28 @@
<table border="1">
<tr>
- <td>
+ <td>
<c:set var="name" value="Hand-held Color PDA"/>
<c:set var="price" value="$298.86"/>
<jsp:invoke fragment="normalPrice"/>
</td>
- <td>
+ <td>
<c:set var="name" value="4-Pack 150 Watt Light Bulbs"/>
<c:set var="origPrice" value="$2.98"/>
<c:set var="salePrice" value="$2.32"/>
<jsp:invoke fragment="onSale"/>
</td>
- <td>
+ <td>
<c:set var="name" value="Digital Cellular Phone"/>
<c:set var="price" value="$68.74"/>
<jsp:invoke fragment="normalPrice"/>
</td>
- <td>
+ <td>
<c:set var="name" value="Baby Grand Piano"/>
<c:set var="price" value="$10,800.00"/>
<jsp:invoke fragment="normalPrice"/>
</td>
- <td>
+ <td>
<c:set var="name" value="Luxury Car w/ Leather Seats"/>
<c:set var="origPrice" value="$23,980.00"/>
<c:set var="salePrice" value="$21,070.00"/>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp
index e93c7c5..a5d9999 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
@@ -22,7 +22,7 @@
<body>
<h1>JSP 2.0 Examples - Hello World Using a Tag File</h1>
<hr>
- <p>This JSP page invokes a custom tag that simply echos "Hello, World!"
+ <p>This JSP page invokes a custom tag that simply echos "Hello, World!"
The custom tag is generated from a tag file in the /WEB-INF/tags
directory.</p>
<p>Notice that we did not need to write a TLD for this tag. We just
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp.html
index c3b7b4f..4fbd217 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/hello.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
@@ -23,7 +23,7 @@
<body>
<h1>JSP 2.0 Examples - Hello World Using a Tag File</h1>
<hr>
- <p>This JSP page invokes a custom tag that simply echos "Hello, World!"
+ <p>This JSP page invokes a custom tag that simply echos "Hello, World!"
The custom tag is generated from a tag file in the /WEB-INF/tags
directory.</p>
<p>Notice that we did not need to write a TLD for this tag. We just
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp
index 4dfc483..56f73b6 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
@@ -22,8 +22,8 @@
<body>
<h1>JSP 2.0 Examples - Panels using Tag Files</h1>
<hr>
- <p>This JSP page invokes a custom tag that draws a
- panel around the contents of the tag body. Normally, such a tag
+ <p>This JSP page invokes a custom tag that draws a
+ panel around the contents of the tag body. Normally, such a tag
implementation would require a Java class with many println() statements,
outputting HTML. Instead, we can use a .tag file as a template,
and we don't need to write a single line of Java or even a TLD!</p>
@@ -32,25 +32,25 @@
<tr valign="top">
<td>
<tags:panel color="#ff8080" bgcolor="#ffc0c0" title="Panel 1">
- First panel.<br/>
- </tags:panel>
+ First panel.<br/>
+ </tags:panel>
</td>
<td>
<tags:panel color="#80ff80" bgcolor="#c0ffc0" title="Panel 2">
- Second panel.<br/>
- Second panel.<br/>
- Second panel.<br/>
- Second panel.<br/>
- </tags:panel>
+ Second panel.<br/>
+ Second panel.<br/>
+ Second panel.<br/>
+ Second panel.<br/>
+ </tags:panel>
</td>
<td>
<tags:panel color="#8080ff" bgcolor="#c0c0ff" title="Panel 3">
- Third panel.<br/>
+ Third panel.<br/>
<tags:panel color="#ff80ff" bgcolor="#ffc0ff" title="Inner">
- A panel in a panel.
- </tags:panel>
- Third panel.<br/>
- </tags:panel>
+ A panel in a panel.
+ </tags:panel>
+ Third panel.<br/>
+ </tags:panel>
</td>
</tr>
</table>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp.html
index 0cc746d..4a8277c 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/panel.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
@@ -23,8 +23,8 @@
<body>
<h1>JSP 2.0 Examples - Panels using Tag Files</h1>
<hr>
- <p>This JSP page invokes a custom tag that draws a
- panel around the contents of the tag body. Normally, such a tag
+ <p>This JSP page invokes a custom tag that draws a
+ panel around the contents of the tag body. Normally, such a tag
implementation would require a Java class with many println() statements,
outputting HTML. Instead, we can use a .tag file as a template,
and we don't need to write a single line of Java or even a TLD!</p>
@@ -33,25 +33,25 @@
<tr valign="top">
<td>
<tags:panel color="#ff8080" bgcolor="#ffc0c0" title="Panel 1">
- First panel.<br/>
- </tags:panel>
+ First panel.<br/>
+ </tags:panel>
</td>
<td>
<tags:panel color="#80ff80" bgcolor="#c0ffc0" title="Panel 2">
- Second panel.<br/>
- Second panel.<br/>
- Second panel.<br/>
- Second panel.<br/>
- </tags:panel>
+ Second panel.<br/>
+ Second panel.<br/>
+ Second panel.<br/>
+ Second panel.<br/>
+ </tags:panel>
</td>
<td>
<tags:panel color="#8080ff" bgcolor="#c0c0ff" title="Panel 3">
- Third panel.<br/>
+ Third panel.<br/>
<tags:panel color="#ff80ff" bgcolor="#ffc0ff" title="Inner">
- A panel in a panel.
- </tags:panel>
- Third panel.<br/>
- </tags:panel>
+ A panel in a panel.
+ </tags:panel>
+ Third panel.<br/>
+ </tags:panel>
</td>
</tr>
</table>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp
index 328cc96..23b84f1 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
@@ -22,7 +22,7 @@
<body>
<h1>JSP 2.0 Examples - Display Products Tag File</h1>
<hr>
- <p>This JSP page invokes a tag file that displays a listing of
+ <p>This JSP page invokes a tag file that displays a listing of
products. The custom tag accepts two fragments that enable
customization of appearance. One for when the product is on sale
and one for normal price.</p>
@@ -31,23 +31,23 @@
<h2>Products</h2>
<tags:displayProducts>
<jsp:attribute name="normalPrice">
- Item: ${name}<br/>
- Price: ${price}
+ Item: ${name}<br/>
+ Price: ${price}
</jsp:attribute>
<jsp:attribute name="onSale">
- Item: ${name}<br/>
- <font color="red"><strike>Was: ${origPrice}</strike></font><br/>
- <b>Now: ${salePrice}</b>
+ Item: ${name}<br/>
+ <font color="red"><strike>Was: ${origPrice}</strike></font><br/>
+ <b>Now: ${salePrice}</b>
</jsp:attribute>
</tags:displayProducts>
<hr>
<h2>Products (Same tag, alternate style)</h2>
<tags:displayProducts>
<jsp:attribute name="normalPrice">
- <b>${name}</b> @ ${price} ea.
+ <b>${name}</b> @ ${price} ea.
</jsp:attribute>
<jsp:attribute name="onSale">
- <b>${name}</b> @ ${salePrice} ea. (was: ${origPrice})
+ <b>${name}</b> @ ${salePrice} ea. (was: ${origPrice})
</jsp:attribute>
</tags:displayProducts>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp.html b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp.html
index f9b6e6f..a081b23 100644
--- a/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsp2/tagfiles/products.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
@@ -23,7 +23,7 @@
<body>
<h1>JSP 2.0 Examples - Display Products Tag File</h1>
<hr>
- <p>This JSP page invokes a tag file that displays a listing of
+ <p>This JSP page invokes a tag file that displays a listing of
products. The custom tag accepts two fragments that enable
customization of appearance. One for when the product is on sale
and one for normal price.</p>
@@ -32,23 +32,23 @@
<h2>Products</h2>
<tags:displayProducts>
<jsp:attribute name="normalPrice">
- Item: ${name}<br/>
- Price: ${price}
+ Item: ${name}<br/>
+ Price: ${price}
</jsp:attribute>
<jsp:attribute name="onSale">
- Item: ${name}<br/>
- <font color="red"><strike>Was: ${origPrice}</strike></font><br/>
- <b>Now: ${salePrice}</b>
+ Item: ${name}<br/>
+ <font color="red"><strike>Was: ${origPrice}</strike></font><br/>
+ <b>Now: ${salePrice}</b>
</jsp:attribute>
</tags:displayProducts>
<hr>
<h2>Products (Same tag, alternate style)</h2>
<tags:displayProducts>
<jsp:attribute name="normalPrice">
- <b>${name}</b> @ ${price} ea.
+ <b>${name}</b> @ ${price} ea.
</jsp:attribute>
<jsp:attribute name="onSale">
- <b>${name}</b> @ ${salePrice} ea. (was: ${origPrice})
+ <b>${name}</b> @ ${salePrice} ea. (was: ${origPrice})
</jsp:attribute>
</tags:displayProducts>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp b/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp
index 5f332ec..1b2b9fc 100644
--- a/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,7 +13,8 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
<h1>
diff --git a/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp.html b/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp.html
index 44ac35e..d9e6138 100644
--- a/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsptoserv/hello.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,7 +14,8 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
<h1>
diff --git a/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp b/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp
index c08192f..c2a460a 100644
--- a/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp
+++ b/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,7 +13,8 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
<!-- Forward to a servlet -->
diff --git a/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp.html b/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp.html
index d694ab4..9e8ea56 100644
--- a/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,7 +14,8 @@
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.
--->
+--%>
+<html>
<body bgcolor="white">
<!-- Forward to a servlet -->
diff --git a/tomcat-cas/webapps/examples/jsp/jsptoserv/jts.html b/tomcat-cas/webapps/examples/jsp/jsptoserv/jts.html
index ec7d5ad..20aa42b 100644
--- a/tomcat-cas/webapps/examples/jsp/jsptoserv/jts.html
+++ b/tomcat-cas/webapps/examples/jsp/jsptoserv/jts.html
@@ -27,7 +27,7 @@
<h3><a href="jsptoservlet.jsp.html">Source Code for JSP calling servlet <font color="#0000FF"></a>
</font> </h3>
-<h3><a href="servletToJsp.java.html">Source Code for Servlet calling JSP
+<h3><a href="ServletToJsp.java.html">Source Code for Servlet calling JSP
<font color="#0000FF"></a> </font> </h3>
</body>
diff --git a/tomcat-cas/webapps/examples/jsp/jsptoserv/servletToJsp.java.html b/tomcat-cas/webapps/examples/jsp/jsptoserv/servletToJsp.java.html
index bf6f249..9e30da5 100644
--- a/tomcat-cas/webapps/examples/jsp/jsptoserv/servletToJsp.java.html
+++ b/tomcat-cas/webapps/examples/jsp/jsptoserv/servletToJsp.java.html
@@ -15,20 +15,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import javax.servlet.http.*;
-public class servletToJsp extends HttpServlet {
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+public class ServletToJsp extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void doGet (HttpServletRequest request,
- HttpServletResponse response) {
+ HttpServletResponse response) {
- try {
- // Set the attribute and Forward to hello.jsp
- request.setAttribute ("servletName", "servletToJsp");
- getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response);
- } catch (Exception ex) {
- ex.printStackTrace ();
- }
+ try {
+ // Set the attribute and Forward to hello.jsp
+ request.setAttribute ("servletName", "servletToJsp");
+ getServletConfig().getServletContext().getRequestDispatcher(
+ "/jsp/jsptoserv/hello.jsp").forward(request, response);
+ } catch (Exception ex) {
+ ex.printStackTrace ();
+ }
}
}
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/num/numguess.jsp b/tomcat-cas/webapps/examples/jsp/num/numguess.jsp
index cfcf6fb..a30eeb5 100644
--- a/tomcat-cas/webapps/examples/jsp/num/numguess.jsp
+++ b/tomcat-cas/webapps/examples/jsp/num/numguess.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -17,7 +17,7 @@
Number Guess Game
Written by Jason Hunter, CTO, K&A Software
http://www.servlets.com
--->
+--%>
<%@ page import = "num.NumberGuessBean" %>
diff --git a/tomcat-cas/webapps/examples/jsp/num/numguess.jsp.html b/tomcat-cas/webapps/examples/jsp/num/numguess.jsp.html
index 01fef5d..3362ac4 100644
--- a/tomcat-cas/webapps/examples/jsp/num/numguess.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/num/numguess.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -18,7 +18,7 @@
Number Guess Game
Written by Jason Hunter, CTO, K&A Software
http://www.servlets.com
--->
+--%>
<%@ page import = "num.NumberGuessBean" %>
diff --git a/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.class b/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.class
index 32fa663..cc968cd 100644
--- a/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.class
+++ b/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.class
Binary files differ
diff --git a/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.java b/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.java
index f228b82..ccc96d1 100644
--- a/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.java
+++ b/tomcat-cas/webapps/examples/jsp/plugin/applet/Clock2.java
@@ -15,10 +15,13 @@
* limitations under the License.
*/
-import java.util.*;
-import java.awt.*;
-import java.applet.*;
-import java.text.*;
+import java.applet.Applet;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
/**
* Time!
@@ -27,9 +30,10 @@
*/
public class Clock2 extends Applet implements Runnable {
+ private static final long serialVersionUID = 1L;
Thread timer; // The thread that displays clock
int lastxs, lastys, lastxm,
- lastym, lastxh, lastyh; // Dimensions used to draw hands
+ lastym, lastxh, lastyh; // Dimensions used to draw hands
SimpleDateFormat formatter; // Formats the date displayed
String lastdate; // String to hold date displayed
Font clockFaceFont; // Font for number display on clock
@@ -37,8 +41,8 @@
Color handColor; // Color of main hands and dial
Color numberColor; // Color of second hand and numbers
+ @Override
public void init() {
- int x,y;
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
currentDate = new Date();
@@ -96,6 +100,7 @@
}
// Paint is the main part of the program
+ @Override
public void paint(Graphics g) {
int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xcenter, ycenter;
String today;
@@ -112,7 +117,7 @@
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 10;
- }
+ }
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
@@ -123,30 +128,30 @@
today = formatter.format(currentDate);
xcenter=80;
ycenter=55;
-
+
// a= s* pi/2 - pi/2 (to switch 0,0 from 3:00 to 12:00)
// x = r(cos a) + xcenter, y = r(sin a) + ycenter
-
+
xs = (int)(Math.cos(s * 3.14f/30 - 3.14f/2) * 45 + xcenter);
ys = (int)(Math.sin(s * 3.14f/30 - 3.14f/2) * 45 + ycenter);
xm = (int)(Math.cos(m * 3.14f/30 - 3.14f/2) * 40 + xcenter);
ym = (int)(Math.sin(m * 3.14f/30 - 3.14f/2) * 40 + ycenter);
xh = (int)(Math.cos((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + xcenter);
yh = (int)(Math.sin((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + ycenter);
-
+
// Draw the circle and numbers
-
+
g.setFont(clockFaceFont);
g.setColor(handColor);
circle(xcenter,ycenter,50,g);
g.setColor(numberColor);
- g.drawString("9",xcenter-45,ycenter+3);
+ g.drawString("9",xcenter-45,ycenter+3);
g.drawString("3",xcenter+40,ycenter+3);
g.drawString("12",xcenter-5,ycenter-37);
g.drawString("6",xcenter-3,ycenter+45);
// Erase if necessary, and redraw
-
+
g.setColor(getBackground());
if (xs != lastxs || ys != lastys) {
g.drawLine(xcenter, ycenter, lastxs, lastys);
@@ -160,7 +165,7 @@
g.drawLine(xcenter-1, ycenter, lastxh, lastyh); }
g.setColor(numberColor);
g.drawString("", 5, 125);
- g.drawString(today, 5, 125);
+ g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, xm, ym);
@@ -174,34 +179,40 @@
currentDate=null;
}
+ @Override
public void start() {
timer = new Thread(this);
timer.start();
}
+ @Override
public void stop() {
timer = null;
}
+ @Override
public void run() {
Thread me = Thread.currentThread();
while (timer == me) {
try {
- Thread.currentThread().sleep(100);
+ Thread.sleep(100);
} catch (InterruptedException e) {
}
repaint();
}
}
+ @Override
public void update(Graphics g) {
paint(g);
}
+ @Override
public String getAppletInfo() {
return "Title: A Clock \nAuthor: Rachel Gollub, 1995 \nAn analog clock.";
}
-
+
+ @Override
public String[][] getParameterInfo() {
String[][] info = {
{"bgcolor", "hexadecimal RGB number", "The background color. Default is the color of your browser."},
diff --git a/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp b/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp
index 12db7d4..3347f6e 100644
--- a/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp
+++ b/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,7 +13,8 @@
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.
--->
+--%>
+<html>
<title> Plugin example </title>
<body bgcolor="white">
<h3> Current time is : </h3>
@@ -25,7 +25,7 @@
</jsp:plugin>
<p>
<h4>
-<font color=red>
+<font color=red>
The above applet is loaded using the Java Plugin from a jsp page using the
plugin tag.
</font>
diff --git a/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp.html b/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp.html
index b350d5e..121b375 100644
--- a/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/plugin/plugin.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,7 +14,8 @@
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.
--->
+--%>
+<html>
<title> Plugin example </title>
<body bgcolor="white">
<h3> Current time is : </h3>
@@ -26,7 +26,7 @@
</jsp:plugin>
<p>
<h4>
-<font color=red>
+<font color=red>
The above applet is loaded using the Java Plugin from a jsp page using the
plugin tag.
</font>
diff --git a/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp b/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp
index 50e0ed5..db7a466 100644
--- a/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp
+++ b/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>Error Page For Examples</title>
diff --git a/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp.html b/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp.html
index d45fb6c..950029e 100644
--- a/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/security/protected/error.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>Error Page For Examples</title>
diff --git a/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp b/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp
index bef9700..1d6495c 100644
--- a/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp
+++ b/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<%
if (request.getParameter("logoff") != null) {
session.invalidate();
diff --git a/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp.html b/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp.html
index b8a9a54..399f05c 100644
--- a/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/security/protected/index.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<%
if (request.getParameter("logoff") != null) {
session.invalidate();
diff --git a/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp b/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp
index dc7e50e..8b6d483 100644
--- a/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp
+++ b/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>Login Page for Examples</title>
diff --git a/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp.html b/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp.html
index 94e16ef..a516764 100644
--- a/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/security/protected/login.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>Login Page for Examples</title>
diff --git a/tomcat-cas/webapps/examples/jsp/sessions/carts.html b/tomcat-cas/webapps/examples/jsp/sessions/carts.html
index fe7dbb5..e972327 100644
--- a/tomcat-cas/webapps/examples/jsp/sessions/carts.html
+++ b/tomcat-cas/webapps/examples/jsp/sessions/carts.html
@@ -47,7 +47,7 @@
<INPUT TYPE=submit name="submit" value="remove">
</form>
-
+
</FONT>
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp b/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp
index e84170a..8847e58 100644
--- a/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp
+++ b/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,26 +13,26 @@
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.
--->
-
+--%>
+<html>
<jsp:useBean id="cart" scope="session" class="sessions.DummyCart" />
<jsp:setProperty name="cart" property="*" />
<%
- cart.processRequest();
+ cart.processRequest();
%>
<FONT size = 5 COLOR="#CC0000">
<br> You have the following items in your cart:
<ol>
-<%
- String[] items = cart.getItems();
- for (int i=0; i<items.length; i++) {
-%>
-<li> <% out.print(util.HTMLFilter.filter(items[i])); %>
<%
- }
+ String[] items = cart.getItems();
+ for (int i=0; i<items.length; i++) {
+%>
+<li> <% out.print(util.HTMLFilter.filter(items[i])); %>
+<%
+ }
%>
</ol>
diff --git a/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp.html b/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp.html
index 92d40c9..9c7add0 100644
--- a/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/sessions/carts.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,26 +14,26 @@
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.
--->
-
+--%>
+<html>
<jsp:useBean id="cart" scope="session" class="sessions.DummyCart" />
<jsp:setProperty name="cart" property="*" />
<%
- cart.processRequest();
+ cart.processRequest();
%>
<FONT size = 5 COLOR="#CC0000">
<br> You have the following items in your cart:
<ol>
-<%
- String[] items = cart.getItems();
- for (int i=0; i<items.length; i++) {
-%>
-<li> <% out.print(util.HTMLFilter.filter(items[i])); %>
<%
- }
+ String[] items = cart.getItems();
+ for (int i=0; i<items.length; i++) {
+%>
+<li> <% out.print(util.HTMLFilter.filter(items[i])); %>
+<%
+ }
%>
</ol>
diff --git a/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp b/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp
index 19ff087..a31890c 100644
--- a/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp
+++ b/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,9 +13,10 @@
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.
--->
+--%>
+<html>
<body>
-<%@ taglib uri="http://tomcat.apache.org/examples-taglib" prefix="eg"%>
+<%@ taglib uri="http://tomcat.apache.org/example-taglib" prefix="eg"%>
Radio stations that rock:
diff --git a/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp.html b/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp.html
index ce7fb97..30c6272 100644
--- a/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/simpletag/foo.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,9 +14,10 @@
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.
--->
+--%>
+<html>
<body>
-<%@ taglib uri="http://tomcat.apache.org/examples-taglib" prefix="eg"%>
+<%@ taglib uri="http://tomcat.apache.org/example-taglib" prefix="eg"%>
Radio stations that rock:
diff --git a/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp b/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp
index 06a3830..500a648 100644
--- a/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp
+++ b/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp
@@ -1,5 +1,4 @@
-<html>
-<!--
+<%--
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.
@@ -14,8 +13,8 @@
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.
--->
-
+--%>
+<html>
<body bgcolor="white">
<h1> Request Information </h1>
<font size="4">
@@ -45,7 +44,7 @@
<br>
Remote host: <%= util.HTMLFilter.filter(request.getRemoteHost()) %>
<br>
-Authorization scheme: <%= util.HTMLFilter.filter(request.getAuthType()) %>
+Authorization scheme: <%= util.HTMLFilter.filter(request.getAuthType()) %>
<br>
Locale: <%= request.getLocale() %>
<hr>
diff --git a/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp.html b/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp.html
index 13025fb..ad7be57 100644
--- a/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/snp/snoop.jsp.html
@@ -1,6 +1,5 @@
<html><body><pre>
-<html>
-<!--
+<%--
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.
@@ -15,8 +14,8 @@
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.
--->
-
+--%>
+<html>
<body bgcolor="white">
<h1> Request Information </h1>
<font size="4">
@@ -46,7 +45,7 @@
<br>
Remote host: <%= util.HTMLFilter.filter(request.getRemoteHost()) %>
<br>
-Authorization scheme: <%= util.HTMLFilter.filter(request.getAuthType()) %>
+Authorization scheme: <%= util.HTMLFilter.filter(request.getAuthType()) %>
<br>
Locale: <%= request.getLocale() %>
<hr>
diff --git a/tomcat-cas/webapps/examples/jsp/source.jsp b/tomcat-cas/webapps/examples/jsp/source.jsp
index efa329a..12a660c 100644
--- a/tomcat-cas/webapps/examples/jsp/source.jsp
+++ b/tomcat-cas/webapps/examples/jsp/source.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,8 +13,8 @@
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.
--->
-<%@ taglib uri="http://tomcat.apache.org/examples-taglib"
+--%>
+<%@ taglib uri="http://tomcat.apache.org/example-taglib"
prefix="eg" %>
<eg:ShowSource jspFile="<%= util.HTMLFilter.filter(request.getQueryString()) %>"/>
diff --git a/tomcat-cas/webapps/examples/jsp/source.jsp.html b/tomcat-cas/webapps/examples/jsp/source.jsp.html
index 841dd3f..8c3f367 100644
--- a/tomcat-cas/webapps/examples/jsp/source.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/source.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,8 +14,8 @@
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.
--->
-<%@ taglib uri="http://tomcat.apache.org/examples-taglib"
+--%>
+<%@ taglib uri="http://tomcat.apache.org/example-taglib"
prefix="eg" %>
<eg:ShowSource jspFile="<%= util.HTMLFilter.filter(request.getQueryString()) %>"/>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp b/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp
index 2427249..52a9011 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>Tag Examples - choose</title>
@@ -21,38 +21,34 @@
<body>
<h1>Tag Plugin Examples - <c:choose></h1>
- <hr>
- </br>
- <a href="notes.html">Plugin Introductory Notes<font <font color="#0000FF"></
-a>
+ <hr/>
<br/>
- <a href="howto.html">Brief Instructions for Writing Plugins<font color="#000
-0
-FF"></a>
+ <a href="notes.html">Plugin Introductory Notes</a>
+ <br/>
+ <a href="howto.html">Brief Instructions for Writing Plugins</a>
<br/> <br/>
- <hr>
+ <hr/>
- <font color="#000000"/>
- </br>
+ <br/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var="index" begin="0" end="4">
- # ${index}:
+ # ${index}:
<c:choose>
- <c:when test="${index == 1}">
- One!</br>
- </c:when>
- <c:when test="${index == 4}">
- Four!</br>
- </c:when>
- <c:when test="${index == 3}">
- Three!</br>
- </c:when>
- <c:otherwise>
- Huh?</br>
- </c:otherwise>
+ <c:when test="${index == 1}">
+ One!<br/>
+ </c:when>
+ <c:when test="${index == 4}">
+ Four!<br/>
+ </c:when>
+ <c:when test="${index == 3}">
+ Three!<br/>
+ </c:when>
+ <c:otherwise>
+ Huh?<br/>
+ </c:otherwise>
</c:choose>
</c:forEach>
</body>
-</html>
+</html>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp.html b/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp.html
index d95ab00..5d70ede 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/choose.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>Tag Examples - choose</title>
@@ -22,39 +22,35 @@
<body>
<h1>Tag Plugin Examples - &lt;c:choose></h1>
- <hr>
- </br>
- <a href="notes.html">Plugin Introductory Notes<font <font color="#0000FF"></
-a>
+ <hr/>
<br/>
- <a href="howto.html">Brief Instructions for Writing Plugins<font color="#000
-0
-FF"></a>
+ <a href="notes.html">Plugin Introductory Notes</a>
+ <br/>
+ <a href="howto.html">Brief Instructions for Writing Plugins</a>
<br/> <br/>
- <hr>
+ <hr/>
- <font color="#000000"/>
- </br>
+ <br/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var="index" begin="0" end="4">
- # ${index}:
+ # ${index}:
<c:choose>
- <c:when test="${index == 1}">
- One!</br>
- </c:when>
- <c:when test="${index == 4}">
- Four!</br>
- </c:when>
- <c:when test="${index == 3}">
- Three!</br>
- </c:when>
- <c:otherwise>
- Huh?</br>
- </c:otherwise>
+ <c:when test="${index == 1}">
+ One!<br/>
+ </c:when>
+ <c:when test="${index == 4}">
+ Four!<br/>
+ </c:when>
+ <c:when test="${index == 3}">
+ Three!<br/>
+ </c:when>
+ <c:otherwise>
+ Huh?<br/>
+ </c:otherwise>
</c:choose>
</c:forEach>
</body>
-</html>
+</html>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp b/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp
index 135d5ed..a7a57c5 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>Tag Plugin Examples: forEach</title>
@@ -21,18 +21,15 @@
<body>
<h1>Tag Plugin Examples - <c:forEach></h1>
- <hr>
- </br>
- <a href="notes.html">Plugin Introductory Notes<font <font color="#0000FF"></
-a>
+ <hr/>
<br/>
- <a href="howto.html">Brief Instructions for Writing Plugins<font color="#0000
-FF"></a>
+ <a href="notes.html">Plugin Introductory Notes</a>
+ <br/>
+ <a href="howto.html">Brief Instructions for Writing Plugins</a>
<br/> <br/>
- <hr>
+ <hr/>
- <font color="#000000"/>
- </br>
+ <br/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.Vector" %>
@@ -43,15 +40,15 @@
</c:forEach>
<% Vector v = new Vector();
- v.add("One"); v.add("Two"); v.add("Three"); v.add("Four");
+ v.add("One"); v.add("Two"); v.add("Three"); v.add("Four");
- pageContext.setAttribute("vector", v);
+ pageContext.setAttribute("vector", v);
%>
<h3>Iterating over a Vector</h3>
<c:forEach items="${vector}" var="item" >
- ${item}
+ ${item}
</c:forEach>
</body>
-</html>
+</html>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp.html b/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp.html
index 1d153c1..1f63f15 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/foreach.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>Tag Plugin Examples: forEach</title>
@@ -22,18 +22,15 @@
<body>
<h1>Tag Plugin Examples - &lt;c:forEach></h1>
- <hr>
- </br>
- <a href="notes.html">Plugin Introductory Notes<font <font color="#0000FF"></
-a>
+ <hr/>
<br/>
- <a href="howto.html">Brief Instructions for Writing Plugins<font color="#0000
-FF"></a>
+ <a href="notes.html">Plugin Introductory Notes</a>
+ <br/>
+ <a href="howto.html">Brief Instructions for Writing Plugins</a>
<br/> <br/>
- <hr>
+ <hr/>
- <font color="#000000"/>
- </br>
+ <br/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.Vector" %>
@@ -44,16 +41,16 @@
</c:forEach>
<% Vector v = new Vector();
- v.add("One"); v.add("Two"); v.add("Three"); v.add("Four");
+ v.add("One"); v.add("Two"); v.add("Three"); v.add("Four");
- pageContext.setAttribute("vector", v);
+ pageContext.setAttribute("vector", v);
%>
<h3>Iterating over a Vector</h3>
<c:forEach items="${vector}" var="item" >
- ${item}
+ ${item}
</c:forEach>
</body>
-</html>
+</html>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/howto.html b/tomcat-cas/webapps/examples/jsp/tagplugin/howto.html
index 02e746d..a193228 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/howto.html
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/howto.html
@@ -21,12 +21,12 @@
<body>
<h2>How to write tag plugins</h2>
<p>
- To write a plugin, you'll need to download the source for Tomcat 5.
+ To write a plugin, you'll need to download the source for Tomcat.
There are two steps:
<ol>
<li>
Implement the plugin class.<p/>
- This class, which implements
+ This class, which implements
<tt>org.apache.jasper.compiler.tagplugin.TagPlugin</tt>
instructs Jasper what Java codes to generate in place of the tag
handler calls.
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp b/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp
index ad9414a..70ad14e 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp
@@ -1,4 +1,4 @@
-<!--
+<%--
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.
@@ -13,7 +13,7 @@
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.
--->
+--%>
<html>
<head>
<title>Tag Plugin Examples: if</title>
@@ -21,25 +21,27 @@
<body>
<h1>Tag Plugin Examples - <c:if></h1>
- <hr>
- </br>
- <a href="notes.html">Plugin Introductory Notes<font <font color="#0000FF"></a>
+ <hr/>
<br/>
- <a href="howto.html">Brief Instructions for Writing Plugins<font color="#0000FF"></a>
+ <a href="notes.html">Plugin Introductory Notes</a>
+ <br/>
+ <a href="howto.html">Brief Instructions for Writing Plugins</a>
<br/> <br/>
- <hr>
+ <hr/>
- <font color="#000000"/>
- </br>
+ <br/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<h3>Set the test result to a variable</h3>
- <c:if test="${1==1}" var="theTruth" scope="session"/>
+ <c:if test="${1==1}" var="theTruth" scope="page"/>
The result of testing for (1==1) is: ${theTruth}
<h3>Conditionally execute the body</h3>
<c:if test="${2>0}">
- It's true that (2>0)!
+ <p>It's true that (2>0)! Working.</p>
+ </c:if>
+ <c:if test="${0>2}">
+ <p>It's not true that (0>2)! Failed.</p>
</c:if>
</body>
-</html>
+</html>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp.html b/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp.html
index efcefe4..ca05498 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/if.jsp.html
@@ -1,5 +1,5 @@
<html><body><pre>
-<!--
+<%--
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.
@@ -14,7 +14,7 @@
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.
--->
+--%>
<html>
<head>
<title>Tag Plugin Examples: if</title>
@@ -22,26 +22,28 @@
<body>
<h1>Tag Plugin Examples - &lt;c:if></h1>
- <hr>
- </br>
- <a href="notes.html">Plugin Introductory Notes<font <font color="#0000FF"></a>
+ <hr/>
<br/>
- <a href="howto.html">Brief Instructions for Writing Plugins<font color="#0000FF"></a>
+ <a href="notes.html">Plugin Introductory Notes</a>
+ <br/>
+ <a href="howto.html">Brief Instructions for Writing Plugins</a>
<br/> <br/>
- <hr>
+ <hr/>
- <font color="#000000"/>
- </br>
+ <br/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<h3>Set the test result to a variable</h3>
- <c:if test="${1==1}" var="theTruth" scope="session"/>
+ <c:if test="${1==1}" var="theTruth" scope="page"/>
The result of testing for (1==1) is: ${theTruth}
<h3>Conditionally execute the body</h3>
<c:if test="${2>0}">
- It's true that (2>0)!
+ <p>It's true that (2>0)! Working.</p>
+ </c:if>
+ <c:if test="${0>2}">
+ <p>It's not true that (0>2)! Failed.</p>
</c:if>
</body>
-</html>
+</html>
</pre></body></html>
diff --git a/tomcat-cas/webapps/examples/jsp/tagplugin/notes.html b/tomcat-cas/webapps/examples/jsp/tagplugin/notes.html
index 281a74c..0b10d40 100644
--- a/tomcat-cas/webapps/examples/jsp/tagplugin/notes.html
+++ b/tomcat-cas/webapps/examples/jsp/tagplugin/notes.html
@@ -21,17 +21,17 @@
<body>
<h2>Tag Plugins: Introductory Notes</h2>
<p>
- Tomcat 5 provides a framework for implementing tag plugins. The
+ Tomcat provides a framework for implementing tag plugins. The
plugins instruct Jasper, at translation time, to replace tag handler
calls with Java scriptlets.
The framework allows tag library authors to implement plugins for
their tags.
</p>
<p>
- Tomcat 5 is released with plugins for several JSTL tags. Note
+ Tomcat is released with plugins for several JSTL tags. Note
that these plugins work with JSTL 1.1 as well as JSTL 1.0, though
- the examples uses JSTL 1.1 and JSP 2.0.
- These plugins are not complete (for instance, some item types not
+ the examples uses JSTL 1.1 and JSP 2.0.
+ These plugins are not complete (for instance, some item types are not
handled in <c:if>).
They do serve as examples to show plugins in action (just
examine the generated Java files), and how they can be implemented.
diff --git a/tomcat-cas/webapps/examples/jsp/xml/xml.jsp b/tomcat-cas/webapps/examples/jsp/xml/xml.jsp
index e7ff43b..9b0c1fc 100644
--- a/tomcat-cas/webapps/examples/jsp/xml/xml.jsp
+++ b/tomcat-cas/webapps/examples/jsp/xml/xml.jsp
@@ -34,7 +34,7 @@
</head>
<body>
-This is the output of a simple JSP using XML format.
+This is the output of a simple JSP using XML format.
<br />
<div>Use a jsp:scriptlet to loop from 1 to 10: </div>
@@ -56,7 +56,7 @@
]]>
<div align="left">
- Use a jsp:expression to write the date and time in the browser's locale:
+ Use a jsp:expression to write the date and time in the browser's locale:
<jsp:expression>getDateTimeStr(request.getLocale())</jsp:expression>
</div>
diff --git a/tomcat-cas/webapps/examples/jsp/xml/xml.jsp.html b/tomcat-cas/webapps/examples/jsp/xml/xml.jsp.html
index 00d2980..b0b8274 100644
--- a/tomcat-cas/webapps/examples/jsp/xml/xml.jsp.html
+++ b/tomcat-cas/webapps/examples/jsp/xml/xml.jsp.html
@@ -35,7 +35,7 @@
</head>
<body>
-This is the output of a simple JSP using XML format.
+This is the output of a simple JSP using XML format.
<br />
<div>Use a jsp:scriptlet to loop from 1 to 10: </div>
@@ -57,7 +57,7 @@
]]>
<div align="left">
- Use a jsp:expression to write the date and time in the browser's locale:
+ Use a jsp:expression to write the date and time in the browser's locale:
<jsp:expression>getDateTimeStr(request.getLocale())</jsp:expression>
</div>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/index.jsp b/tomcat-cas/webapps/examples/servlets/chat/index.jsp
similarity index 98%
rename from tomcat-cas/webapps/examples/jsp/chat/index.jsp
rename to tomcat-cas/webapps/examples/servlets/chat/index.jsp
index b7bc0d0..5a33fcd 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/index.jsp
+++ b/tomcat-cas/webapps/examples/servlets/chat/index.jsp
@@ -1,12 +1,4 @@
-<%@page contentType="text/html; charset=UTF-8" %>
-<% if (session.getAttribute("nickname") == null) {
- response.sendRedirect("login.jsp");
- return;
-}
-%>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
-<html>
-<!--
+<%--
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.
@@ -21,7 +13,15 @@
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.
--->
+--%>
+<%@page contentType="text/html; charset=UTF-8" %>
+<% if (session.getAttribute("nickname") == null) {
+ response.sendRedirect("login.jsp");
+ return;
+}
+%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
<head>
<title>JSP Chat</title>
</head>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/index.jsp.html b/tomcat-cas/webapps/examples/servlets/chat/index.jsp.html
similarity index 98%
rename from tomcat-cas/webapps/examples/jsp/chat/index.jsp.html
rename to tomcat-cas/webapps/examples/servlets/chat/index.jsp.html
index 0b98ebf..250c249 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/index.jsp.html
+++ b/tomcat-cas/webapps/examples/servlets/chat/index.jsp.html
@@ -1,13 +1,5 @@
<html><body><pre>
-<%@page contentType="text/html; charset=UTF-8" %>
-<% if (session.getAttribute("nickname") == null) {
- response.sendRedirect("login.jsp");
- return;
-}
-%>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
-<html>
-<!--
+<%--
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.
@@ -22,7 +14,15 @@
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.
--->
+--%>
+<%@page contentType="text/html; charset=UTF-8" %>
+<% if (session.getAttribute("nickname") == null) {
+ response.sendRedirect("login.jsp");
+ return;
+}
+%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
<head>
<title>JSP Chat</title>
</head>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/login.jsp b/tomcat-cas/webapps/examples/servlets/chat/login.jsp
similarity index 98%
rename from tomcat-cas/webapps/examples/jsp/chat/login.jsp
rename to tomcat-cas/webapps/examples/servlets/chat/login.jsp
index e1c6496..8578ac9 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/login.jsp
+++ b/tomcat-cas/webapps/examples/servlets/chat/login.jsp
@@ -1,7 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<%--
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.
@@ -16,7 +13,10 @@
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.
--->
+--%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%@page contentType="text/html; charset=UTF-8" %>
+<html>
<head>
<title>JSP Chat</title>
</head>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/login.jsp.html b/tomcat-cas/webapps/examples/servlets/chat/login.jsp.html
similarity index 98%
rename from tomcat-cas/webapps/examples/jsp/chat/login.jsp.html
rename to tomcat-cas/webapps/examples/servlets/chat/login.jsp.html
index d0fbe40..699a939 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/login.jsp.html
+++ b/tomcat-cas/webapps/examples/servlets/chat/login.jsp.html
@@ -1,8 +1,5 @@
<html><body><pre>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<%--
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.
@@ -17,7 +14,10 @@
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.
--->
+--%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%@page contentType="text/html; charset=UTF-8" %>
+<html>
<head>
<title>JSP Chat</title>
</head>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/post.jsp b/tomcat-cas/webapps/examples/servlets/chat/post.jsp
similarity index 99%
rename from tomcat-cas/webapps/examples/jsp/chat/post.jsp
rename to tomcat-cas/webapps/examples/servlets/chat/post.jsp
index cc8134d..91fee7b 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/post.jsp
+++ b/tomcat-cas/webapps/examples/servlets/chat/post.jsp
@@ -1,7 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<%--
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.
@@ -16,7 +13,10 @@
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.
--->
+--%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%@page contentType="text/html; charset=UTF-8" %>
+<html>
<head>
<title>JSP Chat</title>
</head>
diff --git a/tomcat-cas/webapps/examples/jsp/chat/post.jsp.html b/tomcat-cas/webapps/examples/servlets/chat/post.jsp.html
similarity index 99%
rename from tomcat-cas/webapps/examples/jsp/chat/post.jsp.html
rename to tomcat-cas/webapps/examples/servlets/chat/post.jsp.html
index 90fa323..2ccfcbc 100644
--- a/tomcat-cas/webapps/examples/jsp/chat/post.jsp.html
+++ b/tomcat-cas/webapps/examples/servlets/chat/post.jsp.html
@@ -1,8 +1,5 @@
<html><body><pre>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<%@page contentType="text/html; charset=UTF-8" %>
-<html>
-<!--
+<%--
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.
@@ -17,7 +14,10 @@
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.
--->
+--%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%@page contentType="text/html; charset=UTF-8" %>
+<html>
<head>
<title>JSP Chat</title>
</head>
diff --git a/tomcat-cas/webapps/examples/servlets/cookies.html b/tomcat-cas/webapps/examples/servlets/cookies.html
index 659a26d..91ee584 100644
--- a/tomcat-cas/webapps/examples/servlets/cookies.html
+++ b/tomcat-cas/webapps/examples/servlets/cookies.html
@@ -24,7 +24,7 @@
<p><font color="#0000FF"><a href="servlet/CookieExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Cookie Example<font color="#0000FF"><br>
</font> </h3>
-<font color="#0000FF"></font>
+<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
@@ -36,7 +36,7 @@
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
-
+
<font color="#CC0000">// print out cookies</font>
Cookie[] cookies = request.getCookies();
diff --git a/tomcat-cas/webapps/examples/servlets/index.html b/tomcat-cas/webapps/examples/servlets/index.html
index b778706..89fbbbe 100644
--- a/tomcat-cas/webapps/examples/servlets/index.html
+++ b/tomcat-cas/webapps/examples/servlets/index.html
@@ -116,6 +116,65 @@
<p>Note: The source code for these examples does not contain all of the
source code that is actually in the example, only the important sections
of code. Code not important to understand the example has been removed
-for clarity.
+for clarity.</p>
+
+<b><u><font size="+1">Other Examples</font></u></b><br>
+<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
+
+<tr>
+ <td colspan="3">Servlet 3.0 Asynchronous processing examples:</td>
+</tr>
+<tr VALIGN=TOP>
+ <td>async0 </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="../async/async0"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+<tr VALIGN=TOP>
+ <td>async1 </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="../async/async1"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+<tr VALIGN=TOP>
+ <td>async2 </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="../async/async2"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+<tr VALIGN=TOP>
+ <td>async3 </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="../async/async3"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+<tr VALIGN=TOP>
+ <td>stockticker </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="../async/stockticker"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+
+<tr>
+ <td colspan="3">Comet processing example:<br />
+ See the <strong>"Advanced IO"</strong> chapter in the User Guide for
+ details. This example only works with the HTTP NIO or HTTP APR/native
+ connectors as these are the only connectors that support Comet.</td>
+</tr>
+<tr VALIGN=TOP>
+ <td>Comet Chat </td>
+ <td VALIGN=TOP WIDTH="30%">
+ <a href="chat/"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP> Execute</a>
+ </td>
+ <td WIDTH="30%"></td>
+</tr>
+
+</table>
+
</body>
</html>
diff --git a/tomcat-cas/webapps/examples/servlets/reqinfo.html b/tomcat-cas/webapps/examples/servlets/reqinfo.html
index 4ac664b..97a54ce 100644
--- a/tomcat-cas/webapps/examples/servlets/reqinfo.html
+++ b/tomcat-cas/webapps/examples/servlets/reqinfo.html
@@ -24,7 +24,7 @@
<p><font color="#0000FF"><a href="servlet/RequestInfoExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Request Info Example<font color="#0000FF"><br>
</font> </h3>
-<font color="#0000FF"></font>
+<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
diff --git a/tomcat-cas/webapps/examples/servlets/reqparams.html b/tomcat-cas/webapps/examples/servlets/reqparams.html
index b0de031..42ec507 100644
--- a/tomcat-cas/webapps/examples/servlets/reqparams.html
+++ b/tomcat-cas/webapps/examples/servlets/reqparams.html
@@ -24,7 +24,7 @@
<p><font color="#0000FF"><a href="servlet/RequestParamExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Request Parameter Example<font color="#0000FF"><br>
</font> </h3>
-<font color="#0000FF"></font>
+<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> java.util.*;
<font color="#0000FF">import</font> javax.servlet.*;
diff --git a/tomcat-cas/webapps/examples/servlets/sessions.html b/tomcat-cas/webapps/examples/servlets/sessions.html
index 65fc7fd..febef83 100644
--- a/tomcat-cas/webapps/examples/servlets/sessions.html
+++ b/tomcat-cas/webapps/examples/servlets/sessions.html
@@ -24,7 +24,7 @@
<p><font color="#0000FF"><a href="servlet/SessionExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Session Example<font color="#0000FF"><br>
</font> </h3>
-<font color="#0000FF"></font>
+<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> java.util.*;
<font color="#0000FF">import</font> javax.servlet.*;
@@ -37,7 +37,7 @@
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
-
+
HttpSession session = request.getSession(true);
<font color="#CC0000">// print session info</font>
diff --git a/tomcat-cas/webapps/examples/websocket-deprecated/chat.html b/tomcat-cas/webapps/examples/websocket-deprecated/chat.html
new file mode 100644
index 0000000..9c49d63
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket-deprecated/chat.html
@@ -0,0 +1,125 @@
+<!--
+ 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.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Apache Tomcat WebSocket Examples: Chat</title>
+ <style type="text/css">
+ input#chat {
+ width: 410px
+ }
+
+ #console-container {
+ width: 400px;
+ }
+
+ #console {
+ border: 1px solid #CCCCCC;
+ border-right-color: #999999;
+ border-bottom-color: #999999;
+ height: 170px;
+ overflow-y: scroll;
+ padding: 5px;
+ width: 100%;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+ </style>
+ <script type="text/javascript">
+ var Chat = {};
+
+ Chat.socket = null;
+
+ Chat.connect = (function(host) {
+ if ('WebSocket' in window) {
+ Chat.socket = new WebSocket(host);
+ } else if ('MozWebSocket' in window) {
+ Chat.socket = new MozWebSocket(host);
+ } else {
+ Console.log('Error: WebSocket is not supported by this browser.');
+ return;
+ }
+
+ Chat.socket.onopen = function () {
+ Console.log('Info: WebSocket connection opened.');
+ document.getElementById('chat').onkeydown = function(event) {
+ if (event.keyCode == 13) {
+ Chat.sendMessage();
+ }
+ };
+ };
+
+ Chat.socket.onclose = function () {
+ document.getElementById('chat').onkeydown = null;
+ Console.log('Info: WebSocket closed.');
+ };
+
+ Chat.socket.onmessage = function (message) {
+ Console.log(message.data);
+ };
+ });
+
+ Chat.initialize = function() {
+ if (window.location.protocol == 'http:') {
+ Chat.connect('ws://' + window.location.host + '/examples/websocket/tc7/chat');
+ } else {
+ Chat.connect('wss://' + window.location.host + '/examples/websocket/tc7/chat');
+ }
+ };
+
+ Chat.sendMessage = (function() {
+ var message = document.getElementById('chat').value;
+ if (message != '') {
+ Chat.socket.send(message);
+ document.getElementById('chat').value = '';
+ }
+ });
+
+ var Console = {};
+
+ Console.log = (function(message) {
+ var console = document.getElementById('console');
+ var p = document.createElement('p');
+ p.style.wordWrap = 'break-word';
+ p.innerHTML = message;
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ });
+
+ Chat.initialize();
+
+ </script>
+</head>
+<body>
+<noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</h2></noscript>
+<div>
+ <p>
+ <input type="text" placeholder="type and press enter to chat" id="chat">
+ </p>
+ <div id="console-container">
+ <div id="console"></div>
+ </div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket-deprecated/echo.html b/tomcat-cas/webapps/examples/websocket-deprecated/echo.html
new file mode 100644
index 0000000..51b61a5
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket-deprecated/echo.html
@@ -0,0 +1,160 @@
+<!--
+ 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.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Apache Tomcat WebSocket Examples: Echo</title>
+ <style type="text/css">
+ #connect-container {
+ float: left;
+ width: 400px
+ }
+
+ #connect-container div {
+ padding: 5px;
+ }
+
+ #console-container {
+ float: left;
+ margin-left: 15px;
+ width: 400px;
+ }
+
+ #console {
+ border: 1px solid #CCCCCC;
+ border-right-color: #999999;
+ border-bottom-color: #999999;
+ height: 170px;
+ overflow-y: scroll;
+ padding: 5px;
+ width: 100%;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+ </style>
+ <script type="text/javascript">
+ var ws = null;
+
+ function setConnected(connected) {
+ document.getElementById('connect').disabled = connected;
+ document.getElementById('disconnect').disabled = !connected;
+ document.getElementById('echo').disabled = !connected;
+ }
+
+ function connect() {
+ var target = document.getElementById('target').value;
+ if (target == '') {
+ alert('Please select server side connection implementation.');
+ return;
+ }
+ if ('WebSocket' in window) {
+ ws = new WebSocket(target);
+ } else if ('MozWebSocket' in window) {
+ ws = new MozWebSocket(target);
+ } else {
+ alert('WebSocket is not supported by this browser.');
+ return;
+ }
+ ws.onopen = function () {
+ setConnected(true);
+ log('Info: WebSocket connection opened.');
+ };
+ ws.onmessage = function (event) {
+ log('Received: ' + event.data);
+ };
+ ws.onclose = function () {
+ setConnected(false);
+ log('Info: WebSocket connection closed.');
+ };
+ }
+
+ function disconnect() {
+ if (ws != null) {
+ ws.close();
+ ws = null;
+ }
+ setConnected(false);
+ }
+
+ function echo() {
+ if (ws != null) {
+ var message = document.getElementById('message').value;
+ log('Sent: ' + message);
+ ws.send(message);
+ } else {
+ alert('WebSocket connection not established, please connect.');
+ }
+ }
+
+ function updateTarget(target) {
+ if (window.location.protocol == 'http:') {
+ document.getElementById('target').value = 'ws://' + window.location.host + target;
+ } else {
+ document.getElementById('target').value = 'wss://' + window.location.host + target;
+ }
+ }
+
+ function log(message) {
+ var console = document.getElementById('console');
+ var p = document.createElement('p');
+ p.style.wordWrap = 'break-word';
+ p.appendChild(document.createTextNode(message));
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ }
+ </script>
+</head>
+<body>
+<noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</h2></noscript>
+<div>
+ <div id="connect-container">
+ <div>
+ <span>Connect using:</span>
+ <!-- echo example using streams on the server side -->
+ <input id="radio1" type="radio" name="group1" value="/examples/websocket/tc7/echoStream"
+ onclick="updateTarget(this.value);"> <label for="radio1">streams</label>
+ <!-- echo example using messages on the server side -->
+ <input id="radio2" type="radio" name="group1" value="/examples/websocket/tc7/echoMessage"
+ onclick="updateTarget(this.value);"> <label for="radio2">messages</label>
+ </div>
+ <div>
+ <input id="target" type="text" size="40" style="width: 350px"/>
+ </div>
+ <div>
+ <button id="connect" onclick="connect();">Connect</button>
+ <button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button>
+ </div>
+ <div>
+ <textarea id="message" style="width: 350px">Here is a message!</textarea>
+ </div>
+ <div>
+ <button id="echo" onclick="echo();" disabled="disabled">Echo message</button>
+ </div>
+ </div>
+ <div id="console-container">
+ <div id="console"></div>
+ </div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket-deprecated/index.html b/tomcat-cas/webapps/examples/websocket-deprecated/index.html
new file mode 100644
index 0000000..6f076e3
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket-deprecated/index.html
@@ -0,0 +1,33 @@
+<!--
+ 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.
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv=Content-Type content="text/html">
+ <title>Apache Tomcat Deprecated WebSocket Examples</title>
+</head>
+<body>
+<h3>Apache Tomcat Deprecated WebSocket Examples</h3>
+<ul>
+ <li><a href="echo.html">Echo example</a></li>
+ <li><a href="chat.html">Chat example</a></li>
+ <li><a href="snake.html">Multiplayer snake example</a></li>
+</ul>
+<p>This API has been deprecated. The examples are also available using the JSR
+ 356 <a href="../websocket/index.xhtml">Java WebSocket 1.1 API</a>.</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket-deprecated/snake.html b/tomcat-cas/webapps/examples/websocket-deprecated/snake.html
new file mode 100644
index 0000000..d52149e
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket-deprecated/snake.html
@@ -0,0 +1,258 @@
+<!--
+ 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.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <title>Apache Tomcat WebSocket Examples: Multiplayer Snake</title>
+ <style type="text/css">
+ #playground {
+ width: 640px;
+ height: 480px;
+ background-color: #000;
+ }
+
+ #console-container {
+ float: left;
+ margin-left: 15px;
+ width: 300px;
+ }
+
+ #console {
+ border: 1px solid #CCCCCC;
+ border-right-color: #999999;
+ border-bottom-color: #999999;
+ height: 480px;
+ overflow-y: scroll;
+ padding-left: 5px;
+ padding-right: 5px;
+ width: 100%;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+ </style>
+</head>
+<body>
+ <noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</h2></noscript>
+ <div style="float: left">
+ <canvas id="playground" width="640" height="480"></canvas>
+ </div>
+ <div id="console-container">
+ <div id="console"></div>
+ </div>
+ <script type="text/javascript">
+
+ var Game = {};
+
+ Game.fps = 30;
+ Game.socket = null;
+ Game.nextFrame = null;
+ Game.interval = null;
+ Game.direction = 'none';
+ Game.gridSize = 10;
+
+ function Snake() {
+ this.snakeBody = [];
+ this.color = null;
+ }
+
+ Snake.prototype.draw = function(context) {
+ for (var id in this.snakeBody) {
+ context.fillStyle = this.color;
+ context.fillRect(this.snakeBody[id].x, this.snakeBody[id].y, Game.gridSize, Game.gridSize);
+ }
+ };
+
+ Game.initialize = function() {
+ this.entities = [];
+ canvas = document.getElementById('playground');
+ if (!canvas.getContext) {
+ Console.log('Error: 2d canvas not supported by this browser.');
+ return;
+ }
+ this.context = canvas.getContext('2d');
+ window.addEventListener('keydown', function (e) {
+ var code = e.keyCode;
+ if (code > 36 && code < 41) {
+ switch (code) {
+ case 37:
+ if (Game.direction != 'east') Game.setDirection('west');
+ break;
+ case 38:
+ if (Game.direction != 'south') Game.setDirection('north');
+ break;
+ case 39:
+ if (Game.direction != 'west') Game.setDirection('east');
+ break;
+ case 40:
+ if (Game.direction != 'north') Game.setDirection('south');
+ break;
+ }
+ }
+ }, false);
+ if (window.location.protocol == 'http:') {
+ Game.connect('ws://' + window.location.host + '/examples/websocket/tc7/snake');
+ } else {
+ Game.connect('wss://' + window.location.host + '/examples/websocket/tc7/snake');
+ }
+ };
+
+ Game.setDirection = function(direction) {
+ Game.direction = direction;
+ Game.socket.send(direction);
+ Console.log('Sent: Direction ' + direction);
+ };
+
+ Game.startGameLoop = function() {
+ if (window.webkitRequestAnimationFrame) {
+ Game.nextFrame = function () {
+ webkitRequestAnimationFrame(Game.run);
+ };
+ } else if (window.mozRequestAnimationFrame) {
+ Game.nextFrame = function () {
+ mozRequestAnimationFrame(Game.run);
+ };
+ } else {
+ Game.interval = setInterval(Game.run, 1000 / Game.fps);
+ }
+ if (Game.nextFrame != null) {
+ Game.nextFrame();
+ }
+ };
+
+ Game.stopGameLoop = function () {
+ Game.nextFrame = null;
+ if (Game.interval != null) {
+ clearInterval(Game.interval);
+ }
+ };
+
+ Game.draw = function() {
+ this.context.clearRect(0, 0, 640, 480);
+ for (var id in this.entities) {
+ this.entities[id].draw(this.context);
+ }
+ };
+
+ Game.addSnake = function(id, color) {
+ Game.entities[id] = new Snake();
+ Game.entities[id].color = color;
+ };
+
+ Game.updateSnake = function(id, snakeBody) {
+ if (typeof Game.entities[id] != "undefined") {
+ Game.entities[id].snakeBody = snakeBody;
+ }
+ };
+
+ Game.removeSnake = function(id) {
+ Game.entities[id] = null;
+ // Force GC.
+ delete Game.entities[id];
+ };
+
+ Game.run = (function() {
+ var skipTicks = 1000 / Game.fps, nextGameTick = (new Date).getTime();
+
+ return function() {
+ while ((new Date).getTime() > nextGameTick) {
+ nextGameTick += skipTicks;
+ }
+ Game.draw();
+ if (Game.nextFrame != null) {
+ Game.nextFrame();
+ }
+ };
+ })();
+
+ Game.connect = (function(host) {
+ if ('WebSocket' in window) {
+ Game.socket = new WebSocket(host);
+ } else if ('MozWebSocket' in window) {
+ Game.socket = new MozWebSocket(host);
+ } else {
+ Console.log('Error: WebSocket is not supported by this browser.');
+ return;
+ }
+
+ Game.socket.onopen = function () {
+ // Socket open.. start the game loop.
+ Console.log('Info: WebSocket connection opened.');
+ Console.log('Info: Press an arrow key to begin.');
+ Game.startGameLoop();
+ setInterval(function() {
+ // Prevent server read timeout.
+ Game.socket.send('ping');
+ }, 5000);
+ };
+
+ Game.socket.onclose = function () {
+ Console.log('Info: WebSocket closed.');
+ Game.stopGameLoop();
+ };
+
+ Game.socket.onmessage = function (message) {
+ // _Potential_ security hole, consider using json lib to parse data in production.
+ var packet = eval('(' + message.data + ')');
+ switch (packet.type) {
+ case 'update':
+ for (var i = 0; i < packet.data.length; i++) {
+ Game.updateSnake(packet.data[i].id, packet.data[i].body);
+ }
+ break;
+ case 'join':
+ for (var j = 0; j < packet.data.length; j++) {
+ Game.addSnake(packet.data[j].id, packet.data[j].color);
+ }
+ break;
+ case 'leave':
+ Game.removeSnake(packet.id);
+ break;
+ case 'dead':
+ Console.log('Info: Your snake is dead, bad luck!');
+ Game.direction = 'none';
+ break;
+ case 'kill':
+ Console.log('Info: Head shot!');
+ break;
+ }
+ };
+ });
+
+ var Console = {};
+
+ Console.log = (function(message) {
+ var console = document.getElementById('console');
+ var p = document.createElement('p');
+ p.style.wordWrap = 'break-word';
+ p.innerHTML = message;
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ });
+
+ Game.initialize();
+ </script>
+</body>
+</html>
diff --git a/tomcat-cas/webapps/examples/websocket/chat.xhtml b/tomcat-cas/webapps/examples/websocket/chat.xhtml
new file mode 100644
index 0000000..5e31dab
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket/chat.xhtml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Apache Tomcat WebSocket Examples: Chat</title>
+ <style type="text/css"><![CDATA[
+ input#chat {
+ width: 410px
+ }
+
+ #console-container {
+ width: 400px;
+ }
+
+ #console {
+ border: 1px solid #CCCCCC;
+ border-right-color: #999999;
+ border-bottom-color: #999999;
+ height: 170px;
+ overflow-y: scroll;
+ padding: 5px;
+ width: 100%;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+ ]]></style>
+ <script type="application/javascript"><![CDATA[
+ var Chat = {};
+
+ Chat.socket = null;
+
+ Chat.connect = (function(host) {
+ if ('WebSocket' in window) {
+ Chat.socket = new WebSocket(host);
+ } else if ('MozWebSocket' in window) {
+ Chat.socket = new MozWebSocket(host);
+ } else {
+ Console.log('Error: WebSocket is not supported by this browser.');
+ return;
+ }
+
+ Chat.socket.onopen = function () {
+ Console.log('Info: WebSocket connection opened.');
+ document.getElementById('chat').onkeydown = function(event) {
+ if (event.keyCode == 13) {
+ Chat.sendMessage();
+ }
+ };
+ };
+
+ Chat.socket.onclose = function () {
+ document.getElementById('chat').onkeydown = null;
+ Console.log('Info: WebSocket closed.');
+ };
+
+ Chat.socket.onmessage = function (message) {
+ Console.log(message.data);
+ };
+ });
+
+ Chat.initialize = function() {
+ if (window.location.protocol == 'http:') {
+ Chat.connect('ws://' + window.location.host + '/examples/websocket/chat');
+ } else {
+ Chat.connect('wss://' + window.location.host + '/examples/websocket/chat');
+ }
+ };
+
+ Chat.sendMessage = (function() {
+ var message = document.getElementById('chat').value;
+ if (message != '') {
+ Chat.socket.send(message);
+ document.getElementById('chat').value = '';
+ }
+ });
+
+ var Console = {};
+
+ Console.log = (function(message) {
+ var console = document.getElementById('console');
+ var p = document.createElement('p');
+ p.style.wordWrap = 'break-word';
+ p.innerHTML = message;
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ });
+
+ Chat.initialize();
+
+
+ document.addEventListener("DOMContentLoaded", function() {
+ // Remove elements with "noscript" class - <noscript> is not allowed in XHTML
+ var noscripts = document.getElementsByClassName("noscript");
+ for (var i = 0; i < noscripts.length; i++) {
+ noscripts[i].parentNode.removeChild(noscripts[i]);
+ }
+ }, false);
+
+ ]]></script>
+</head>
+<body>
+<div class="noscript"><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</h2></div>
+<div>
+ <p>
+ <input type="text" placeholder="type and press enter to chat" id="chat" />
+ </p>
+ <div id="console-container">
+ <div id="console"/>
+ </div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket/drawboard.xhtml b/tomcat-cas/webapps/examples/websocket/drawboard.xhtml
new file mode 100644
index 0000000..342bef4
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket/drawboard.xhtml
@@ -0,0 +1,897 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Apache Tomcat WebSocket Examples: Drawboard</title>
+ <style type="text/css"><![CDATA[
+
+ body {
+ font-family: Arial, sans-serif;
+ font-size: 11pt;
+ background-color: #eeeeea;
+ padding: 10px;
+ }
+
+ #console-container {
+ float: left;
+ background-color: #fff;
+ width: 250px;
+ }
+
+ #console {
+ font-size: 10pt;
+ height: 600px;
+ overflow-y: scroll;
+ padding-left: 5px;
+ padding-right: 5px;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+
+ #drawContainer {
+ float: left;
+ display: none;
+ margin-right: 25px;
+ }
+
+ #drawContainer canvas {
+ display: block;
+ -ms-touch-action: none;
+ touch-action: none; /* Disable touch behaviors, like pan and zoom */
+ cursor: crosshair;
+ }
+
+ #labelContainer {
+ margin-bottom: 15px;
+ }
+
+ #drawContainer, #console-container {
+ box-shadow: 0px 0px 8px 3px #bbb;
+ border: 1px solid #CCCCCC;
+ }
+
+ ]]></style>
+ <script type="application/javascript"><![CDATA[
+ "use strict";
+
+ (function() {
+
+ document.addEventListener("DOMContentLoaded", function() {
+ // Remove elements with "noscript" class - <noscript> is not
+ // allowed in XHTML
+ var noscripts = document.getElementsByClassName("noscript");
+ for (var i = 0; i < noscripts.length; i++) {
+ noscripts[i].parentNode.removeChild(noscripts[i]);
+ }
+
+ // Add script for expand content.
+ var expandElements = document.getElementsByClassName("expand");
+ for (var ixx = 0; ixx < expandElements.length; ixx++) {
+ (function(el) {
+ var expandContent = document.getElementById(el.getAttribute("data-content-id"));
+ expandContent.style.display = "none";
+ var arrow = document.createTextNode("◢ ");
+ var arrowSpan = document.createElement("span");
+ arrowSpan.appendChild(arrow);
+
+ var link = document.createElement("a");
+ link.setAttribute("href", "#!");
+ while (el.firstChild != null) {
+ link.appendChild(el.removeChild(el.firstChild));
+ }
+ el.appendChild(arrowSpan);
+ el.appendChild(link);
+
+ var textSpan = document.createElement("span");
+ textSpan.setAttribute("style", "font-weight: normal;");
+ textSpan.appendChild(document.createTextNode(" (click to expand)"));
+ el.appendChild(textSpan);
+
+
+ var visible = true;
+
+ var switchExpand = function() {
+ visible = !visible;
+ expandContent.style.display = visible ? "block" : "none";
+ arrowSpan.style.color = visible ? "#000" : "#888";
+ return false;
+ };
+
+ link.onclick = switchExpand;
+ switchExpand();
+
+ })(expandElements[ixx]);
+ }
+
+
+ var Console = {};
+
+ Console.log = (function() {
+ var consoleContainer =
+ document.getElementById("console-container");
+ var console = document.createElement("div");
+ console.setAttribute("id", "console");
+ consoleContainer.appendChild(console);
+
+ return function(message) {
+ var p = document.createElement('p');
+ p.style.wordWrap = "break-word";
+ p.appendChild(document.createTextNode(message));
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ }
+ })();
+
+
+ function Room(drawContainer) {
+
+ /* A pausable event forwarder that can be used to pause and
+ * resume handling of events (e.g. when we need to wait
+ * for a Image's load event before we can process further
+ * WebSocket messages).
+ * The object's callFunction(func) should be called from an
+ * event handler and give the function to handle the event as
+ * argument.
+ * Call pauseProcessing() to suspend event forwarding and
+ * resumeProcessing() to resume it.
+ */
+ function PausableEventForwarder() {
+
+ var pauseProcessing = false;
+ // Queue for buffering functions to be called.
+ var functionQueue = [];
+
+ this.callFunction = function(func) {
+ // If message processing is paused, we push it
+ // into the queue - otherwise we process it directly.
+ if (pauseProcessing) {
+ functionQueue.push(func);
+ } else {
+ func();
+ }
+ };
+
+ this.pauseProcessing = function() {
+ pauseProcessing = true;
+ };
+
+ this.resumeProcessing = function() {
+ pauseProcessing = false;
+
+ // Process all queued functions until some handler calls
+ // pauseProcessing() again.
+ while (functionQueue.length > 0 && !pauseProcessing) {
+ var func = functionQueue.pop();
+ func();
+ }
+ };
+ }
+
+ // The WebSocket object.
+ var socket;
+ // ID of the timer which sends ping messages.
+ var pingTimerId;
+
+ var isStarted = false;
+ var playerCount = 0;
+
+ // An array of PathIdContainer objects that the server
+ // did not yet handle.
+ // They are ordered by id (ascending).
+ var pathsNotHandled = [];
+
+ var nextMsgId = 1;
+
+ var canvasDisplay = document.createElement("canvas");
+ var canvasBackground = document.createElement("canvas");
+ var canvasServerImage = document.createElement("canvas");
+ var canvasArray = [canvasDisplay, canvasBackground,
+ canvasServerImage];
+ canvasDisplay.addEventListener("mousedown", function(e) {
+ // Prevent default mouse event to prevent browsers from marking text
+ // (and Chrome from displaying the "text" cursor).
+ e.preventDefault();
+ }, false);
+
+ var labelPlayerCount = document.createTextNode("0");
+ var optionContainer = document.createElement("div");
+
+
+ var canvasDisplayCtx = canvasDisplay.getContext("2d");
+ var canvasBackgroundCtx = canvasBackground.getContext("2d");
+ var canvasServerImageCtx = canvasServerImage.getContext("2d");
+ var canvasMouseMoveHandler;
+ var canvasMouseDownHandler;
+
+ var isActive = false;
+ var mouseInWindow = false;
+ var mouseDown = false;
+ var currentMouseX = 0, currentMouseY = 0;
+ var currentPreviewPath = null;
+
+ var availableColors = [];
+ var currentColorIndex;
+ var colorContainers;
+ var previewTransparency = 0.65;
+
+ var availableThicknesses = [2, 3, 6, 10, 16, 28, 50];
+ var currentThicknessIndex;
+ var thicknessContainers;
+
+ var availableDrawTypes = [
+ { name: "Brush", id: 1, continuous: true },
+ { name: "Line", id: 2, continuous: false },
+ { name: "Rectangle", id: 3, continuous: false },
+ { name: "Ellipse", id: 4, continuous: false }
+ ];
+ var currentDrawTypeIndex;
+ var drawTypeContainers;
+
+
+ var labelContainer = document.getElementById("labelContainer");
+ var placeholder = document.createElement("div");
+ placeholder.appendChild(document.createTextNode("Loading... "));
+ var progressElem = document.createElement("progress");
+ placeholder.appendChild(progressElem);
+
+ labelContainer.appendChild(placeholder);
+
+ function rgb(color) {
+ return "rgba(" + color[0] + "," + color[1] + ","
+ + color[2] + "," + color[3] + ")";
+ }
+
+ function PathIdContainer(path, id) {
+ this.path = path;
+ this.id = id;
+ }
+
+ function Path(type, color, thickness, x1, y1, x2, y2, lastInChain) {
+ this.type = type;
+ this.color = color;
+ this.thickness = thickness;
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ this.lastInChain = lastInChain;
+
+ function ellipse(ctx, x, y, w, h) {
+ /* Drawing a ellipse cannot be done directly in a
+ * CanvasRenderingContext2D - we need to use drawArc()
+ * in conjunction with scaling the context so that we
+ * get the needed proportion.
+ */
+ ctx.save();
+
+ // Translate and scale the context so that we can draw
+ // an arc at (0, 0) with a radius of 1.
+ ctx.translate(x + w / 2, y + h / 2);
+ ctx.scale(w / 2, h / 2);
+
+ ctx.beginPath();
+ ctx.arc(0, 0, 1, 0, Math.PI * 2, false);
+
+ ctx.restore();
+ }
+
+ this.draw = function(ctx) {
+ ctx.beginPath();
+ ctx.lineCap = "round";
+ ctx.lineWidth = thickness;
+ var style = rgb(color);
+ ctx.strokeStyle = style;
+
+ if (x1 == x2 && y1 == y2) {
+ // Always draw as arc to meet the behavior
+ // in Java2D.
+ ctx.fillStyle = style;
+ ctx.arc(x1, y1, thickness / 2.0, 0,
+ Math.PI * 2.0, false);
+ ctx.fill();
+ } else {
+ if (type == 1 || type == 2) {
+ // Draw a line.
+ ctx.moveTo(x1, y1);
+ ctx.lineTo(x2, y2);
+ ctx.stroke();
+ } else if (type == 3) {
+ // Draw a rectangle.
+ if (x1 == x2 || y1 == y2) {
+ // Draw as line
+ ctx.moveTo(x1, y1);
+ ctx.lineTo(x2, y2);
+ ctx.stroke();
+ } else {
+ ctx.strokeRect(x1, y1, x2 - x1, y2 - y1);
+ }
+ } else if (type == 4) {
+ // Draw a ellipse.
+ ellipse(ctx, x1, y1, x2 - x1, y2 - y1);
+ ctx.closePath();
+ ctx.stroke();
+ }
+ }
+ };
+ }
+
+
+ function connect() {
+ var host = (window.location.protocol == "https:"
+ ? "wss://" : "ws://") + window.location.host
+ + "/examples/websocket/drawboard";
+ socket = new WebSocket(host);
+
+ /* Use a pausable event forwarder.
+ * This is needed when we load an Image object with data
+ * from a previous message, because we must wait until the
+ * Image's load event it raised before we can use it (and
+ * in the meantime the socket.message event could be
+ * raised).
+ * Therefore we need this pausable event handler to handle
+ * e.g. socket.onmessage and socket.onclose.
+ */
+ var eventForwarder = new PausableEventForwarder();
+
+ socket.onopen = function () {
+ // Socket has opened. Now wait for the server to
+ // send us the initial packet.
+ Console.log("WebSocket connection opened.");
+
+ // Set up a timer for pong messages.
+ pingTimerId = window.setInterval(function() {
+ socket.send("0");
+ }, 30000);
+ };
+
+ socket.onclose = function () {
+ eventForwarder.callFunction(function() {
+ Console.log("WebSocket connection closed.");
+ disableControls();
+
+ // Disable pong timer.
+ window.clearInterval(pingTimerId);
+ });
+ };
+
+ // Handles an incoming Websocket message.
+ var handleOnMessage = function(message) {
+
+ // Split joined message and process them
+ // individually.
+ var messages = message.data.split(";");
+ for (var msgArrIdx = 0; msgArrIdx < messages.length;
+ msgArrIdx++) {
+ var msg = messages[msgArrIdx];
+ var type = msg.substring(0, 1);
+
+ if (type == "0") {
+ // Error message.
+ var error = msg.substring(1);
+ // Log it to the console and show an alert.
+ Console.log("Error: " + error);
+ alert(error);
+
+ } else {
+ if (!isStarted) {
+ if (type == "2") {
+ // Initial message. It contains the
+ // number of players.
+ // After this message we will receive
+ // a binary message containing the current
+ // room image as PNG.
+ playerCount = parseInt(msg.substring(1));
+
+ refreshPlayerCount();
+
+ // The next message will be a binary
+ // message containing the room images
+ // as PNG. Therefore we temporarily swap
+ // the message handler.
+ var originalHandler = handleOnMessage;
+ handleOnMessage = function(message) {
+ // First, we restore the original handler.
+ handleOnMessage = originalHandler;
+
+ // Read the image.
+ var blob = message.data;
+ // Create new blob with correct MIME type.
+ blob = new Blob([blob], {type : "image/png"});
+
+ var url = URL.createObjectURL(blob);
+
+ var img = new Image();
+
+ // We must wait until the onload event is
+ // raised until we can draw the image onto
+ // the canvas.
+ // Therefore we need to pause the event
+ // forwarder until the image is loaded.
+ eventForwarder.pauseProcessing();
+
+ img.onload = function() {
+
+ // Release the object URL.
+ URL.revokeObjectURL(url);
+
+ // Set the canvases to the correct size.
+ for (var i = 0; i < canvasArray.length; i++) {
+ canvasArray[i].width = img.width;
+ canvasArray[i].height = img.height;
+ }
+
+ // Now draw the image on the last canvas.
+ canvasServerImageCtx.clearRect(0, 0,
+ canvasServerImage.width,
+ canvasServerImage.height);
+ canvasServerImageCtx.drawImage(img, 0, 0);
+
+ // Draw it on the background canvas.
+ canvasBackgroundCtx.drawImage(canvasServerImage,
+ 0, 0);
+
+ isStarted = true;
+ startControls();
+
+ // Refresh the display canvas.
+ refreshDisplayCanvas();
+
+
+ // Finally, resume the event forwarder.
+ eventForwarder.resumeProcessing();
+ };
+
+ img.src = url;
+ };
+ }
+ } else {
+ if (type == "3") {
+ // The number of players in this room changed.
+ var playerAdded = msg.substring(1) == "+";
+ playerCount += playerAdded ? 1 : -1;
+ refreshPlayerCount();
+
+ Console.log("Player " + (playerAdded
+ ? "joined." : "left."));
+
+ } else if (type == "1") {
+ // We received a new DrawMessage.
+ var maxLastHandledId = -1;
+ var drawMessages = msg.substring(1).split("|");
+ for (var i = 0; i < drawMessages.length; i++) {
+ var elements = drawMessages[i].split(",");
+ var lastHandledId = parseInt(elements[0]);
+ maxLastHandledId = Math.max(maxLastHandledId,
+ lastHandledId);
+
+ var path = new Path(
+ parseInt(elements[1]),
+ [parseInt(elements[2]),
+ parseInt(elements[3]),
+ parseInt(elements[4]),
+ parseInt(elements[5]) / 255.0],
+ parseFloat(elements[6]),
+ parseFloat(elements[7]),
+ parseFloat(elements[8]),
+ parseFloat(elements[9]),
+ parseFloat(elements[10]),
+ elements[11] != "0");
+
+ // Draw the path onto the last canvas.
+ path.draw(canvasServerImageCtx);
+ }
+
+ // Draw the last canvas onto the background one.
+ canvasBackgroundCtx.drawImage(canvasServerImage,
+ 0, 0);
+
+ // Now go through the pathsNotHandled array and
+ // remove the paths that were already handled by
+ // the server.
+ while (pathsNotHandled.length > 0
+ && pathsNotHandled[0].id <= maxLastHandledId)
+ pathsNotHandled.shift();
+
+ // Now me must draw the remaining paths onto
+ // the background canvas.
+ for (var i = 0; i < pathsNotHandled.length; i++) {
+ pathsNotHandled[i].path.draw(canvasBackgroundCtx);
+ }
+
+ refreshDisplayCanvas();
+ }
+ }
+ }
+ }
+ };
+
+ socket.onmessage = function(message) {
+ eventForwarder.callFunction(function() {
+ handleOnMessage(message);
+ });
+ };
+
+ }
+
+
+ function refreshPlayerCount() {
+ labelPlayerCount.nodeValue = String(playerCount);
+ }
+
+ function refreshDisplayCanvas() {
+ if (!isActive) { // Don't draw a curser when not active.
+ return;
+ }
+
+ canvasDisplayCtx.drawImage(canvasBackground, 0, 0);
+ if (currentPreviewPath != null) {
+ // Draw the preview path.
+ currentPreviewPath.draw(canvasDisplayCtx);
+
+ } else if (mouseInWindow && !mouseDown) {
+ canvasDisplayCtx.beginPath();
+ var color = availableColors[currentColorIndex].slice(0);
+ color[3] = previewTransparency;
+ canvasDisplayCtx.fillStyle = rgb(color);
+
+ canvasDisplayCtx.arc(currentMouseX, currentMouseY,
+ availableThicknesses[currentThicknessIndex] / 2,
+ 0, Math.PI * 2.0, true);
+ canvasDisplayCtx.fill();
+ }
+
+ }
+
+ function startControls() {
+ isActive = true;
+
+ labelContainer.removeChild(placeholder);
+ placeholder = undefined;
+
+ labelContainer.appendChild(
+ document.createTextNode("Number of Players: "));
+ labelContainer.appendChild(labelPlayerCount);
+
+
+ drawContainer.style.display = "block";
+ drawContainer.appendChild(canvasDisplay);
+
+ drawContainer.appendChild(optionContainer);
+
+ canvasMouseDownHandler = function(e) {
+ if (e.button == 0) {
+ currentMouseX = e.pageX - canvasDisplay.offsetLeft;
+ currentMouseY = e.pageY - canvasDisplay.offsetTop;
+
+ mouseDown = true;
+ canvasMouseMoveHandler(e);
+
+ } else if (mouseDown) {
+ // Cancel drawing.
+ mouseDown = false;
+ currentPreviewPath = null;
+
+ currentMouseX = e.pageX - canvasDisplay.offsetLeft;
+ currentMouseY = e.pageY - canvasDisplay.offsetTop;
+
+ refreshDisplayCanvas();
+ }
+ };
+ canvasDisplay.addEventListener("mousedown", canvasMouseDownHandler, false);
+
+ canvasMouseMoveHandler = function(e) {
+ var mouseX = e.pageX - canvasDisplay.offsetLeft;
+ var mouseY = e.pageY - canvasDisplay.offsetTop;
+
+ if (mouseDown) {
+ var drawType = availableDrawTypes[currentDrawTypeIndex];
+
+ if (drawType.continuous) {
+
+ var path = new Path(drawType.id,
+ availableColors[currentColorIndex],
+ availableThicknesses[currentThicknessIndex],
+ currentMouseX, currentMouseY, mouseX,
+ mouseY, false);
+ // Draw it on the background canvas.
+ path.draw(canvasBackgroundCtx);
+
+ // Send it to the sever.
+ pushPath(path);
+
+ // Refresh old coordinates
+ currentMouseX = mouseX;
+ currentMouseY = mouseY;
+
+ } else {
+ // Create a new preview path.
+ var color = availableColors[currentColorIndex].slice(0);
+ color[3] = previewTransparency;
+ currentPreviewPath = new Path(drawType.id,
+ color,
+ availableThicknesses[currentThicknessIndex],
+ currentMouseX, currentMouseY, mouseX,
+ mouseY, false);
+ }
+
+ refreshDisplayCanvas();
+ } else {
+ currentMouseX = mouseX;
+ currentMouseY = mouseY;
+
+ if (mouseInWindow) {
+ refreshDisplayCanvas();
+ }
+ }
+
+ };
+ document.addEventListener("mousemove", canvasMouseMoveHandler, false);
+
+ document.addEventListener("mouseup", function(e) {
+ if (e.button == 0) {
+ if (mouseDown) {
+ mouseDown = false;
+ currentPreviewPath = null;
+
+ var mouseX = e.pageX - canvasDisplay.offsetLeft;
+ var mouseY = e.pageY - canvasDisplay.offsetTop;
+ var drawType = availableDrawTypes[currentDrawTypeIndex];
+
+ var path = new Path(drawType.id, availableColors[currentColorIndex],
+ availableThicknesses[currentThicknessIndex],
+ currentMouseX, currentMouseY, mouseX,
+ mouseY, true);
+ // Draw it on the background canvas.
+ path.draw(canvasBackgroundCtx);
+
+ // Send it to the sever.
+ pushPath(path);
+
+ // Refresh old coordinates
+ currentMouseX = mouseX;
+ currentMouseY = mouseY;
+
+ refreshDisplayCanvas();
+ }
+ }
+ }, false);
+
+ canvasDisplay.addEventListener("mouseout", function(e) {
+ mouseInWindow = false;
+ refreshDisplayCanvas();
+ }, false);
+
+ canvasDisplay.addEventListener("mousemove", function(e) {
+ if (!mouseInWindow) {
+ mouseInWindow = true;
+ refreshDisplayCanvas();
+ }
+ }, false);
+
+
+ // Create color and thickness controls.
+ var colorContainersBox = document.createElement("div");
+ colorContainersBox.setAttribute("style",
+ "margin: 4px; border: 1px solid #bbb; border-radius: 3px;");
+ optionContainer.appendChild(colorContainersBox);
+
+ colorContainers = new Array(3 * 3 * 3);
+ for (var i = 0; i < colorContainers.length; i++) {
+ var colorContainer = colorContainers[i] =
+ document.createElement("div");
+ var color = availableColors[i] =
+ [
+ Math.floor((i % 3) * 255 / 2),
+ Math.floor((Math.floor(i / 3) % 3) * 255 / 2),
+ Math.floor((Math.floor(i / (3 * 3)) % 3) * 255 / 2),
+ 1.0
+ ];
+ colorContainer.setAttribute("style",
+ "margin: 3px; width: 18px; height: 18px; "
+ + "float: left; background-color: " + rgb(color));
+ colorContainer.style.border = '2px solid #000';
+ colorContainer.addEventListener("mousedown", (function(ix) {
+ return function() {
+ setColor(ix);
+ };
+ })(i), false);
+
+ colorContainersBox.appendChild(colorContainer);
+ }
+
+ var divClearLeft = document.createElement("div");
+ divClearLeft.setAttribute("style", "clear: left;");
+ colorContainersBox.appendChild(divClearLeft);
+
+
+ var drawTypeContainersBox = document.createElement("div");
+ drawTypeContainersBox.setAttribute("style",
+ "float: right; margin-right: 3px; margin-top: 1px;");
+ optionContainer.appendChild(drawTypeContainersBox);
+
+ drawTypeContainers = new Array(availableDrawTypes.length);
+ for (var i = 0; i < drawTypeContainers.length; i++) {
+ var drawTypeContainer = drawTypeContainers[i] =
+ document.createElement("div");
+ drawTypeContainer.setAttribute("style",
+ "text-align: center; margin: 3px; padding: 0 3px;"
+ + "height: 18px; float: left;");
+ drawTypeContainer.style.border = "2px solid #000";
+ drawTypeContainer.appendChild(document.createTextNode(
+ String(availableDrawTypes[i].name)));
+ drawTypeContainer.addEventListener("mousedown", (function(ix) {
+ return function() {
+ setDrawType(ix);
+ };
+ })(i), false);
+
+ drawTypeContainersBox.appendChild(drawTypeContainer);
+ }
+
+
+ var thicknessContainersBox = document.createElement("div");
+ thicknessContainersBox.setAttribute("style",
+ "margin: 3px; border: 1px solid #bbb; border-radius: 3px;");
+ optionContainer.appendChild(thicknessContainersBox);
+
+ thicknessContainers = new Array(availableThicknesses.length);
+ for (var i = 0; i < thicknessContainers.length; i++) {
+ var thicknessContainer = thicknessContainers[i] =
+ document.createElement("div");
+ thicknessContainer.setAttribute("style",
+ "text-align: center; margin: 3px; width: 18px; "
+ + "height: 18px; float: left;");
+ thicknessContainer.style.border = "2px solid #000";
+ thicknessContainer.appendChild(document.createTextNode(
+ String(availableThicknesses[i])));
+ thicknessContainer.addEventListener("mousedown", (function(ix) {
+ return function() {
+ setThickness(ix);
+ };
+ })(i), false);
+
+ thicknessContainersBox.appendChild(thicknessContainer);
+ }
+
+
+ divClearLeft = document.createElement("div");
+ divClearLeft.setAttribute("style", "clear: left;");
+ thicknessContainersBox.appendChild(divClearLeft);
+
+
+ setColor(0);
+ setThickness(0);
+ setDrawType(0);
+
+ }
+
+ function disableControls() {
+ document.removeEventListener("mousedown", canvasMouseDownHandler);
+ document.removeEventListener("mousemove", canvasMouseMoveHandler);
+ mouseInWindow = false;
+ refreshDisplayCanvas();
+
+ isActive = false;
+ }
+
+ function pushPath(path) {
+
+ // Push it into the pathsNotHandled array.
+ var container = new PathIdContainer(path, nextMsgId++);
+ pathsNotHandled.push(container);
+
+ // Send the path to the server.
+ var message = container.id + "|" + path.type + ","
+ + path.color[0] + "," + path.color[1] + ","
+ + path.color[2] + ","
+ + Math.round(path.color[3] * 255.0) + ","
+ + path.thickness + "," + path.x1 + ","
+ + path.y1 + "," + path.x2 + "," + path.y2 + ","
+ + (path.lastInChain ? "1" : "0");
+
+ socket.send("1" + message);
+ }
+
+ function setThickness(thicknessIndex) {
+ if (typeof currentThicknessIndex !== "undefined")
+ thicknessContainers[currentThicknessIndex]
+ .style.borderColor = "#000";
+ currentThicknessIndex = thicknessIndex;
+ thicknessContainers[currentThicknessIndex]
+ .style.borderColor = "#d08";
+ }
+
+ function setColor(colorIndex) {
+ if (typeof currentColorIndex !== "undefined")
+ colorContainers[currentColorIndex]
+ .style.borderColor = "#000";
+ currentColorIndex = colorIndex;
+ colorContainers[currentColorIndex]
+ .style.borderColor = "#d08";
+ }
+
+ function setDrawType(drawTypeIndex) {
+ if (typeof currentDrawTypeIndex !== "undefined")
+ drawTypeContainers[currentDrawTypeIndex]
+ .style.borderColor = "#000";
+ currentDrawTypeIndex = drawTypeIndex;
+ drawTypeContainers[currentDrawTypeIndex]
+ .style.borderColor = "#d08";
+ }
+
+
+ connect();
+
+ }
+
+
+ // Initialize the room
+ var room = new Room(document.getElementById("drawContainer"));
+
+
+ }, false);
+
+ })();
+ ]]></script>
+</head>
+<body>
+ <div class="noscript"><div style="color: #ff0000; font-size: 16pt;">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</div></div>
+ <div id="labelContainer"/>
+ <div id="drawContainer"/>
+ <div id="console-container"/>
+ <div style="clear: left;"/>
+
+ <h1 class="expand" data-content-id="expandContent" style="font-size: 1.3em;"
+ >About Drawboard WebSocket Example</h1>
+ <div id="expandContent">
+ <p>
+ This drawboard is a page where you can draw with your mouse or touch input
+ (using different colors) and everybody else which has the page open will
+ <em>immediately</em> see what you are drawing.<br/>
+ If someone opens the page later, they will get the current room image (so they
+ can see what was already drawn by other people).
+ </p>
+ <p>
+ It uses asynchronous sending of messages so that it doesn't need separate threads
+ for each client to send messages (this needs NIO or APR connector to be used).<br/>
+ Each "Room" (where the drawing happens) uses a ReentrantLock to synchronize access
+ (currently, only a single Room is implemented).
+ </p>
+ <p>
+ When you open the page, first you will receive a binary websocket message containing
+ the current room image as PNG image. After that, you will receive string messages
+ that contain the drawing actions (line from x1,y1 to x2,y2).<br/>
+ <small>Note that it currently only uses simple string messages instead of JSON because
+ I did not want to introduce a dependency on a JSON lib.</small>
+ </p>
+ <p>
+ It uses synchronization mechanisms to ensure that the final image will look the same
+ for every user, regardless of what their network latency/speed is – e.g. if two user
+ draw at the same time on the same place, the server will decide which line was the
+ first one, and that will be reflected on every client.
+ </p>
+ </div>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket/echo.xhtml b/tomcat-cas/webapps/examples/websocket/echo.xhtml
new file mode 100644
index 0000000..6153bff
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket/echo.xhtml
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Apache Tomcat WebSocket Examples: Echo</title>
+ <style type="text/css"><![CDATA[
+ #connect-container {
+ float: left;
+ width: 400px
+ }
+
+ #connect-container div {
+ padding: 5px;
+ }
+
+ #console-container {
+ float: left;
+ margin-left: 15px;
+ width: 400px;
+ }
+
+ #console {
+ border: 1px solid #CCCCCC;
+ border-right-color: #999999;
+ border-bottom-color: #999999;
+ height: 170px;
+ overflow-y: scroll;
+ padding: 5px;
+ width: 100%;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+ ]]></style>
+ <script type="application/javascript"><![CDATA[
+ var ws = null;
+
+ function setConnected(connected) {
+ document.getElementById('connect').disabled = connected;
+ document.getElementById('disconnect').disabled = !connected;
+ document.getElementById('echo').disabled = !connected;
+ }
+
+ function connect() {
+ var target = document.getElementById('target').value;
+ if (target == '') {
+ alert('Please select server side connection implementation.');
+ return;
+ }
+ if ('WebSocket' in window) {
+ ws = new WebSocket(target);
+ } else if ('MozWebSocket' in window) {
+ ws = new MozWebSocket(target);
+ } else {
+ alert('WebSocket is not supported by this browser.');
+ return;
+ }
+ ws.onopen = function () {
+ setConnected(true);
+ log('Info: WebSocket connection opened.');
+ };
+ ws.onmessage = function (event) {
+ log('Received: ' + event.data);
+ };
+ ws.onclose = function (event) {
+ setConnected(false);
+ log('Info: WebSocket connection closed, Code: ' + event.code + (event.reason == "" ? "" : ", Reason: " + event.reason));
+ };
+ }
+
+ function disconnect() {
+ if (ws != null) {
+ ws.close();
+ ws = null;
+ }
+ setConnected(false);
+ }
+
+ function echo() {
+ if (ws != null) {
+ var message = document.getElementById('message').value;
+ log('Sent: ' + message);
+ ws.send(message);
+ } else {
+ alert('WebSocket connection not established, please connect.');
+ }
+ }
+
+ function updateTarget(target) {
+ if (window.location.protocol == 'http:') {
+ document.getElementById('target').value = 'ws://' + window.location.host + target;
+ } else {
+ document.getElementById('target').value = 'wss://' + window.location.host + target;
+ }
+ }
+
+ function log(message) {
+ var console = document.getElementById('console');
+ var p = document.createElement('p');
+ p.style.wordWrap = 'break-word';
+ p.appendChild(document.createTextNode(message));
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ }
+
+
+ document.addEventListener("DOMContentLoaded", function() {
+ // Remove elements with "noscript" class - <noscript> is not allowed in XHTML
+ var noscripts = document.getElementsByClassName("noscript");
+ for (var i = 0; i < noscripts.length; i++) {
+ noscripts[i].parentNode.removeChild(noscripts[i]);
+ }
+ }, false);
+ ]]></script>
+</head>
+<body>
+<div class="noscript"><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</h2></div>
+<div>
+ <div id="connect-container">
+ <div>
+ <span>Connect to service implemented using:</span>
+ <!-- echo example using new programmatic API on the server side -->
+ <input id="radio1" type="radio" name="group1" value="/examples/websocket/echoProgrammatic"
+ onclick="updateTarget(this.value);"/> <label for="radio1">programmatic API</label>
+ <!-- echo example using new annotation API on the server side -->
+ <input id="radio2" type="radio" name="group1" value="/examples/websocket/echoAnnotation"
+ onclick="updateTarget(this.value);"/> <label for="radio2">annotation API</label>
+ </div>
+ <div>
+ <input id="target" type="text" size="40" style="width: 350px"/>
+ </div>
+ <div>
+ <button id="connect" onclick="connect();">Connect</button>
+ <button id="disconnect" disabled="disabled" onclick="disconnect();">Disconnect</button>
+ </div>
+ <div>
+ <textarea id="message" style="width: 350px">Here is a message!</textarea>
+ </div>
+ <div>
+ <button id="echo" onclick="echo();" disabled="disabled">Echo message</button>
+ </div>
+ </div>
+ <div id="console-container">
+ <div id="console"/>
+ </div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket/index.xhtml b/tomcat-cas/webapps/examples/websocket/index.xhtml
new file mode 100644
index 0000000..2b8d8cd
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket/index.xhtml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Apache Tomcat WebSocket Examples</title>
+</head>
+<body>
+<h1>Apache Tomcat WebSocket Examples</h1>
+<ul>
+ <li><a href="echo.xhtml">Echo example</a></li>
+ <li><a href="chat.xhtml">Chat example</a></li>
+ <li><a href="snake.xhtml">Multiplayer snake example</a></li>
+ <li><a href="drawboard.xhtml">Multiplayer drawboard example</a></li>
+
+</ul>
+</body>
+</html>
\ No newline at end of file
diff --git a/tomcat-cas/webapps/examples/websocket/snake.xhtml b/tomcat-cas/webapps/examples/websocket/snake.xhtml
new file mode 100644
index 0000000..86d1b3c
--- /dev/null
+++ b/tomcat-cas/webapps/examples/websocket/snake.xhtml
@@ -0,0 +1,266 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Apache Tomcat WebSocket Examples: Multiplayer Snake</title>
+ <style type="text/css"><![CDATA[
+ #playground {
+ width: 640px;
+ height: 480px;
+ background-color: #000;
+ }
+
+ #console-container {
+ float: left;
+ margin-left: 15px;
+ width: 300px;
+ }
+
+ #console {
+ border: 1px solid #CCCCCC;
+ border-right-color: #999999;
+ border-bottom-color: #999999;
+ height: 480px;
+ overflow-y: scroll;
+ padding-left: 5px;
+ padding-right: 5px;
+ width: 100%;
+ }
+
+ #console p {
+ padding: 0;
+ margin: 0;
+ }
+ ]]></style>
+</head>
+<body>
+ <div class="noscript"><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable
+ Javascript and reload this page!</h2></div>
+ <div style="float: left">
+ <canvas id="playground" width="640" height="480"/>
+ </div>
+ <div id="console-container">
+ <div id="console"/>
+ </div>
+ <script type="application/javascript"><![CDATA[
+
+ var Game = {};
+
+ Game.fps = 30;
+ Game.socket = null;
+ Game.nextFrame = null;
+ Game.interval = null;
+ Game.direction = 'none';
+ Game.gridSize = 10;
+
+ function Snake() {
+ this.snakeBody = [];
+ this.color = null;
+ }
+
+ Snake.prototype.draw = function(context) {
+ for (var id in this.snakeBody) {
+ context.fillStyle = this.color;
+ context.fillRect(this.snakeBody[id].x, this.snakeBody[id].y, Game.gridSize, Game.gridSize);
+ }
+ };
+
+ Game.initialize = function() {
+ this.entities = [];
+ canvas = document.getElementById('playground');
+ if (!canvas.getContext) {
+ Console.log('Error: 2d canvas not supported by this browser.');
+ return;
+ }
+ this.context = canvas.getContext('2d');
+ window.addEventListener('keydown', function (e) {
+ var code = e.keyCode;
+ if (code > 36 && code < 41) {
+ switch (code) {
+ case 37:
+ if (Game.direction != 'east') Game.setDirection('west');
+ break;
+ case 38:
+ if (Game.direction != 'south') Game.setDirection('north');
+ break;
+ case 39:
+ if (Game.direction != 'west') Game.setDirection('east');
+ break;
+ case 40:
+ if (Game.direction != 'north') Game.setDirection('south');
+ break;
+ }
+ }
+ }, false);
+ if (window.location.protocol == 'http:') {
+ Game.connect('ws://' + window.location.host + '/examples/websocket/snake');
+ } else {
+ Game.connect('wss://' + window.location.host + '/examples/websocket/snake');
+ }
+ };
+
+ Game.setDirection = function(direction) {
+ Game.direction = direction;
+ Game.socket.send(direction);
+ Console.log('Sent: Direction ' + direction);
+ };
+
+ Game.startGameLoop = function() {
+ if (window.webkitRequestAnimationFrame) {
+ Game.nextFrame = function () {
+ webkitRequestAnimationFrame(Game.run);
+ };
+ } else if (window.mozRequestAnimationFrame) {
+ Game.nextFrame = function () {
+ mozRequestAnimationFrame(Game.run);
+ };
+ } else {
+ Game.interval = setInterval(Game.run, 1000 / Game.fps);
+ }
+ if (Game.nextFrame != null) {
+ Game.nextFrame();
+ }
+ };
+
+ Game.stopGameLoop = function () {
+ Game.nextFrame = null;
+ if (Game.interval != null) {
+ clearInterval(Game.interval);
+ }
+ };
+
+ Game.draw = function() {
+ this.context.clearRect(0, 0, 640, 480);
+ for (var id in this.entities) {
+ this.entities[id].draw(this.context);
+ }
+ };
+
+ Game.addSnake = function(id, color) {
+ Game.entities[id] = new Snake();
+ Game.entities[id].color = color;
+ };
+
+ Game.updateSnake = function(id, snakeBody) {
+ if (typeof Game.entities[id] != "undefined") {
+ Game.entities[id].snakeBody = snakeBody;
+ }
+ };
+
+ Game.removeSnake = function(id) {
+ Game.entities[id] = null;
+ // Force GC.
+ delete Game.entities[id];
+ };
+
+ Game.run = (function() {
+ var skipTicks = 1000 / Game.fps, nextGameTick = (new Date).getTime();
+
+ return function() {
+ while ((new Date).getTime() > nextGameTick) {
+ nextGameTick += skipTicks;
+ }
+ Game.draw();
+ if (Game.nextFrame != null) {
+ Game.nextFrame();
+ }
+ };
+ })();
+
+ Game.connect = (function(host) {
+ if ('WebSocket' in window) {
+ Game.socket = new WebSocket(host);
+ } else if ('MozWebSocket' in window) {
+ Game.socket = new MozWebSocket(host);
+ } else {
+ Console.log('Error: WebSocket is not supported by this browser.');
+ return;
+ }
+
+ Game.socket.onopen = function () {
+ // Socket open.. start the game loop.
+ Console.log('Info: WebSocket connection opened.');
+ Console.log('Info: Press an arrow key to begin.');
+ Game.startGameLoop();
+ setInterval(function() {
+ // Prevent server read timeout.
+ Game.socket.send('ping');
+ }, 5000);
+ };
+
+ Game.socket.onclose = function () {
+ Console.log('Info: WebSocket closed.');
+ Game.stopGameLoop();
+ };
+
+ Game.socket.onmessage = function (message) {
+ // _Potential_ security hole, consider using json lib to parse data in production.
+ var packet = eval('(' + message.data + ')');
+ switch (packet.type) {
+ case 'update':
+ for (var i = 0; i < packet.data.length; i++) {
+ Game.updateSnake(packet.data[i].id, packet.data[i].body);
+ }
+ break;
+ case 'join':
+ for (var j = 0; j < packet.data.length; j++) {
+ Game.addSnake(packet.data[j].id, packet.data[j].color);
+ }
+ break;
+ case 'leave':
+ Game.removeSnake(packet.id);
+ break;
+ case 'dead':
+ Console.log('Info: Your snake is dead, bad luck!');
+ Game.direction = 'none';
+ break;
+ case 'kill':
+ Console.log('Info: Head shot!');
+ break;
+ }
+ };
+ });
+
+ var Console = {};
+
+ Console.log = (function(message) {
+ var console = document.getElementById('console');
+ var p = document.createElement('p');
+ p.style.wordWrap = 'break-word';
+ p.innerHTML = message;
+ console.appendChild(p);
+ while (console.childNodes.length > 25) {
+ console.removeChild(console.firstChild);
+ }
+ console.scrollTop = console.scrollHeight;
+ });
+
+ Game.initialize();
+
+
+ document.addEventListener("DOMContentLoaded", function() {
+ // Remove elements with "noscript" class - <noscript> is not allowed in XHTML
+ var noscripts = document.getElementsByClassName("noscript");
+ for (var i = 0; i < noscripts.length; i++) {
+ noscripts[i].parentNode.removeChild(noscripts[i]);
+ }
+ }, false);
+
+ ]]></script>
+</body>
+</html>
\ No newline at end of file