1 16 17 package org.apache.axis2.integration; 18 19 import org.apache.axis2.context.ConfigurationContext; 20 import org.apache.axis2.context.ConfigurationContextFactory; 21 import org.apache.axis2.description.ServiceDescription; 22 import org.apache.axis2.engine.AxisFault; 23 import org.apache.axis2.transport.tcp.TCPServer; 24 25 import javax.xml.namespace.QName ; 26 import java.io.File ; 27 28 public class UtilsTCPServer { 29 private static int count = 0; 30 private static TCPServer reciver; 31 32 private static ConfigurationContext configurationContext; 33 public static final int TESTING_PORT = 5555; 34 public static final String FAILURE_MESSAGE = "Intentional Faliure"; 35 36 public static synchronized void deployService(ServiceDescription service) 37 throws AxisFault { 38 configurationContext.getAxisConfiguration().addService(service); 39 40 } 41 42 public static synchronized void unDeployService(QName service) 43 throws AxisFault { 44 configurationContext.getAxisConfiguration().removeService(service); 45 } 46 47 public static synchronized void start() throws Exception { 48 if (count == 0) { 49 50 52 ConfigurationContextFactory erfac = 53 new ConfigurationContextFactory(); 54 File file = new File (org.apache.axis2.Constants.TESTING_REPOSITORY); 55 System.out.println(file.getAbsoluteFile()); 56 if (!file.exists()) { 57 throw new Exception ("repository directory does not exists"); 58 } 59 60 configurationContext = 61 erfac.buildConfigurationContext(file.getAbsolutePath()); 62 try { 63 Thread.sleep(2000); 64 } catch (InterruptedException e1) { 65 throw new AxisFault("Thread interuptted", e1); 66 } 67 configurationContext.getAxisConfiguration().engageModule( 68 new QName ("addressing")); 69 reciver = 70 new TCPServer(UtilServer.TESTING_PORT, configurationContext); 71 reciver.start(); 72 73 } 74 count++; 75 } 76 77 public static synchronized void stop() { 78 try { 79 if (count == 1) { 80 reciver.stop(); 81 count = 0; 82 System.out.print("Server stopped ....."); 83 } else { 84 count--; 85 } 86 } catch (AxisFault e) { 87 e.printStackTrace(); 89 } 90 } 91 92 public static ConfigurationContext getConfigurationContext() { 93 return configurationContext; 94 } 95 } 96 | Popular Tags |