001: package org.objectweb.celtix.axisinterop;
002:
003: import java.io.File;
004: import java.io.InputStream;
005: import java.net.ServerSocket;
006: import java.util.logging.Logger;
007:
008: import org.apache.axis.client.AdminClient;
009: import org.apache.axis.transport.http.SimpleAxisServer;
010: import org.apache.axis.utils.Options;
011: import org.objectweb.celtix.testutil.common.AbstractTestServerBase;
012:
013: public class AxisServer extends AbstractTestServerBase {
014:
015: private static final int AXIS_PORT = 9360;
016: private SimpleAxisServer axisServer;
017: private boolean configExists;
018:
019: protected void run() {
020: axisServer = new SimpleAxisServer();
021: ServerSocket socket = null;
022: final int retries = 5;
023: for (int i = 0; i < retries; i++) {
024: try {
025: socket = new ServerSocket(AXIS_PORT);
026: break;
027: } catch (java.net.BindException be) {
028: // Retry at 3 second intervals.
029: if (i < (retries - 1)) {
030: try {
031: Thread.sleep(3000);
032: } catch (InterruptedException ex) {
033: // ignore
034: }
035: } else {
036: System.err
037: .println("Failed to start axisServer on port : "
038: + Integer.toString(AXIS_PORT));
039: startFailed();
040: }
041: } catch (java.io.IOException ie) {
042: System.err.println("Failed to start axisServer.");
043: startFailed();
044: }
045: }
046: axisServer.setServerSocket(socket);
047: try {
048: axisServer.start(true);
049: AdminClient admin = new AdminClient();
050: Options opts = new Options(new String[] { "-p",
051: Integer.toString(AXIS_PORT) });
052: InputStream is = getClass().getResourceAsStream(
053: "resources/echoDeploy.wsdd");
054: String result = admin.process(opts, is);
055: if (null == result || result.contains("AxisFault")) {
056: throw new Exception("Failed to start axis server");
057: }
058: } catch (Exception ex) {
059: System.err.println("Failed to deploy echo axis server.");
060: axisServer.stop();
061: axisServer = null;
062: startFailed();
063: }
064: }
065:
066: public void start() {
067: try {
068: System.out.println("running server");
069: run();
070: System.out.println("signal ready");
071: ready();
072:
073: // wait for a key press then shut
074: // down the server
075: //
076: System.in.read();
077: System.out.println("stopping bus");
078:
079: } catch (Throwable ex) {
080: ex.printStackTrace();
081: startFailed();
082: } finally {
083: if (verify(getLog())) {
084: System.out.println("server passed");
085: }
086: System.out.println("server stopped");
087: }
088: }
089:
090: public void setUp() throws Exception {
091: configExists = new File("server-config.wsdd").exists();
092: if (configExists) {
093: System.out
094: .println("Warning: Found an axis server-config.wsdd file in working directory.");
095: }
096: }
097:
098: public void tearDown() throws Exception {
099: if (null != axisServer) {
100: axisServer.stop();
101: axisServer = null;
102: }
103: // If there was no server-config.wsdd file before running the test
104: // and we created one, then delete it.
105: File serverConfig = new File("server-config.wsdd");
106: if (!configExists && serverConfig.exists()) {
107: System.out
108: .println("Removing generated server-config.wsdd.");
109: serverConfig.delete();
110: }
111: }
112:
113: protected boolean verify(Logger l) {
114: AdminClient admin = new AdminClient();
115: try {
116: Options opts = new Options(new String[] { "-p",
117: Integer.toString(AXIS_PORT) });
118: InputStream is = getClass().getResourceAsStream(
119: "resources/echoUndeploy.wsdd");
120: String result = admin.process(opts, is);
121: if (null == result || result.contains("AxisFault")) {
122: return false;
123: }
124: admin.quit(opts);
125: } catch (Exception ex) {
126: return false;
127: }
128: return true;
129: }
130:
131: public static void main(String[] args) {
132: try {
133: AxisServer s = new AxisServer();
134: s.setUp();
135: s.start();
136: s.tearDown();
137: } catch (Exception ex) {
138: ex.printStackTrace();
139: System.exit(-1);
140: } finally {
141: System.out.println("done!");
142: }
143: }
144: }
|