1 package org.objectweb.celtix.axisinterop; 2 3 import java.io.File ; 4 import java.io.InputStream ; 5 import java.net.ServerSocket ; 6 import java.util.logging.Logger ; 7 8 import org.apache.axis.client.AdminClient; 9 import org.apache.axis.transport.http.SimpleAxisServer; 10 import org.apache.axis.utils.Options; 11 import org.objectweb.celtix.testutil.common.AbstractTestServerBase; 12 13 public class AxisServer extends AbstractTestServerBase { 14 15 private static final int AXIS_PORT = 9360; 16 private SimpleAxisServer axisServer; 17 private boolean configExists; 18 19 protected void run() { 20 axisServer = new SimpleAxisServer(); 21 ServerSocket socket = null; 22 final int retries = 5; 23 for (int i = 0; i < retries; i++) { 24 try { 25 socket = new ServerSocket (AXIS_PORT); 26 break; 27 } catch (java.net.BindException be) { 28 if (i < (retries - 1)) { 30 try { 31 Thread.sleep(3000); 32 } catch (InterruptedException ex) { 33 } 35 } else { 36 System.err.println("Failed to start axisServer on port : " 37 + Integer.toString(AXIS_PORT)); 38 startFailed(); 39 } 40 } catch (java.io.IOException ie) { 41 System.err.println("Failed to start axisServer."); 42 startFailed(); 43 } 44 } 45 axisServer.setServerSocket(socket); 46 try { 47 axisServer.start(true); 48 AdminClient admin = new AdminClient(); 49 Options opts = new Options(new String [] {"-p", Integer.toString(AXIS_PORT)}); 50 InputStream is = getClass().getResourceAsStream("resources/echoDeploy.wsdd"); 51 String result = admin.process(opts, is); 52 if (null == result || result.contains("AxisFault")) { 53 throw new Exception ("Failed to start axis server"); 54 } 55 } catch (Exception ex) { 56 System.err.println("Failed to deploy echo axis server."); 57 axisServer.stop(); 58 axisServer = null; 59 startFailed(); 60 } 61 } 62 63 public void start() { 64 try { 65 System.out.println("running server"); 66 run(); 67 System.out.println("signal ready"); 68 ready(); 69 70 System.in.read(); 74 System.out.println("stopping bus"); 75 76 } catch (Throwable ex) { 77 ex.printStackTrace(); 78 startFailed(); 79 } finally { 80 if (verify(getLog())) { 81 System.out.println("server passed"); 82 } 83 System.out.println("server stopped"); 84 } 85 } 86 87 public void setUp() throws Exception { 88 configExists = new File ("server-config.wsdd").exists(); 89 if (configExists) { 90 System.out.println("Warning: Found an axis server-config.wsdd file in working directory."); 91 } 92 } 93 94 public void tearDown() throws Exception { 95 if (null != axisServer) { 96 axisServer.stop(); 97 axisServer = null; 98 } 99 File serverConfig = new File ("server-config.wsdd"); 102 if (!configExists && serverConfig.exists()) { 103 System.out.println("Removing generated server-config.wsdd."); 104 serverConfig.delete(); 105 } 106 } 107 108 protected boolean verify(Logger l) { 109 AdminClient admin = new AdminClient(); 110 try { 111 Options opts = new Options(new String [] {"-p", Integer.toString(AXIS_PORT)}); 112 InputStream is = getClass().getResourceAsStream("resources/echoUndeploy.wsdd"); 113 String result = admin.process(opts, is); 114 if (null == result || result.contains("AxisFault")) { 115 return false; 116 } 117 admin.quit(opts); 118 } catch (Exception ex) { 119 return false; 120 } 121 return true; 122 } 123 124 public static void main(String [] args) { 125 try { 126 AxisServer s = new AxisServer(); 127 s.setUp(); 128 s.start(); 129 s.tearDown(); 130 } catch (Exception ex) { 131 ex.printStackTrace(); 132 System.exit(-1); 133 } finally { 134 System.out.println("done!"); 135 } 136 } 137 } 138
| Popular Tags
|