geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xiam...@apache.org
Subject svn commit: r1222581 - in /geronimo/samples/branches/2.1/samples: ./ all-samples/all-samples-tomcat/ chat/ chat/chat-tomcat/ chat/chat-tomcat/src/ chat/chat-tomcat/src/main/ chat/chat-tomcat/src/main/plan/ chat/chat-war/ chat/chat-war/src/ chat/chat-wa...
Date Fri, 23 Dec 2011 06:00:10 GMT
Author: xiaming
Date: Fri Dec 23 06:00:09 2011
New Revision: 1222581

URL: http://svn.apache.org/viewvc?rev=1222581&view=rev
Log:
GERONIMO-6242 Fork tomcat async servlet sample Chat

Added:
    geronimo/samples/branches/2.1/samples/chat/
    geronimo/samples/branches/2.1/samples/chat/chat-tomcat/
    geronimo/samples/branches/2.1/samples/chat/chat-tomcat/pom.xml
    geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/
    geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/
    geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/plan/
    geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/plan/plan.xml
    geronimo/samples/branches/2.1/samples/chat/chat-war/
    geronimo/samples/branches/2.1/samples/chat/chat-war/README.txt
    geronimo/samples/branches/2.1/samples/chat/chat-war/pom.xml
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/chat/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/chat/ChatServlet.java
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/geronimo-web.xml
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/web.xml
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/index.html
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/index.jsp
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/login.jsp
    geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/post.jsp
    geronimo/samples/branches/2.1/samples/chat/pom.xml
Modified:
    geronimo/samples/branches/2.1/samples/all-samples/all-samples-tomcat/pom.xml
    geronimo/samples/branches/2.1/samples/pom.xml

Modified: geronimo/samples/branches/2.1/samples/all-samples/all-samples-tomcat/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/all-samples/all-samples-tomcat/pom.xml?rev=1222581&r1=1222580&r2=1222581&view=diff
==============================================================================
--- geronimo/samples/branches/2.1/samples/all-samples/all-samples-tomcat/pom.xml (original)
+++ geronimo/samples/branches/2.1/samples/all-samples/all-samples-tomcat/pom.xml Fri Dec 23
06:00:09 2011
@@ -163,6 +163,13 @@
             <version>${version}</version>
             <type>car</type>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.samples</groupId>
+            <artifactId>chat-tomcat</artifactId>
+            <version>${version}</version>
+            <type>car</type>
+        </dependency>
     </dependencies>
 
     <build>

Added: geronimo/samples/branches/2.1/samples/chat/chat-tomcat/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-tomcat/pom.xml?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-tomcat/pom.xml (added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-tomcat/pom.xml Fri Dec 23 06:00:09 2011
@@ -0,0 +1,115 @@
+<?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.
+-->
+
+<!-- $Rev: 639460 $ $Date: 2008-03-20 17:12:27 -0400 (Thu, 20 Mar 2008) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.geronimo.samples</groupId>
+        <artifactId>chat</artifactId>
+        <version>2.1.8-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>chat-tomcat</artifactId>
+    <name>Geronimo Samples Plugin :: Asynchronous HTTP :: Chat</name>
+    <packaging>car</packaging>
+
+    <description>Geronimo Samples Chat Plugin for Tomcat</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.samples</groupId>
+            <artifactId>chat-war</artifactId>
+            <version>${version}</version>
+            <type>war</type>
+            <scope>provided</scope>
+        </dependency>        
+
+        <dependency>
+            <groupId>org.apache.geronimo.configs</groupId>
+            <artifactId>tomcat6-deployer</artifactId>
+            <version>${geronimoVersion}</version>
+            <type>car</type>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.configs</groupId>
+            <artifactId>jasper-deployer</artifactId>
+            <version>${geronimoVersion}</version>
+            <type>car</type>
+            <scope>provided</scope>
+        </dependency>        
+
+        <dependency>
+            <groupId>org.apache.geronimo.configs</groupId>
+            <artifactId>tomcat6</artifactId>
+            <version>${geronimoVersion}</version>
+            <type>car</type>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.configs</groupId>
+            <artifactId>jasper</artifactId>
+            <version>${geronimoVersion}</version>
+            <type>car</type>
+        </dependency>
+        
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>${pom.basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.geronimo.buildsupport</groupId>
+                <artifactId>car-maven-plugin</artifactId>
+                <configuration>
+                    <deploymentConfigs>
+                        <deploymentConfig>${gbeanDeployer}</deploymentConfig>
+                        <deploymentConfig>${j2eeDeployer}</deploymentConfig>
+                        <deploymentConfig>${tomcatDeployer}</deploymentConfig>
+                        <deploymentConfig>${jasperDeployer}</deploymentConfig>
                       
+                    </deploymentConfigs>
+                    <module>
+                        <groupId>org.apache.geronimo.samples</groupId>
+                        <artifactId>chat-war</artifactId>
+                        <version>${version}</version>
+                        <type>war</type>
+                    </module>
+                    <useMavenDependencies>
+                        <value>true</value>
+                        <includeVersion>true</includeVersion>
+                    </useMavenDependencies>
+                    <category>Sample</category>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+

Added: geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/plan/plan.xml?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/plan/plan.xml (added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-tomcat/src/main/plan/plan.xml Fri Dec
23 06:00:09 2011
@@ -0,0 +1,24 @@
+<?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.
+-->
+
+<!-- $Rev: 497879 $ $Date: 2007-01-19 12:11:01 -0500 (Fri, 19 Jan 2007) $ -->
+<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.2">
+    <context-root>/chat</context-root>    
+</web-app>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/README.txt
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/README.txt?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/README.txt (added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/README.txt Fri Dec 23 06:00:09 2011
@@ -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.
+
+-----------
+Description
+-----------
+This sample is forked from Tomcat example - Chat - to demonstrate Async Servlet use with
Tomcat Comet API
+
+-------
+Install
+-------
+1. Build this sample
+    mvn install
+2. Start geronimo server and define a NIO web connector at certain port, for example, 8090
+3. Deploy it
+    bin/deploy --user system --password manager <SAMPLES_HOME>/samples/javaee5/chat/target/chat-<version>.war
+
+---
+Run
+---
+ Open a browser to input URL: http://localhost:8090/chat
+
+

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/pom.xml?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/pom.xml (added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/pom.xml Fri Dec 23 06:00:09 2011
@@ -0,0 +1,97 @@
+<?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.
+-->
+<!-- $Rev: 805938 $ $Date: 2009-08-19 15:16:22 -0400 (Wed, 19 Aug 2009) $ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.geronimo.samples</groupId>
+        <artifactId>chat</artifactId>
+        <version>2.1.8-SNAPSHOT</version>
+    </parent>
+    <artifactId>chat-war</artifactId>
+    <name>Geronimo Samples :: Asynchronous HTTP :: Chat</name>
+    <packaging>war</packaging>
+
+    <description>
+        Geronimo chat sample forked from tomcat chat example
+    </description>
+
+    <dependencies>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.ext.tomcat</groupId>
+            <artifactId>catalina</artifactId>
+            <version>6.0.35.1</version>
+            <scope>provided</scope>
+        </dependency>
+        
+    </dependencies>
+
+    <build>
+        <plugins>            
+            <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-war-plugin</artifactId>
+                    <configuration>
+                        <archiveClasses>false</archiveClasses>
+                        <archive>
+                            <!-- Do not include META-INF/maven to avoid long file problems
on windows -->
+                            <addMavenDescriptor>false</addMavenDescriptor>
+                        </archive>
+                        
+                        <webResources>                        
+                        <!--To filter config files in war project. For some reason, maven-war-plugin
cannot handle common resources as above-->  
+                            <resource>
+                                <directory>${pom.basedir}/src/main/webapp</directory>
+                                <filtering>true</filtering>
+                                <includes>
+                                    <include>*/*.xml</include>
+                                </includes>              
+                            </resource>   
+                            <resource>
+                                <directory>${project.build.outputDirectory}</directory>
+                                <includes>
+                                    <include>META-INF/LICENSE*</include>
+                                    <include>META-INF/NOTICE*</include>
+                                    <include>META-INF/DISCLAIMER*</include>
+                                </includes>
+                            </resource>                                      
+                        </webResources>                        
+                    </configuration>
+                </plugin>
+            
+            <!--<plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+                <version>2.1.2</version>
+                <executions>
+                    <execution>
+                        <id>attach-sources</id>
+                        <phase>verify</phase>
+                        <goals>
+                          <goal>jar-no-fork</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>-->
+
+        </plugins>
+    </build>
+</project>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/chat/ChatServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/chat/ChatServlet.java?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/chat/ChatServlet.java
(added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/java/chat/ChatServlet.java
Fri Dec 23 06:00:09 2011
@@ -0,0 +1,293 @@
+/*
+ * 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 chat;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+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;
+
+
+/**
+ * Helper class to implement Comet functionality.
+ */
+public class ChatServlet
+    extends HttpServlet implements CometProcessor {
+
+    private static final String CHARSET = "UTF-8";
+
+    protected ArrayList<HttpServletResponse> connections = 
+        new ArrayList<HttpServletResponse>();
+    protected MessageSender messageSender = null;
+    
+    public void init() throws ServletException {
+        messageSender = new MessageSender();
+        Thread messageSenderThread = 
+            new Thread(messageSender, "MessageSender[" + getServletContext().getContextPath()
+ "]");
+        messageSenderThread.setDaemon(true);
+        messageSenderThread.start();
+    }
+
+    public void destroy() {
+        connections.clear();
+        messageSender.stop();
+        messageSender = null;
+    }
+
+    /**
+     * Process the given Comet event.
+     * 
+     * @param event The Comet event that will be processed
+     * @throws IOException
+     * @throws ServletException
+     */
+    public void event(CometEvent event)
+        throws IOException, ServletException {
+
+        // Note: There should really be two servlets in this example, to avoid
+        // 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) {
+                if ("login".equals(action)) {
+                    String nickname = request.getParameter("nickname");
+                    request.getSession(true).setAttribute("nickname", nickname);
+                    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;
+                }
+            }
+            begin(event, request, response);
+        } else if (event.getEventType() == CometEvent.EventType.ERROR) {
+            error(event, request, response);
+        } else if (event.getEventType() == CometEvent.EventType.END) {
+            end(event, request, response);
+        } else if (event.getEventType() == CometEvent.EventType.READ) {
+            read(event, request, response);
+        }
+    }
+
+    protected void begin(CometEvent event, HttpServletRequest request, HttpServletResponse
response)
+        throws IOException, ServletException {
+        log("Begin for session: " + request.getSession(true).getId());
+
+        response.setContentType("text/html; charset=" + CHARSET);
+
+        PrintWriter writer = response.getWriter();
+        writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">");
+        writer.println("<html><head><title>JSP Chat</title></head><body
bgcolor=\"#FFFFFF\">");
+        writer.println("<div>Welcome to the chat. <a href='chat'>Click here to
reload this window</a></div>");
+        writer.flush();
+
+        synchronized(connections) {
+            connections.add(response);
+        }
+
+        messageSender.send("Tomcat", request.getSession(true).getAttribute("nickname") +
" joined the chat.");
+    }
+    
+    protected void end(CometEvent event, HttpServletRequest request, HttpServletResponse
response)
+        throws IOException, ServletException {
+        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 {
+        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 {
+        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) 
+                        + " for session: " + request.getSession(true).getId());
+            } else if (n < 0) {
+                log("End of file: " + n);
+                end(event, request, response);
+                return;
+            }
+        }
+    }
+
+    protected void service(HttpServletRequest request, HttpServletResponse response)
+        throws IOException, ServletException {
+        // Compatibility method: equivalent method using the regular connection model
+        response.setContentType("text/html; charset=" + CHARSET);
+        PrintWriter writer = response.getWriter();
+        writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">");
+        writer.println("<html><head><title>JSP Chat</title></head><body
bgcolor=\"#FFFFFF\">");
+        writer.println("Chat example only supports Comet processing. ");
+        writer.println("Configure a connector that supports Comet and try again.");
+        writer.println("</body></html>");
+    }
+    
+
+    /**
+     * Poller class.
+     */
+    public class MessageSender implements Runnable {
+
+        protected boolean running = true;
+        protected ArrayList<String> messages = new ArrayList<String>();
+        
+        public MessageSender() {
+        }
+        
+        public void stop() {
+            running = false;
+            synchronized (messages) {
+                messages.notify();
+            }
+        }
+
+        /**
+         * 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);
+                messages.notify();
+            }
+        }
+
+        /**
+         * The background thread that listens for incoming TCP/IP connections and
+         * hands them off to an appropriate processor.
+         */
+        public void run() {
+
+            // Loop until we receive a shutdown command
+            while (running) {
+                String[] pendingMessages;
+                synchronized (messages) {
+                    try {
+                        if (messages.size() == 0) {
+                            messages.wait();
+                        }
+                    } catch (InterruptedException e) {
+                        // Ignore
+                    }
+                    pendingMessages = messages.toArray(new String[0]);
+                    messages.clear();
+                }
+
+                synchronized (connections) {
+                    for (int i = 0; i < connections.size(); i++) {
+                        try {
+                            PrintWriter writer = connections.get(i).getWriter();
+                            for (int j = 0; j < pendingMessages.length; j++) {
+                                writer.println("<div>"+filter(pendingMessages[j]) +
"</div>");
+                            }
+                            writer.flush();
+                        } catch (IOException e) {
+                            log("IOException sending message", e);
+                        }
+                    }
+                }
+
+            }
+
+        }
+
+    }
+
+    /**
+     * Filter the specified message string for characters that are sensitive
+     * in HTML.
+     *
+     * @param message The message string to be filtered
+     * @author Copied from org.apache.catalina.util.RequestUtil#filter(String) 
+     */
+    protected static String filter(String message) {
+        if (message == null)
+            return (null);
+
+        char content[] = new char[message.length()];
+        message.getChars(0, message.length(), content, 0);
+        StringBuilder result = new StringBuilder(content.length + 50);
+        for (int i = 0; i < content.length; i++) {
+            switch (content[i]) {
+            case '<':
+                result.append("&lt;");
+                break;
+            case '>':
+                result.append("&gt;");
+                break;
+            case '&':
+                result.append("&amp;");
+                break;
+            case '"':
+                result.append("&quot;");
+                break;
+            default:
+                result.append(content[i]);
+            }
+        }
+        return (result.toString());
+    }
+}

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/geronimo-web.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/geronimo-web.xml?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/geronimo-web.xml
(added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/geronimo-web.xml
Fri Dec 23 06:00:09 2011
@@ -0,0 +1,43 @@
+<!--
+    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.
+-->
+<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" 
+         xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" 
+         xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" 
+         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
+
+  <sys:environment>
+    <sys:moduleId>
+      <sys:groupId>${project.groupId}</sys:groupId>
+      <sys:artifactId>${project.artifactId}</sys:artifactId>
+      <sys:version>${project.version}</sys:version>
+      <sys:type>car</sys:type>
+    </sys:moduleId>
+    <sys:dependencies>
+        <sys:dependency>
+            <sys:groupId>org.apache.geronimo.ext.tomcat</sys:groupId>
+            <sys:artifactId>catalina</sys:artifactId>
+        </sys:dependency>    
+    </sys:dependencies>
+    <sys:hidden-classes/>
+    <sys:non-overridable-classes/>
+  </sys:environment>
+
+  <context-root>/chat</context-root>
+
+</web-app>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/web.xml?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/web.xml (added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/WEB-INF/web.xml Fri
Dec 23 06:00:09 2011
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+
+<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"> 
+
+    <description>
+      Async Servlet Examples - Chat
+    </description>
+    <display-name>Async Servlet Examples - Chat</display-name>
+
+
+    
+    <servlet>
+        <servlet-name>ChatServlet</servlet-name>
+        <servlet-class>chat.ChatServlet</servlet-class>
+    </servlet>
+    
+
+    <servlet-mapping>
+        <servlet-name>ChatServlet</servlet-name>
+        <url-pattern>/jsp/chat/chat</url-pattern>
+    </servlet-mapping>    
+
+</web-app>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/index.html?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/index.html (added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/index.html Fri Dec
23 06:00:09 2011
@@ -0,0 +1,28 @@
+<!--
+  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><TITLE>Apache Tomcat Examples</TITLE>
+<META http-equiv=Content-Type content="text/html">
+</HEAD>
+<BODY>
+<P>
+<H3>Apache Tomcat Examples - Chat</H3>
+<P></P>
+<ul>
+<li><a href="jsp/chat/index.jsp">Go Chat!</a></li>
+</ul>
+</BODY></HTML>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/index.jsp
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/index.jsp?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/index.jsp
(added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/index.jsp
Fri Dec 23 06:00:09 2011
@@ -0,0 +1,32 @@
+<%@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.
+  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>JSP Chat</title>
+</head>
+<frameset rows="1*,4*">
+  <frame name="post" src="post.jsp" scrolling="no" title="Post message">
+  <frame name="chat" src="chat" scrolling="yes" title="Chat">
+</frameset>
+</html>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/login.jsp
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/login.jsp?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/login.jsp
(added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/login.jsp
Fri Dec 23 06:00:09 2011
@@ -0,0 +1,33 @@
+<!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.
+  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>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>

Added: geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/post.jsp
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/post.jsp?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/post.jsp
(added)
+++ geronimo/samples/branches/2.1/samples/chat/chat-war/src/main/webapp/jsp/chat/post.jsp
Fri Dec 23 06:00:09 2011
@@ -0,0 +1,55 @@
+<!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.
+  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>JSP Chat</title>
+</head>
+
+<body bgcolor="#FFFFFF">
+
+<form method="POST" action='chat' name="postForm">
+<input type="hidden" name="action" value="post">
+Message: <input type="text" name="message">
+<input type="submit">
+</form>
+
+<br>
+<%
+  String serverName = request.getServerName();
+  if ("localhost".equals(serverName)) {
+      serverName = "127.0.0.1";
+  } else if ("127.0.0.1".equals(serverName)) {
+      serverName = "localhost";
+  }
+
+  String chatUrl = request.getScheme() + "://" + serverName + ":"
+    + request.getServerPort() + request.getContextPath()
+    + request.getServletPath();
+
+  // strip "post.jsp" from the address
+  chatUrl = chatUrl.substring(0, chatUrl.lastIndexOf("/") + 1);
+%>
+<a target="_blank" href="<%=chatUrl %>">Click to open a new chat window</a>
+<em>Note</em>: To avoid hitting the limit on the count of simultaneous
+connections to the same host, imposed by the
+<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4">HTTP specification</a>,
+the second chat window should be opened using a different URL, e.g. with
+an IP address instead of the host name.
+</body>
+</html>

Added: geronimo/samples/branches/2.1/samples/chat/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/chat/pom.xml?rev=1222581&view=auto
==============================================================================
--- geronimo/samples/branches/2.1/samples/chat/pom.xml (added)
+++ geronimo/samples/branches/2.1/samples/chat/pom.xml Fri Dec 23 06:00:09 2011
@@ -0,0 +1,46 @@
+<?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.
+-->
+
+<!-- $Rev: 1038972 $ $Date: 2010-11-25 04:47:09 -0500 (Thu, 25 Nov 2010) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.geronimo.samples</groupId>
+        <artifactId>samples</artifactId>
+        <version>2.1.8-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>chat</artifactId>
+    <name>Geronimo Samples :: Chat</name>
+    <packaging>pom</packaging>
+
+    <description>
+        Geronimo chat sample forked from tomcat chat example
+    </description>
+
+    <modules>
+        <module>chat-war</module>
+        <module>chat-tomcat</module>        
+    </modules>
+
+</project>

Modified: geronimo/samples/branches/2.1/samples/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/2.1/samples/pom.xml?rev=1222581&r1=1222580&r2=1222581&view=diff
==============================================================================
--- geronimo/samples/branches/2.1/samples/pom.xml (original)
+++ geronimo/samples/branches/2.1/samples/pom.xml Fri Dec 23 06:00:09 2011
@@ -69,6 +69,7 @@
         <module>servlet-examples</module>
         <module>app-per-port</module>
         <module>generic-auth</module>
+        <module>chat</module>
         <module>all-samples</module>
     </modules>
 



Mime
View raw message