Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/WebTest.java b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/WebTest.java
new file mode 100644
index 0000000..5ac1b6a
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/WebTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.io.*;
+import java.net.*;
+import com.sun.ejte.ccl.reporter.*;
+
+/**
+ * Unit test for:
+ *
+ * https://glassfish.dev.java.net/issues/show_bug.cgi?id=3398
+ * ("Access logging may not be turned on or off dynamically, requires
+ * server restart to take effect")
+ */
+public class WebTest {
+
+ private static SimpleReporterAdapter stat
+ = new SimpleReporterAdapter("appserv-tests");
+
+ private static final String TEST_NAME = "access-logging-dynamic-reconfig";
+
+ private static final String EXPECTED = "SUCCESS!";
+
+ private String host;
+ private String port;
+ private String contextRoot;
+ private String location;
+
+ public WebTest(String[] args) {
+ host = args[0];
+ port = args[1];
+ contextRoot = args[2];
+ location = args[3];
+ }
+
+ public static void main(String[] args) {
+ stat.addDescription("Unit test for GlassFish Issue 3398");
+ WebTest webTest = new WebTest(args);
+ webTest.doTest();
+ stat.printSummary(TEST_NAME);
+ }
+
+ public void doTest() {
+ try {
+ invoke();
+ stat.addStatus(TEST_NAME, stat.PASS);
+ } catch (Exception ex) {
+ stat.addStatus(TEST_NAME, stat.FAIL);
+ ex.printStackTrace();
+ }
+ }
+
+ private void invoke() throws Exception {
+
+ URL url = new URL("http://" + host + ":" + port + contextRoot
+ + "/CheckAccessLog?location="
+ + URLEncoder.encode(location));
+ System.out.println("Connecting to: " + url.toString());
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.connect();
+ int responseCode = conn.getResponseCode();
+ if (responseCode != 200) {
+ throw new Exception("Wrong response code. Expected: 200"
+ + ", received: " + responseCode);
+ } else {
+ BufferedReader bis = new BufferedReader(
+ new InputStreamReader(conn.getInputStream()));
+ String line = null;
+ while ((line = bis.readLine()) != null) {
+ if (EXPECTED.equals(line)) {
+ break;
+ }
+ }
+ if (line == null) {
+ throw new Exception("Wrong response body. Could not find "
+ + "expected string: " + EXPECTED);
+ }
+ }
+ }
+}
diff --git a/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/build.properties b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/build.properties
new file mode 100644
index 0000000..d2aa5e2
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/build.properties
@@ -0,0 +1,24 @@
+<!--
+
+ 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}-access-logging-dynamic-reconfig"/>
+<property name="assemble" value="${build.classes.dir}/archive"/>
+<property name="web.xml" value="descriptor/web.xml"/>
+<property name="contextroot" value="/${appname}"/>
diff --git a/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/build.xml b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/build.xml
new file mode 100644
index 0000000..42017c3
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/build.xml
@@ -0,0 +1,101 @@
+<?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 run SYSTEM "./../../../config/run.xml">
+<!ENTITY testproperties SYSTEM "./build.properties">
+]>
+
+<project name="webcontainer_unittest" default="all" basedir=".">
+
+ &commonSetup;
+ &commonBuild;
+ &testproperties;
+ &run;
+
+ <target name="all" depends="enable-access-logging,build,deploy,run,undeploy,disable-access-logging"/>
+
+ <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>
+
+ <javac srcdir="." classpath="${env.APS_HOME}/lib/reportbuilder.jar"
+ includes="WebTest.java"/>
+ </target>
+
+ <target name="enable-access-logging" depends="init-common">
+ <delete dir="${env.S1AS_HOME}/domains/domain1/logs/access"/>
+ <antcall target="asadmin-common-ignore-fail">
+ <param name="admin.command" value="set" />
+ <param name="operand.props"
+ value="${appserver.instance.name}.http-service.access-logging-enabled=true"/>
+ </antcall>
+ </target>
+
+ <target name="build-publish-war" depends="build, publish-war-common" />
+
+ <target name="deploy" depends="init-common">
+ <antcall target="deploy-war-common"/>
+ </target>
+
+ <target name="run" depends="init-common">
+ <java classname="WebTest">
+ <arg value="${http.host}"/>
+ <arg value="${http.port}"/>
+ <arg value="${contextroot}"/>
+ <arg value="${env.S1AS_HOME}"/>
+ <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="disable-access-logging" depends="init-common">
+ <antcall target="asadmin-common-ignore-fail">
+ <param name="admin.command" value="set" />
+ <param name="operand.props"
+ value="${appserver.instance.name}.http-service.access-logging-enabled=false"/>
+ </antcall>
+ <delete dir="${env.S1AS_HOME}/domains/domain1/logs/access"/>
+ </target>
+
+ <target name="usage">
+ <antcall target="usage-common"/>
+ </target>
+</project>
diff --git a/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/descriptor/web.xml b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/descriptor/web.xml
new file mode 100644
index 0000000..f50b79b
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/descriptor/web.xml
@@ -0,0 +1,34 @@
+<?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 version="2.5" 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">
+
+ <servlet>
+ <servlet-name>CheckAccessLog</servlet-name>
+ <servlet-class>CheckAccessLog</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>CheckAccessLog</servlet-name>
+ <url-pattern>/CheckAccessLog</url-pattern>
+ </servlet-mapping>
+
+</web-app>
+
+
diff --git a/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/servlet/CheckAccessLog.java b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/servlet/CheckAccessLog.java
new file mode 100644
index 0000000..10a79cf
--- /dev/null
+++ b/appserver/tests/appserv-tests/devtests/web/accessLoggingDynamicReconfig/servlet/CheckAccessLog.java
@@ -0,0 +1,32 @@
+/*
+ * 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.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+public class CheckAccessLog extends HttpServlet {
+
+ public void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException, ServletException {
+
+ String location = req.getParameter("location");
+ String[] files = new File(location + "/domains/domain1/logs/access").list();
+ if (files != null && files.length == 2) {
+ resp.getWriter().println("SUCCESS!");
+ }
+ }
+}