1 16 17 package org.apache.axis2.integration; 18 19 import junit.framework.TestCase; 20 import org.apache.axis2.context.ConfigurationContext; 21 import org.apache.axis2.context.ConfigurationContextFactory; 22 import org.apache.axis2.context.ServiceContext; 23 import org.apache.axis2.deployment.DeploymentEngine; 24 import org.apache.axis2.description.ModuleDescription; 25 import org.apache.axis2.description.ServiceDescription; 26 import org.apache.axis2.engine.AxisFault; 27 import org.apache.axis2.transport.http.SimpleHTTPServer; 28 import org.apache.axis2.util.Utils; 29 30 import javax.xml.namespace.QName ; 31 import java.io.File ; 32 import java.net.ServerSocket ; 33 34 public class UtilServer { 35 private static int count = 0; 36 private static SimpleHTTPServer reciver; 37 public static final int TESTING_PORT = 5555; 38 public static final String FAILURE_MESSAGE = "Intentional Faliure"; 39 40 public static synchronized void deployService(ServiceDescription service) throws AxisFault { 41 reciver.getSystemContext().getAxisConfiguration().addService(service); 42 Utils.resolvePhases(reciver.getSystemContext().getAxisConfiguration(), service); 43 } 44 45 public static synchronized void unDeployService(QName service) throws AxisFault { 46 reciver.getSystemContext().getAxisConfiguration().removeService(service); 47 } 48 49 public static synchronized void start() throws Exception { 50 start(org.apache.axis2.Constants.TESTING_REPOSITORY); 51 } 52 53 public static synchronized void start(String repositry) throws Exception { 54 if (count == 0) { 55 ConfigurationContextFactory erfac = new ConfigurationContextFactory(); 56 File file = new File (repositry); 57 if (!file.exists()) { 58 throw new Exception ("repository directory "+ file.getAbsolutePath()+ " does not exists"); 59 } 60 ConfigurationContext er = erfac.buildConfigurationContext(file.getAbsolutePath()); 61 try { 62 Thread.sleep(2000); 63 } catch (InterruptedException e1) { 64 throw new AxisFault("Thread interuptted", e1); 65 } 66 67 ServerSocket serverSoc = null; 68 serverSoc = new ServerSocket (Constants.TESTING_PORT); 69 reciver = new SimpleHTTPServer(er, serverSoc); 70 Thread thread = new Thread (reciver); 71 thread.setDaemon(true); 72 73 try { 74 thread.start(); 75 System.out.print("Server started on port " + Constants.TESTING_PORT + "....."); 76 } finally { 77 78 } 79 } 80 count++; 81 } 82 83 public static synchronized void stop() { 84 if (count == 1) { 85 reciver.stop(); 86 count = 0; 87 System.out.print("Server stopped ....."); 88 } else { 89 count--; 90 } 91 } 92 93 public static ConfigurationContext getConfigurationContext() { 94 return reciver.getSystemContext(); 95 } 96 97 public static ServiceContext createAdressedEnabledClientSide(ServiceDescription service) 98 throws AxisFault { 99 DeploymentEngine deploymentEngine = new DeploymentEngine(); 100 File file = new File (org.apache.axis2.Constants.TESTING_REPOSITORY + "/modules/addressing.mar"); 101 TestCase.assertTrue(file.exists()); 102 ModuleDescription moduleDesc = deploymentEngine.buildModule(file); 103 104 ConfigurationContextFactory efac = new ConfigurationContextFactory(); 105 ConfigurationContext sysContext = efac.buildClientConfigurationContext(null); 106 107 sysContext.getAxisConfiguration().addMdoule(moduleDesc); 108 110 sysContext.getAxisConfiguration().addService(service); 111 ServiceContext serviceContext = sysContext.createServiceContext(service.getName()); 113 return serviceContext; 114 115 } 116 117 } 118 | Popular Tags |