1 16 package org.apache.axis.management; 17 18 import org.apache.axis.AxisFault; 19 import org.apache.axis.ConfigurationException; 20 import org.apache.axis.EngineConfiguration; 21 import org.apache.axis.WSDDEngineConfiguration; 22 import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration; 23 import org.apache.axis.deployment.wsdd.WSDDHandler; 24 import org.apache.axis.deployment.wsdd.WSDDService; 25 import org.apache.axis.deployment.wsdd.WSDDTransport; 26 import org.apache.axis.description.ServiceDesc; 27 import org.apache.axis.handlers.soap.SOAPService; 28 import org.apache.axis.management.jmx.DeploymentAdministrator; 29 import org.apache.axis.management.jmx.DeploymentQuery; 30 import org.apache.axis.management.jmx.ServiceAdministrator; 31 import org.apache.axis.server.AxisServer; 32 33 import javax.xml.namespace.QName ; 34 import java.util.ArrayList ; 35 import java.util.Iterator ; 36 37 44 public class ServiceAdmin { 45 static private AxisServer axisServer = null; 47 48 54 static public void startService(String serviceName) 55 throws AxisFault, ConfigurationException { 56 AxisServer server = getEngine(); 57 try { 58 SOAPService service = server.getConfig().getService( 59 new QName ("", serviceName)); 60 service.start(); 61 } catch (ConfigurationException configException) { 62 if (configException.getContainedException() instanceof AxisFault) { 63 throw (AxisFault) configException.getContainedException(); 64 } else { 65 throw configException; 66 } 67 } 68 } 69 70 76 static public void stopService(String serviceName) 77 throws AxisFault, ConfigurationException { 78 AxisServer server = getEngine(); 79 try { 80 SOAPService service = server.getConfig().getService( 81 new QName ("", serviceName)); 82 service.stop(); 83 } catch (ConfigurationException configException) { 84 if (configException.getContainedException() instanceof AxisFault) { 85 throw (AxisFault) configException.getContainedException(); } else { 87 throw configException; 88 } 89 } 90 } 91 92 98 static public String [] listServices() 99 throws AxisFault, ConfigurationException { 100 ArrayList list = new ArrayList (); 101 AxisServer server = getEngine(); 102 Iterator iter; try { 104 iter = server.getConfig().getDeployedServices(); 105 } catch (ConfigurationException configException) { 106 if (configException.getContainedException() instanceof AxisFault) { 107 throw (AxisFault) configException.getContainedException(); } else { 109 throw configException; 110 } 111 } 112 while (iter.hasNext()) { 113 ServiceDesc sd = (ServiceDesc) iter.next(); 114 String name = sd.getName(); 115 list.add(name); 116 } 117 return (String []) list.toArray(new String [list.size()]); 118 } 119 120 126 static public AxisServer getEngine() throws AxisFault { 127 if (axisServer == null) { 128 throw new AxisFault( 130 "Unable to locate AxisEngine for ServiceAdmin Object"); 131 } 132 return axisServer; 133 } 134 135 140 static public void setEngine(AxisServer axisSrv, String name) { 141 ServiceAdmin.axisServer = axisSrv; 142 Registrar.register(new ServiceAdministrator(), "axis:type=server", "ServiceAdministrator"); 143 Registrar.register(new DeploymentAdministrator(), "axis:type=deploy", "DeploymentAdministrator"); 144 Registrar.register(new DeploymentQuery(), "axis:type=query", "DeploymentQuery"); 145 } 146 147 static public void start() { 148 if (axisServer != null) { 149 axisServer.start(); 150 } 151 } 152 153 static public void stop() { 154 if (axisServer != null) { 155 axisServer.stop(); 156 } 157 } 158 159 static public void restart() { 160 if (axisServer != null) { 161 axisServer.stop(); 162 axisServer.start(); 163 } 164 } 165 166 static public void saveConfiguration() { 167 if (axisServer != null) { 168 axisServer.saveConfiguration(); 169 } 170 } 171 172 static private WSDDEngineConfiguration getWSDDEngineConfiguration() { 173 if (axisServer != null) { 174 EngineConfiguration config = axisServer.getConfig(); 175 if (config instanceof WSDDEngineConfiguration) { 176 return (WSDDEngineConfiguration) config; 177 } else { 178 throw new RuntimeException ("WSDDDeploymentHelper.getWSDDEngineConfiguration(): EngineConguration not of type WSDDEngineConfiguration"); 179 } 180 } 181 return null; 182 } 183 184 static public void setGlobalConfig(WSDDGlobalConfiguration globalConfig) { 185 getWSDDEngineConfiguration().getDeployment().setGlobalConfiguration(globalConfig); 186 } 187 188 static public WSDDGlobalConfiguration getGlobalConfig() { 189 return getWSDDEngineConfiguration().getDeployment().getGlobalConfiguration(); 190 } 191 192 static public WSDDHandler getHandler(QName qname) { 193 return getWSDDEngineConfiguration().getDeployment().getWSDDHandler(qname); 194 } 195 196 static public WSDDHandler[] getHandlers() { 197 return getWSDDEngineConfiguration().getDeployment().getHandlers(); 198 } 199 200 static public WSDDService getService(QName qname) { 201 return getWSDDEngineConfiguration().getDeployment().getWSDDService(qname); 202 } 203 204 static public WSDDService[] getServices() { 205 return getWSDDEngineConfiguration().getDeployment().getServices(); 206 } 207 208 static public WSDDTransport getTransport(QName qname) { 209 return getWSDDEngineConfiguration().getDeployment().getWSDDTransport(qname); 210 } 211 212 static public WSDDTransport[] getTransports() { 213 return getWSDDEngineConfiguration().getDeployment().getTransports(); 214 } 215 216 static public void deployHandler(WSDDHandler handler) { 217 getWSDDEngineConfiguration().getDeployment().deployHandler(handler); 218 } 219 220 static public void deployService(WSDDService service) { 221 getWSDDEngineConfiguration().getDeployment().deployService(service); 222 } 223 224 static public void deployTransport(WSDDTransport transport) { 225 getWSDDEngineConfiguration().getDeployment().deployTransport(transport); 226 } 227 228 static public void undeployHandler(QName qname) { 229 getWSDDEngineConfiguration().getDeployment().undeployHandler(qname); 230 } 231 232 static public void undeployService(QName qname) { 233 getWSDDEngineConfiguration().getDeployment().undeployService(qname); 234 } 235 236 static public void undeployTransport(QName qname) { 237 getWSDDEngineConfiguration().getDeployment().undeployTransport(qname); 238 } 239 } | Popular Tags |