Author: jfrederic.clere(a)jboss.com
Date: 2011-05-10 05:10:10 -0400 (Tue, 10 May 2011)
New Revision: 2782
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/ProcJBossWeb.java
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ServerThread.java
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StartJBossWeb.java
Log:
use jbossweb_trunk instead 2.1.x
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-10
08:15:49 UTC (rev 2781)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/JBossWeb.java 2011-05-10
09:10:10 UTC (rev 2782)
@@ -34,9 +34,6 @@
import java.io.FileOutputStream;
import org.apache.catalina.startup.Embedded;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Host;
-import org.apache.catalina.Context;
import org.apache.catalina.*;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.*;
@@ -58,51 +55,7 @@
fos.close();
}
- private static void copyFiles(File src, File dest) throws IOException {
- if (src.isDirectory()) {
- if (!dest.exists())
- dest.mkdirs();
-
- String list[] = src.list();
- for (int i = 0; i < list.length; i++) {
- File dest1 = new File(dest, list[i]);
- File src1 = new File(src, list[i]);
- copyFiles(src1 , dest1);
- }
- } else {
- //This was not a directory, so lets just copy the file
- FileInputStream fin = null;
- FileOutputStream fout = null;
- byte[] buffer = new byte[4096]; //Buffer 4K at a time (you can change this).
- int bytesRead;
- //open the files for input and output
- fin = new FileInputStream(src);
- fout = new FileOutputStream (dest);
- //while bytesRead indicates a successful read, lets write...
- while ((bytesRead = fin.read(buffer)) >= 0) {
- fout.write(buffer,0,bytesRead);
- }
- fout.close();
- fin.close();
- }
- }
- private void copyNativeDir(String route) throws IOException {
- File in = new File("bin/");
- if (!in.exists()) {
- return;
- }
- File ou = new File("node1/bin");
- if (!ou.exists()) {
- ou.mkdirs();
- }
- copyFiles(in, ou);
- }
-
public JBossWeb(String route, String host, boolean nat, String webapp, String[]
Aliases) throws IOException {
- // Copy native tree...
- if (nat) {
- copyNativeDir(route);
- }
setCatalinaBase(route);
setCatalinaHome(route);
@@ -128,12 +81,9 @@
//Create Host
Host baseHost = createHost( host, appBase);
- baseHost.setDeployOnStartup(true);
baseHost.setBackgroundProcessorDelay(1);
StandardHost stdhost = (StandardHost)baseHost;
- stdhost.setDeployXML(true);
stdhost.setConfigClass("org.apache.catalina.startup.ContextConfig");
- stdhost.setUnpackWARs(true);
if (Aliases != null && Aliases.length>0) {
for (int j = 0; j < Aliases.length; j++) {
stdhost.addAlias(Aliases[j]);
@@ -162,9 +112,15 @@
addEngine( baseEngine );
baseEngine.setService(this);
this.setName(host + "Engine" + route);
- setRedirectStreams(false);
}
- void AddContext(String path, String docBase, String servletname, boolean wait) {
+ private Context createContext(String string, String docBase) {
+ StandardContext context = new StandardContext();
+ context.setDocBase(docBase);
+ context.setPath(string);
+ return context;
+ }
+
+ void AddContext(String path, String docBase, String servletname, boolean wait) {
File fd = new File ( route + "/webapps/" + docBase);
fd.mkdirs();
docBase = fd.getAbsolutePath();
@@ -252,15 +208,4 @@
return connector;
}
- public void removeContext(String path) {
- Engine engine = (Engine) getContainer();
- Container[] containers = engine.findChildren();
- for (int j = 0; j < containers.length; j++) {
- if (containers[j] instanceof StandardHost) {
- StandardHost host = (StandardHost) containers[j];
- Context context = host.map(path);
- containers[j].removeChild(context);
- }
- }
- }
}
Modified:
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ProcJBossWeb.java
===================================================================
---
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ProcJBossWeb.java 2011-05-10
08:15:49 UTC (rev 2781)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ProcJBossWeb.java 2011-05-10
09:10:10 UTC (rev 2782)
@@ -64,7 +64,7 @@
}
public void start() {
- server = (StandardServer) ServerFactory.getServer();
+ StandardService service = new StandardService();
ServerThread wait = null;
try {
@@ -78,8 +78,6 @@
System.exit(0);
} else if (cmd[0].compareToIgnoreCase("new") == 0) {
service = new JBossWeb(cmd[1], cmd[2]);
- } else if (cmd[0].compareToIgnoreCase("addConnector") == 0) {
- service.addConnector(Integer.parseInt(cmd[1]));
} else if (cmd[0].compareToIgnoreCase("addService")== 0) {
server.addService(service);
} else if (cmd[0].compareToIgnoreCase("start") == 0) {
Modified:
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ServerThread.java
===================================================================
---
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ServerThread.java 2011-05-10
08:15:49 UTC (rev 2781)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/ServerThread.java 2011-05-10
09:10:10 UTC (rev 2782)
@@ -30,7 +30,6 @@
import java.io.IOException;
import org.apache.catalina.Engine;
-import org.apache.catalina.ServerFactory;
import org.apache.catalina.Service;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.LifecycleException;
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-10
08:15:49 UTC (rev 2781)
+++
trunk/build/unix/util/jbosswebtests/src/main/java/org/jboss/test/StartJBossWeb.java 2011-05-10
09:10:10 UTC (rev 2782)
@@ -32,11 +32,14 @@
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.security.AccessControlException;
+import java.util.Random;
import org.apache.catalina.startup.Embedded;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Host;
-import org.apache.catalina.Context;
import org.apache.catalina.*;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.*;
@@ -49,6 +52,9 @@
public class StartJBossWeb {
private static Logger log = Logger.getLogger(StartJBossWeb.class);
+ private static String address = "localhost";
+ private static String shutdown = "SHUTDOWN";
+ private static Random random = null;
/* Start a JBossWEB with domain */
public static void main(String[] args) {
@@ -69,14 +75,16 @@
log.info("Starting JBossWEB on " + port + " " + node + "
" + domain + " " + serverport);
try {
- server = (StandardServer) ServerFactory.getServer();
- server.setPort(serverport);
+ server = new StandardServer();
service = new JBossWeb(node, "localhost");
AprLifecycleListener apr = new AprLifecycleListener();
server.addLifecycleListener(apr);
- service.addConnector(port, "https", null);
+ final Connector connector = new Connector("HTTP/1.1");
+ connector.setScheme("https");
+ connector.setPort(port);
+ service.addConnector(connector);
server.addService(service);
// server.addLifecycleListener(apr);
@@ -93,7 +101,7 @@
}
// Wait until we are stopped...
- server.await();
+ await(serverport);
// Stop the server or services.
try {
@@ -105,4 +113,84 @@
}
}
+
+ /* Wait until we receive a stop command */
+ private static void await(int port) {
+ // Set up a server socket to wait on
+ ServerSocket serverSocket = null;
+ try {
+ serverSocket =
+ new ServerSocket(port, 1,
+ InetAddress.getByName(address));
+ } catch (IOException e) {
+ log.error("StandardServer.await: create[" + address
+ + ":" + port
+ + "]: ", e);
+ System.exit(1);
+ }
+
+ // Loop waiting for a connection and a valid command
+ while (true) {
+
+ // Wait for the next connection
+ Socket socket = null;
+ InputStream stream = null;
+ try {
+ socket = serverSocket.accept();
+ socket.setSoTimeout(10 * 1000); // Ten seconds
+ stream = socket.getInputStream();
+ } catch (AccessControlException ace) {
+ log.warn("StandardServer.accept security exception: "
+ + ace.getMessage(), ace);
+ continue;
+ } catch (IOException e) {
+ log.error("StandardServer.await: accept: ", e);
+ System.exit(1);
+ }
+
+ // Read a set of characters from the socket
+ StringBuffer command = new StringBuffer();
+ int expected = 1024; // Cut off to avoid DoS attack
+ while (expected < shutdown.length()) {
+ if (random == null)
+ random = new Random(System.currentTimeMillis());
+ expected += (random.nextInt() % 1024);
+ }
+ while (expected > 0) {
+ int ch = -1;
+ try {
+ ch = stream.read();
+ } catch (IOException e) {
+ log.warn("StandardServer.await: read: ", e);
+ ch = -1;
+ }
+ if (ch < 32) // Control character or EOF terminates loop
+ break;
+ command.append((char) ch);
+ expected--;
+ }
+
+ // Close the socket now that we are done with it
+ try {
+ socket.close();
+ } catch (IOException e) {
+ ;
+ }
+
+ // Match against our command string
+ boolean match = command.toString().equals(shutdown);
+ if (match) {
+ break;
+ } else
+ log.warn("StandardServer.await: Invalid command '" +
+ command.toString() + "' received");
+
+ }
+ // Close the server socket and return
+ try {
+ serverSocket.close();
+ } catch (IOException e) {
+ ;
+ }
+ }
}