Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/WebTest.java b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/WebTest.java
new file mode 100644
index 0000000..5ff1f27
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/WebTest.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+import java.lang.*;
+import java.io.*;
+import java.net.*;
+
+import com.sun.ejte.ccl.reporter.*;
+
+public class WebTest
+{
+
+ private static int count = 0;
+ private static int EXPECTED_COUNT = 1;
+
+ static SimpleReporterAdapter stat=
+ new SimpleReporterAdapter("appserv-tests");
+
+ public static void main(String args[])
+ {
+
+ // The stat reporter writes out the test info and results
+ // into the top-level quicklook directory during a run.
+
+ stat.addDescription("Multi Servlet Requests");
+
+ String host = args[0];
+ String portS = args[1];
+ String contextRoot = args[2];
+
+ int port = new Integer(portS).intValue();
+ String name;
+
+ try {
+ goGet(host, port, "multiServletRequests", contextRoot + "/ServletTest" );
+ } catch (Throwable t) {
+ System.out.println(t.getMessage());
+ }
+
+ if (count != EXPECTED_COUNT){
+ stat.addStatus("web-multiServletRequests", stat.FAIL);
+ }
+ stat.printSummary("web/multiServletRequests---> expect " + EXPECTED_COUNT);
+ }
+
+ private static void goGet(String host, int port,
+ String result, String contextPath)
+ throws Exception
+ {
+ long time = System.currentTimeMillis();
+ Socket s = new Socket(host, port);
+ OutputStream os = s.getOutputStream();
+
+ contextPath += "?host=" + host + "&port=" + port + "&contextRoot=" + contextPath;
+ System.out.println(("GET " + contextPath + " HTTP/1.1\n"));
+ os.write(("GET " + contextPath + " HTTP/1.1\n").getBytes());
+ os.write(("Host: localhost\n").getBytes());
+ os.write("\n".getBytes());
+
+ InputStream is = s.getInputStream();
+ System.out.println("Time: " + (System.currentTimeMillis() - time));
+ BufferedReader bis = new BufferedReader(new InputStreamReader(is));
+ String line = null;
+
+ try{
+ int index;
+ int j=0;
+ while ((line = bis.readLine()) != null) {
+ index = line.indexOf(result);
+ System.out.println(j + ":" + line);
+ if (index != -1) {
+ index = line.indexOf("::");
+ String status = line.substring(index+2);
+
+ System.out.println("=== status: " + status);
+ if (status.equalsIgnoreCase("PASS")){
+ stat.addStatus("web-multiServletRequests: " + line.substring(0,index), stat.PASS);
+ } else {
+ stat.addStatus("web-multiServletRequests: " + line.substring(0,index), stat.FAIL);
+ }
+ count++;
+ }
+ j++;
+ }
+ } catch( Exception ex){
+ }
+ }
+
+}
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/build.properties b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/build.properties
new file mode 100644
index 0000000..cfa4ab2
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/build.properties
@@ -0,0 +1,28 @@
+<!--
+
+ Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+
+<property name="module" value="web"/>
+<property name="appname" value="${module}-multiServletRequests"/>
+<property name="assemble" value="${build.classes.dir}/archive"/>
+<property name="application.xml" value="descriptor/application.xml"/>
+<property name="sun-application.xml" value="descriptor/sun-application.xml"/>
+<property name="apptype" value="web"/>
+<property name="web.xml" value="descriptor/web.xml"/>
+<property name="sun-web.xml" value="descriptor/sun-web.xml"/>
+<property name="contextroot" value="/web-multiServletRequests"/>
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/build.xml b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/build.xml
new file mode 100644
index 0000000..deec8a9
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/build.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<!DOCTYPE project [
+<!ENTITY commonSetup SYSTEM "./../../../config/properties.xml">
+<!ENTITY commonBuild SYSTEM "./../../../config/common.xml">
+<!ENTITY testproperties SYSTEM "./build.properties">
+]>
+
+<project name="webcontainer_unittest" default="all" basedir=".">
+
+ &commonSetup;
+ &commonBuild;
+ &testproperties;
+
+ <target name="all" depends="build,deploy,run,undeploy"/>
+
+ <target name="clean" depends="init-common">
+ <antcall target="clean-common"/>
+ </target>
+
+ <target name="compile" depends="clean">
+ <antcall target="compile-common">
+ <param name="src" value="servlet"/>
+ </antcall>
+ </target>
+
+ <target name="build" depends="compile">
+ <property name="hasWebclient" value="yes"/>
+ <antcall target="webclient-war-common">
+ <param name="hasWebclient" value="yes"/>
+ <param name="webclient.war.classes" value="**/*.class"/>
+ </antcall>
+
+ </target>
+
+ <target name="build-publish-war" depends="build, publish-war-common" />
+
+ <target name="re-deploy" depends="init-common">
+ <antcall target="deploy-war-common"/>
+ </target>
+
+ <target name="deploy" depends="init-common">
+ <antcall target="deploy-war-common"/>
+ </target>
+
+ <target name="run" depends="init-common">
+ <javac
+ srcdir="."
+ classpath="${env.APS_HOME}/lib/reportbuilder.jar"
+ includes="WebTest.java"/>
+
+ <java classname="WebTest">
+ <arg value="${http.host}"/>
+ <arg value="${http.port}"/>
+ <arg value="${contextroot}"/>
+ <classpath>
+ <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/>
+ <pathelement location="."/>
+ </classpath>
+ </java>
+ </target>
+
+ <target name="undeploy" depends="init-common">
+ <antcall target="undeploy-war-common"/>
+ </target>
+
+ <target name="usage">
+ <antcall target="usage-common"/>
+ </target>
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/descriptor/web.xml b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/descriptor/web.xml
new file mode 100644
index 0000000..ac3278e
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/descriptor/web.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+
+ <servlet>
+ <display-name>ServletTest</display-name>
+ <servlet-name>ServletTest</servlet-name>
+ <servlet-class>test.ServletTest</servlet-class>
+ </servlet>
+ <servlet>
+ <display-name>ServletTest2</display-name>
+ <servlet-name>ServletTest2</servlet-name>
+ <servlet-class>test.ServletTest2</servlet-class>
+ </servlet>
+ <servlet>
+ <display-name>ServletTest3</display-name>
+ <servlet-name>ServletTest3</servlet-name>
+ <servlet-class>test.ServletTest3</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>ServletTest</servlet-name>
+ <url-pattern>/ServletTest</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ServletTest2</servlet-name>
+ <url-pattern>/ServletTest2</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ServletTest3</servlet-name>
+ <url-pattern>/ServletTest3</url-pattern>
+ </servlet-mapping>
+
+ <session-config>
+ <session-timeout>10</session-timeout>
+ </session-config>
+
+</web-app>
+
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest.java b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest.java
new file mode 100644
index 0000000..3b7c8c6
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package test;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class ServletTest extends HttpServlet {
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request, response);
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.setContentType("text/html");
+ PrintWriter out = response.getWriter();
+
+ String host = request.getParameter("host");
+ String port = request.getParameter("port");
+ String contextRoot = request.getParameter("contextRoot");
+
+ URL url = new URL("http://" + host + ":" + port + "/web-multiServletRequests/ServletTest2?host="+ host + "&port=" + port + "&contextRoot=" + contextRoot);
+ System.out.println("\n Servlet1 Invoking url: " + url.toString());
+ URLConnection conn = url.openConnection();
+ if (conn instanceof HttpURLConnection) {
+ HttpURLConnection urlConnection = (HttpURLConnection)conn;
+ urlConnection.setDoOutput(true);
+
+ DataOutputStream dout =
+ new DataOutputStream(urlConnection.getOutputStream());
+ dout.writeByte(1);
+
+ int responseCode= urlConnection.getResponseCode();
+ System.out.println("responseCode: " + responseCode);
+ if (responseCode == 200){
+ out.println("multiServletRequests::PASS");
+ } else {
+ out.println("multiServletRequests::FAIL");
+ }
+ }
+ }
+}
+
+
+
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest2.java b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest2.java
new file mode 100644
index 0000000..ddf9a78
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest2.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package test;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class ServletTest2 extends HttpServlet {
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request, response);
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ System.out.println("=========== In ServletTest2 ============");
+ response.setContentType("text/html");
+ PrintWriter out = response.getWriter();
+
+ String host = request.getParameter("host");
+ String port = request.getParameter("port");
+ String contextRoot = request.getParameter("contextRoot");
+
+ URL url = new URL("http://" + host + ":" + port + "/web-multiServletRequests/ServletTest3?host="+ host + "&port=" + port + "&contextRoot=" + contextRoot);
+ System.out.println("\n Servlet2 Invoking url: " + url.toString());
+ response.sendRedirect(url.toString());
+ System.out.println("=========== Servlet3 invoked =============");
+
+ }
+}
+
+
+
diff --git a/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest3.java b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest3.java
new file mode 100644
index 0000000..ec15a6f
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/multiServletRequests/servlet/ServletTest3.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package test;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class ServletTest3 extends HttpServlet {
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doPost(request, response);
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ System.out.println("================ In Servlet3 ===============");
+ response.setContentType("text/html");
+ PrintWriter out = response.getWriter();
+
+ String host = request.getParameter("host");
+ String port = request.getParameter("port");
+ String contextRoot = request.getParameter("contextRoot");
+
+ URL url = new URL("http://" + host + ":" + port + contextRoot + "/ServletTest2?host="+ host + "&port=" + port + "&contextRoot=" + contextRoot);
+ System.out.println("\n Servlet3 url: " + url.toString());
+ System.out.println("================ End Servlet3 ===============");
+ }
+}
+
+
+