Author: jfrederic.clere(a)jboss.com
Date: 2011-05-27 10:33:14 -0400 (Fri, 27 May 2011)
New Revision: 2786
Added:
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StopJBossWeb.java
Modified:
trunk/build/unix/util/jbosswebtests/pom.xml
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/JBossWeb.java
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StartJBossWeb.java
Log:
Arrange the logic to get the test working.
Modified: trunk/build/unix/util/jbosswebtests/pom.xml
===================================================================
--- trunk/build/unix/util/jbosswebtests/pom.xml 2011-05-27 12:01:18 UTC (rev 2785)
+++ trunk/build/unix/util/jbosswebtests/pom.xml 2011-05-27 14:33:14 UTC (rev 2786)
@@ -76,14 +76,15 @@
<unjar src="${org.jboss.as:jbossweb-native:jar}"
dest="node1" />
<!-- Start jbossweb (embedded) -->
- <java dir="node1"
classname="org.jboss.test.StartJBossWeb"
+ <java classname="org.jboss.test.StartJBossWeb"
spawn="true" fork="yes">
- <arg line="${line}"/>
<jvmarg
line="-Djava.util.logging.config.file=node1/conf/logging.properties" />
<jvmarg
line="-Djava.util.logging.manager=org.jboss.test.ClassLoaderLogManager"/>
<classpath refid="maven.test.classpath"/>
</java>
+ <sleep seconds="10"/>
+
<!-- Test it -->
<delete file="index.html"/>
<exec executable="wget">
@@ -93,6 +94,11 @@
<available file="index.html"
property="exist"/>
<fail unless="exist" message="Can't get test
file"/>
+ <java classname="org.jboss.test.StopJBossWeb"
+ spawn="true" fork="yes">
+ <classpath refid="maven.test.classpath"/>
+ </java>
+
</tasks>
</configuration>
<goals>
Modified: trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/JBossWeb.java
===================================================================
---
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/JBossWeb.java 2011-05-27
12:01:18 UTC (rev 2785)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/JBossWeb.java 2011-05-27
14:33:14 UTC (rev 2786)
@@ -32,14 +32,20 @@
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.lang.reflect.InvocationTargetException;
+import javax.naming.NamingException;
+
+import org.apache.catalina.startup.ContextConfig;
import org.apache.catalina.startup.Embedded;
import org.apache.catalina.*;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.*;
import org.apache.catalina.startup.HostConfig;
+import org.apache.tomcat.InstanceManager;
+import org.apache.tomcat.util.IntrospectionUtils;
-public class JBossWeb extends Embedded {
+public class JBossWeb extends StandardService {
private String route = null;
@@ -57,12 +63,12 @@
public JBossWeb(String route, String host, boolean nat, String webapp, String[]
Aliases) throws IOException {
- setCatalinaBase(route);
- setCatalinaHome(route);
+ System.setProperty( "catalina.base", route);
+ System.setProperty( "catalina.home", route);
this.route = route;
//Create an Engine
- StandardEngine baseEngine = (StandardEngine) createEngine();
+ StandardEngine baseEngine = new StandardEngine();
baseEngine.setName(host + "Engine" + route);
baseEngine.setDefaultHost(host);
@@ -72,7 +78,8 @@
// Create node1/webapps/ROOT and index.html
File fd = new File ( route + "/webapps/" + webapp);
- fd.mkdirs();
+ if (!fd.exists())
+ fd.mkdirs();
String docBase = fd.getAbsolutePath();
String appBase = fd.getParent();
fd = new File (route + "/webapps/" + webapp, "index.html");
@@ -81,7 +88,9 @@
out.close();
//Create Host
- Host baseHost = createHost( host, appBase);
+ StandardHost baseHost = new StandardHost();
+ baseHost.setAppBase(appBase);
+ baseHost.setName(host);
baseHost.setBackgroundProcessorDelay(1);
StandardHost stdhost = (StandardHost)baseHost;
stdhost.setConfigClass("org.apache.catalina.startup.ContextConfig");
@@ -95,30 +104,37 @@
baseEngine.addChild( baseHost );
//Create default context
- Context rootContext;
+ StandardContext rootContext;
if (webapp.equals("ROOT"))
- rootContext = createContext("/",docBase );
+ rootContext = createContext("",docBase );
else
rootContext = createContext("/" + webapp, docBase );
rootContext.setIgnoreAnnotations(true);
rootContext.setPrivileged(true);
+ rootContext.setInstanceManager(new LocalInstanceManager());
+ rootContext.setReplaceWelcomeFiles(true);
+ rootContext.addWelcomeFile("index.html");
+ rootContext.addMimeMapping("html", "text/html");
Wrapper wrapper = rootContext.createWrapper();
wrapper.setName("default");
wrapper.setServletClass("org.apache.catalina.servlets.DefaultServlet");
+ wrapper.setLoadOnStartup(0);
rootContext.addChild(wrapper);
rootContext.addServletMapping("/", "default");
+ ContextConfig config = new ContextConfig();
+ rootContext.addLifecycleListener(config);
baseHost.addChild( rootContext );
- addEngine( baseEngine );
+ setContainer( baseEngine );
baseEngine.setService(this);
this.setName(host + "Engine" + route);
}
- private Context createContext(String string, String docBase) {
+ private StandardContext createContext(String path, String docBase) {
StandardContext context = new StandardContext();
context.setDocBase(docBase);
- context.setPath(string);
- return context;
+ context.setPath(path);
+ return context;
}
void AddContext(String path, String docBase, String servletname, boolean wait) {
@@ -183,30 +199,45 @@
copyFile(fdin, fd);
}
- public Connector addConnector(int port) throws IOException {
- return addConnector(port, "https");
- }
-
- public Connector addConnector(int port, String scheme) throws IOException {
- return addConnector(port, scheme, null);
- }
-
- public Connector addConnector(int port, String scheme, String address) throws
IOException {
+ public void addConnector(int port, String scheme) throws Exception {
- Connector connector = createConnector( address,
- port, scheme);
+ Connector connector = new Connector("http");
+ connector.setPort(port);
/* Set the SSL properties */
connector.setProperty("SSLCertificateFile", "newcert.pem");
connector.setProperty("SSLCertificateKeyFile",
"newkey.pem");
connector.setProperty("SSLPassword", "changeit");
- connector.setProperty("SLEnabled", "true");
+ connector.setProperty("SSLEnabled", "true");
connector.setSecure(true);
connector.setScheme(scheme);
// Look in StandardService to see why it works ;-)
addConnector( connector );
+ }
+ private static class LocalInstanceManager implements InstanceManager {
+ @Override
+ public Object newInstance(String className) throws IllegalAccessException,
InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException
{
+ return Class.forName(className).newInstance();
+ }
- return connector;
+ @Override
+ public Object newInstance(String fqcn, ClassLoader classLoader) throws
IllegalAccessException, InvocationTargetException, NamingException,
InstantiationException, ClassNotFoundException {
+ return Class.forName(fqcn, false, classLoader).newInstance();
+ }
+
+ @Override
+ public Object newInstance(Class<?> c) throws IllegalAccessException,
InvocationTargetException, NamingException, InstantiationException {
+ return c.newInstance();
+ }
+
+ @Override
+ public void newInstance(Object o) throws IllegalAccessException,
InvocationTargetException, NamingException {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public void destroyInstance(Object o) throws IllegalAccessException,
InvocationTargetException {
+ }
}
}
Modified:
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StartJBossWeb.java
===================================================================
---
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StartJBossWeb.java 2011-05-27
12:01:18 UTC (rev 2785)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StartJBossWeb.java 2011-05-27
14:33:14 UTC (rev 2786)
@@ -51,6 +51,10 @@
public class StartJBossWeb {
+ static {
+ System.setProperty( "catalina.base", "node1"); // Log :D
+ }
+
private static Logger log = Logger.getLogger(StartJBossWeb.class);
private static String address = "localhost";
private static String shutdown = "SHUTDOWN";
Added: trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StopJBossWeb.java
===================================================================
--- trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StopJBossWeb.java
(rev 0)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StopJBossWeb.java 2011-05-27
14:33:14 UTC (rev 2786)
@@ -0,0 +1,47 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2011 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+package org.jboss.test;
+
+import java.io.PrintWriter;
+import java.net.Socket;
+
+public class StopJBossWeb {
+ public static void main(String[] args) {
+ // Stop JBossWeb.
+ try {
+ Socket clientSocket = new Socket ("localhost", 8005);
+ PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
+ out.println("SHUTDOWN");
+ out.close();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}