geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xiam...@apache.org
Subject svn commit: r1354077 - /geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
Date Tue, 26 Jun 2012 16:01:26 GMT
Author: xiaming
Date: Tue Jun 26 16:01:25 2012
New Revision: 1354077

URL: http://svn.apache.org/viewvc?rev=1354077&view=rev
Log:
Add missing servlet class for test-web-forward case

Added:
    geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
  (with props)

Added: geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java?rev=1354077&view=auto
==============================================================================
--- geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
(added)
+++ geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
Tue Jun 26 16:01:25 2012
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.test;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+public class TestServlet2 extends HttpServlet {
+        
+    private static Integer expectedValue = new Integer(20);
+
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
+        String mode = request.getParameter("mode");
+
+        if ("forward".equals(mode)) {
+            getServletConfig().getServletContext().getContext("/dispatch1").getRequestDispatcher("/TestServlet").forward(request,
response);
+        } else {
+            PrintWriter out = response.getWriter();
+            Integer value = lookup("java:comp/env/value", request);
+        
+            out.println("TestServlet2: " + value);
+
+            // create new session for testing
+            HttpSession session = request.getSession(true);
+            session.setAttribute("sessAttr1", "value21");
+        }
+    }
+    
+    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
+    }         
+
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        testLookup("servletInit");
+    }
+
+    public void destroy() {
+        testLookup("servletDestroy");
+    }
+
+    private Integer lookup(String name, HttpServletRequest request) {
+        try {
+            Context ctx = new InitialContext();
+            Integer value = (Integer)ctx.lookup(name);
+            return value;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static void testLookup(String name) {
+        System.out.println(name);
+
+        Integer value;
+        try {
+            Context ctx = new InitialContext();
+            value = (Integer)ctx.lookup("java:comp/env/value");
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException(name, e);
+        }
+        
+        if (!expectedValue.equals(value)) {
+            throw new RuntimeException("Values do not match: " + expectedValue + " " + value);
+        }
+    }
+    
+}

Propchange: geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/3.0/testsuite/web-testsuite/test-web-forward/web-forward-war-2/src/main/java/org/apache/geronimo/test/TestServlet2.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message