1 57 58 package org.apache.soap.server; 59 60 import java.util.*; 61 import java.io.*; 62 import javax.servlet.*; 63 import javax.xml.parsers.*; 64 import org.apache.soap.*; 65 import org.apache.soap.server.http.*; 66 import org.apache.soap.util.* ; 67 import org.apache.soap.util.xml.*; 68 import org.apache.soap.rpc.SOAPContext ; 69 import org.w3c.dom.*; 70 import org.xml.sax.*; 71 72 78 public class ServiceManager { 79 protected String configFilename = "soap.xml"; 80 protected DeploymentDescriptor smsdd; protected ConfigManager configMgr = null; 82 protected ServletContext context = null; 83 protected DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); 84 protected boolean soapInterfaceEnabled = true; 85 86 public ServiceManager (ServletContext context, String configFilename) { 87 this.context = context; 88 89 if (configFilename != null && !configFilename.equals("")) 90 { 91 this.configFilename = configFilename; 92 } 93 94 readConfigFile (); 95 96 98 if (soapInterfaceEnabled) 99 { 100 smsdd = new DeploymentDescriptor (); 101 smsdd.setID (ServerConstants.SERVICE_MANAGER_SERVICE_NAME); 102 String [] svcs = new String [] { "deploy", "undeploy", "list", "query" }; 103 smsdd.setMethods (svcs); 104 smsdd.setScope (DeploymentDescriptor.SCOPE_APPLICATION); 105 smsdd.setProviderType (DeploymentDescriptor.PROVIDER_JAVA); 106 smsdd.setProviderClass ("org.apache.soap.server.ServiceManager"); 107 smsdd.setIsStatic (false); 108 109 smsdd.setMappings (new TypeMapping[] { 112 new TypeMapping (Constants.NS_URI_SOAP_ENC, 113 new QName (Constants.NS_URI_XML_SOAP, 114 "DeploymentDescriptor"), 115 "org.apache.soap.server.DeploymentDescriptor", 116 "org.apache.soap.encoding.soapenc.BeanSerializer", 117 "org.apache.soap.encoding.soapenc.BeanSerializer"), 118 new TypeMapping (Constants.NS_URI_SOAP_ENC, 119 new QName (Constants.NS_URI_XML_SOAP, 120 "TypeMapping"), 121 "org.apache.soap.server.TypeMapping", 122 "org.apache.soap.server.TypeMappingSerializer", 123 "org.apache.soap.server.TypeMappingSerializer")}); 124 } 125 } 126 127 public void setConfigFilename (String configFilename) { 128 if (configFilename == null || configFilename.equals("")) 129 { 130 return; 131 } 132 else 133 { 134 this.configFilename = configFilename; 135 readConfigFile(); 136 } 137 } 138 139 private void readConfigFile() { 140 FileReader reader = null ; 141 Document doc = null ; 142 Element elem = null ; 143 NodeList list = null ; 144 int i, k ; 145 Hashtable options = null ; 146 147 try { 148 File configFile = 149 ServerHTTPUtils.getFileFromNameAndContext(configFilename, context); 150 151 reader = new FileReader(configFile); 152 doc = xdb.parse(new InputSource(reader)); 153 elem = doc.getDocumentElement(); 154 if ( !"soapServer".equals(elem.getTagName()) ) 155 throw new Exception ( "Root element must be 'soapServer'" ); 156 157 list = elem.getChildNodes(); 158 for ( i = 0 ; list != null && i < list.getLength() ; i++ ) { 159 String name = null ; 160 Node n = list.item( i ); 161 162 if ( n.getNodeType() != Node.ELEMENT_NODE ) continue ; 163 elem = (Element) n ; 164 name = elem.getTagName(); 165 if ( name.equals( "configManager" ) ) { 166 String className = elem.getAttribute( "value" ); 167 168 ClassLoader cl = null ; 169 Class c = null ; 170 171 cl = ServerHTTPUtils.getServletClassLoaderFromContext(context); 172 173 if ( cl == null ) 174 c = Class.forName( className ); 175 else 176 c = Class.forName( className, true, cl ); 177 178 if (!ConfigManager.class.isAssignableFrom(c)) { 179 throw new IllegalArgumentException ("Class '" + className + 180 "' isn't a ConfigManager."); 181 } 182 183 configMgr = (ConfigManager) c.newInstance(); 184 185 configMgr.setContext(context); 187 NodeList optList = elem.getElementsByTagName( "option" ); 189 for ( k = 0 ; optList != null && k < optList.getLength() ; k++ ) { 190 elem = (Element) optList.item( k ); 191 name = elem.getAttribute( "name" ); 192 String value = elem.getAttribute( "value" ) ; 193 if ( options == null ) options = new Hashtable(); 194 if ( name == null || value == null ) continue ; 195 options.put( name, value ); 196 } 197 if ( options != null ) 199 configMgr.setOptions( options ); 200 } 201 else 202 if (name.equals("serviceManager")) 203 { 204 NodeList optList = elem.getElementsByTagName( "option" ); 206 for ( k = 0 ; optList != null && k < optList.getLength() ; k++ ) { 207 elem = (Element) optList.item( k ); 208 name = elem.getAttribute( "name" ); 209 String value = elem.getAttribute( "value" ) ; 210 if ( name == null || value == null ) continue ; 211 if (name.equalsIgnoreCase("SOAPInterfaceEnabled") && value.equalsIgnoreCase("false")) 212 soapInterfaceEnabled = false; 213 } 214 } 215 } 216 reader.close(); 217 } 218 catch( Throwable e ) { 219 if ( reader != null ) { 223 System.err.println( "Error processing configuration file (" + 224 configFilename + ")" ); 225 System.err.println( "Error was: " + e ); 226 System.err.println( "Using DefaultConfigManager" ); 227 } 228 } 229 230 231 if ( configMgr == null ) { 234 configMgr = new DefaultConfigManager( ); 235 236 configMgr.setContext(context); 238 } 239 240 try { 241 configMgr.init(); 242 } 243 catch( SOAPException e ) { 244 e.printStackTrace(); 245 } 246 } 247 248 252 public void deploy (DeploymentDescriptor dd) throws SOAPException { 253 String id = dd.getID (); 254 if (id.equals (ServerConstants.SERVICE_MANAGER_SERVICE_NAME)) { 255 throw new SOAPException (Constants.FAULT_CODE_SERVER, 256 "service management service '" + 257 ServerConstants.SERVICE_MANAGER_SERVICE_NAME + 258 "' cannot be user deployed"); 259 } 260 configMgr.deploy( dd ); 261 } 262 263 270 public DeploymentDescriptor undeploy (String id) throws SOAPException { 271 return( configMgr.undeploy( id ) ); 272 } 273 274 282 public DeploymentDescriptor query(String id) throws SOAPException { 283 if (id == null) 284 return null; 285 else if (id.equals (ServerConstants.SERVICE_MANAGER_SERVICE_NAME)) 286 return smsdd; 287 else { 288 DeploymentDescriptor dd = configMgr.query( id ); 289 if (dd != null) 290 return dd; 291 else 292 throw new SOAPException (Constants.FAULT_CODE_SERVER, 295 "service '" + id + "' unknown"); 296 } 297 } 298 299 305 public String [] list () throws SOAPException { 306 return( configMgr.list() ); 307 } 308 } 309 | Popular Tags |