You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by du...@locus.apache.org on 2000/12/14 01:11:16 UTC
cvs commit: xml-soap/java/src/org/apache/soap/util ConfigManager.java
dug 00/12/13 16:11:15
Modified: java/src/org/apache/soap/server ServiceManager.java
java/src/org/apache/soap/server/http
MessageRouterServlet.java RPCRouterServlet.java
Added: java/src/org/apache/soap/server DefaultConfigManager.java
java/src/org/apache/soap/util ConfigManager.java
Log:
Adding support for pluggable Config Managers
Revision Changes Path
1.6 +91 -29 xml-soap/java/src/org/apache/soap/server/ServiceManager.java
Index: ServiceManager.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/ServiceManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServiceManager.java 2000/09/01 03:52:53 1.5
+++ ServiceManager.java 2000/12/14 00:11:08 1.6
@@ -59,8 +59,10 @@
import java.util.*;
import java.io.*;
-import org.apache.soap.util.xml.QName;
import org.apache.soap.*;
+import org.apache.soap.util.* ;
+import org.apache.soap.util.xml.* ;
+import org.w3c.dom.* ;
/**
* A <code>ServiceManager</code> manages services and their associated
@@ -69,13 +71,15 @@
* @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
*/
public class ServiceManager {
- protected Hashtable dds;
- protected String filename = "DeployedServices.ds";
- // service management service's deployment descriptor
- protected DeploymentDescriptor smsdd;
- protected String[] serviceNamesCache;
+ protected static String configFilename = "soap.xml" ;
+ protected Hashtable dds;
+ protected DeploymentDescriptor smsdd; // Svc Mgmnt Svc's Dep Descriptor
+ protected String[] serviceNamesCache;
+ protected ConfigManager configMgr = null ;
public ServiceManager () {
+ readConfigFile();
+
smsdd = new DeploymentDescriptor ();
smsdd.setID (ServerConstants.SERVICE_MANAGER_SERVICE_NAME);
String[] svcs = new String[] { "deploy", "undeploy", "list", "query" };
@@ -101,33 +105,89 @@
"org.apache.soap.server.TypeMappingSerializer",
"org.apache.soap.server.TypeMappingSerializer")});
- // load in a serialized thing
try {
- FileInputStream fis = new FileInputStream (filename);
- ObjectInputStream is = new ObjectInputStream (fis);
-
- dds = (Hashtable) is.readObject ();
- is.close ();
- } catch(Exception e) {
- dds = new Hashtable ();
- System.err.println ("SOAP Service Manager: Unable to read '" +
- filename + "': assuming fresh start");
+ dds = configMgr.loadRegistry();
}
+ catch( SOAPException e ) {
+ // Just ignore it ??
+ }
+
}
- private void saveRegistry () throws SOAPException {
- serviceNamesCache = null;
+ public static void setConfigFilename( String name ) {
+ if (name == null || "".equals(name)) return ;
+ configFilename = name ;
+ }
+
+ private void readConfigFile() {
+ XMLParserLiaison xpl = null ;
+ FileReader reader = null ;
+ Document doc = null ;
+ Element elem = null ;
+ NodeList list = null ;
+ int i, k ;
+ Hashtable options = null ;
+
try {
- FileOutputStream fos = new FileOutputStream (filename);
- ObjectOutputStream os = new ObjectOutputStream (fos);
+
+ xpl = new XercesParserLiaison();
+ reader = new FileReader( configFilename );
+ doc = xpl.read( "Config File", reader );
+ elem = doc.getDocumentElement();
+ if ( !"soapServer".equals(elem.getTagName()) )
+ throw new Exception( "Root element must be 'soapServer'" );
+
+ list = elem.getChildNodes();
+ for ( i = 0 ; list != null && i < list.getLength() ; i++ ) {
+ String name = null ;
+ Node n = list.item( i );
+
+ if ( n.getNodeType() != Node.ELEMENT_NODE ) continue ;
+ elem = (Element) n ;
+ name = elem.getTagName();
+ if ( name.equals( "configManager" ) ) {
+ String className = elem.getAttribute( "value" );
+ Class c = Class.forName( className );
+ configMgr = (ConfigManager) c.newInstance();
+ if ( !(configMgr instanceof ConfigManager) )
+ throw new Exception( "Class " + className + " isn't a " +
+ "ConfigManager" );
+ // Now check for options
+
+ NodeList optList = elem.getElementsByTagName( "option" );
+ for ( k = 0 ; optList != null && k < optList.getLength() ; k++ ) {
+ elem = (Element) optList.item( k );
+ name = elem.getAttribute( "name" );
+ String value = elem.getAttribute( "value" ) ;
+ if ( options == null ) options = new Hashtable();
+ if ( name == null || value == null ) continue ;
+ options.put( name, value );
+ }
+ // Now set the options
+ if ( options != null )
+ configMgr.setOptions( options );
+ }
+ }
+ reader.close();
+ }
+ catch( Throwable e ) {
+ // For backwards compatibility - if there was no reader then
+ // we probably failed because the file doesn't exists and in that
+ // case just skip the error message - it'll just annoy old users
+ if ( reader != null ) {
+ System.err.println( "Error processing configuration file (" +
+ configFilename + ")" );
+ System.err.println( "Error was: " + e );
+ System.err.println( "Using DefaultConfigManager" );
+ }
+ }
- os.writeObject (dds);
- os.close ();
- } catch (Exception e) {
- throw new SOAPException (Constants.FAULT_CODE_SERVER,
- "Error saving services registry: " +
- e.getMessage ());
- };
+
+ // When all is said and done - if there still isn't a configMgr
+ // then use the default one.
+ if ( configMgr == null )
+ configMgr = new DefaultConfigManager( );
+
}
/**
@@ -143,7 +203,8 @@
"' cannot be user deployed");
}
dds.put (id, dd);
- saveRegistry ();
+ configMgr.saveRegistry( dds );
+ serviceNamesCache = null;
}
/**
@@ -157,7 +218,8 @@
throws SOAPException {
DeploymentDescriptor dd = (DeploymentDescriptor) dds.remove (id);
if (dd != null) {
- saveRegistry ();
+ configMgr.saveRegistry( dds );
+ serviceNamesCache = null;
} else {
throw new SOAPException (Constants.FAULT_CODE_SERVER,
"service '" + id + "' unknown");
1.1 xml-soap/java/src/org/apache/soap/server/DefaultConfigManager.java
Index: DefaultConfigManager.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.server ;
import java.util.* ;
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import org.apache.soap.* ;
import org.apache.soap.rpc.* ;
import org.apache.soap.server.* ;
import org.apache.soap.util.* ;
/**
* A <code>DefaultConfigManager</code> ...
*
* @author Dug (dug@us.ibm.com)
*
* Just writes it out to a file.
* To override where it goes specify a "filename" in the
* option section of the "configManager" portion of the soap.xml file
*
*/
public class DefaultConfigManager implements ConfigManager {
protected String filename = "DeployedServices.ds";
public void setOptions( Hashtable options ) {
if ( options == null ) return ;
String value = (String) options.get( "filename" );
if ( value != null && !"".equals(value) )
filename = value ;
}
public Hashtable loadRegistry() throws SOAPException {
// load in a serialized thing
Hashtable dds = null ;
try {
FileInputStream fis = new FileInputStream (filename);
ObjectInputStream is = new ObjectInputStream (fis);
dds = (Hashtable) is.readObject ();
is.close ();
} catch(Exception e) {
dds = new Hashtable ();
System.err.println ("SOAP Service Manager: Unable to read '" +
filename + "': assuming fresh start");
}
return( dds );
}
public void saveRegistry(Hashtable dds) throws SOAPException {
try {
FileOutputStream fos = new FileOutputStream (filename);
ObjectOutputStream os = new ObjectOutputStream (fos);
os.writeObject (dds);
os.close ();
} catch (Exception e) {
throw new SOAPException (Constants.FAULT_CODE_SERVER,
"Error saving services registry: " +
e.getMessage ());
};
}
};
1.7 +8 -0 xml-soap/java/src/org/apache/soap/server/http/MessageRouterServlet.java
Index: MessageRouterServlet.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/MessageRouterServlet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MessageRouterServlet.java 2000/11/29 00:23:54 1.6
+++ MessageRouterServlet.java 2000/12/14 00:11:11 1.7
@@ -110,6 +110,7 @@
private static final String TRANSPORT_HOOK_EXTENSION =
"org.apache.soap.TransportHookExtension" ;
+ private static final String CONFIGFILENAME = "ConfigFile";
private EnvelopeEditor editor = null;
private XMLParserLiaison xpl = new XercesParserLiaison();
@@ -136,6 +137,13 @@
}
if ((xpl = (XMLParserLiaison)createObject(XML_PARSER)) == null)
xpl = new XercesParserLiaison();
+ }
+ Enumeration enum = getServletConfig().getInitParameterNames();
+ while(enum.hasMoreElements()) {
+ String name = (String)enum.nextElement();
+ String value = getServletConfig().getInitParameter(name);
+ if (CONFIGFILENAME.equals(name))
+ ServiceManager.setConfigFilename( value );
}
}
1.11 +26 -18 xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java
Index: RPCRouterServlet.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RPCRouterServlet.java 2000/11/28 23:03:56 1.10
+++ RPCRouterServlet.java 2000/12/14 00:11:11 1.11
@@ -114,33 +114,41 @@
private static final String ENVELOPE_EDITOR_FACTORY =
"EnvelopeEditorFactory";
private static final String XML_PARSER = "XMLParser";
+ private static final String CONFIGFILENAME = "ConfigFile";
private EnvelopeEditor editor = null;
private XMLParserLiaison xpl = new XercesParserLiaison();
public void init() {
if (System.getProperties().
getProperty(Constants.TRANSPORT_HOOK_EXTENSION) != null) {
- EnvelopeEditorFactory factory =
- (EnvelopeEditorFactory)createObject(ENVELOPE_EDITOR_FACTORY);
- if (factory != null) {
- try {
- Properties props = new Properties();
- Enumeration enum = getServletConfig().getInitParameterNames();
- while(enum.hasMoreElements()) {
- String name = (String)enum.nextElement();
- if (!ENVELOPE_EDITOR_FACTORY.equals(name) &&
- !XML_PARSER.equals(name))
- props.put(name, getServletConfig().getInitParameter(name));
+ EnvelopeEditorFactory factory =
+ (EnvelopeEditorFactory)createObject(ENVELOPE_EDITOR_FACTORY);
+ if (factory != null) {
+ try {
+ Properties props = new Properties();
+ Enumeration enum = getServletConfig().getInitParameterNames();
+ while(enum.hasMoreElements()) {
+ String name = (String)enum.nextElement();
+ if (!ENVELOPE_EDITOR_FACTORY.equals(name) &&
+ !XML_PARSER.equals(name))
+ props.put(name, getServletConfig().getInitParameter(name));
+ }
+ editor = factory.create(props);
+ } catch (SOAPException e) {
+ System.err.println("WARNING: Can't create editor: " +
+ e.getMessage());
}
- editor = factory.create(props);
- } catch (SOAPException e) {
- System.err.println("WARNING: Can't create editor: " +
- e.getMessage());
}
+ if ((xpl = (XMLParserLiaison)createObject(XML_PARSER)) == null)
+ xpl = new XercesParserLiaison();
}
- if ((xpl = (XMLParserLiaison)createObject(XML_PARSER)) == null)
- xpl = new XercesParserLiaison();
- }
+ Enumeration enum = getServletConfig().getInitParameterNames();
+ while(enum.hasMoreElements()) {
+ String name = (String)enum.nextElement();
+ String value = getServletConfig().getInitParameter(name);
+ if (CONFIGFILENAME.equals(name))
+ ServiceManager.setConfigFilename( value );
+ }
}
private Object createObject(String name) {
1.1 xml-soap/java/src/org/apache/soap/util/ConfigManager.java
Index: ConfigManager.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.util;
import java.util.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import org.apache.soap.* ;
import org.apache.soap.rpc.* ;
import org.apache.soap.server.* ;
/**
* A <code>ConfigManager</code> ...
*
* @author Dug (dug@us.ibm.com)
*
*/
public interface ConfigManager
{
public void setOptions( Hashtable options ) throws SOAPException ;
public void saveRegistry( Hashtable dds ) throws SOAPException ;
public Hashtable loadRegistry() throws SOAPException ;
}