ws-soap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@locus.apache.org
Subject cvs commit: xml-soap/java/src/org/apache/soap/util Provider.java
Date Tue, 07 Nov 2000 00:35:02 GMT
dug         00/11/06 16:35:02

  Modified:    java/src/org/apache/soap/rpc RPCMessage.java
               java/src/org/apache/soap/server DeploymentDescriptor.java
                        RPCRouter.java
               java/src/org/apache/soap/server/http RPCRouterServlet.java
                        ServerHTTPUtils.java
  Added:       java/samples/ejb DeploymentDescriptor.xml ejbtest.java
                        hellobean.jar
               java/src/org/apache/soap/providers JavaProvider.java
                        StatelessEJBProvider.java TemplateProvider.java
               java/src/org/apache/soap/util Provider.java
  Log:
  Added support for Pluggable Providers
  Reviewed by:	Glen Daniels
  
  Revision  Changes    Path
  1.1                  xml-soap/java/samples/ejb/DeploymentDescriptor.xml
  
  Index: DeploymentDescriptor.xml
  ===================================================================
  <?xml version="1.0"?>
  <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
               id="urn:testprovider">
    <isd:provider type="org.apache.soap.providers.StatelessEJBProvider"
                  scope="Application"
                  methods="create">
      <isd:java class="samples/HelloService"/>
      <isd:option key="FullHomeInterfaceName" value="samples.HelloServiceHome" />
      <isd:option key="ContextProviderURL" value="iiop://localhost:900" />
      <isd:option key="FullContextFactoryName" value="com.ibm.ejs.ns.jndi.CNInitialContextFactory" />
    </isd:provider>
  	<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
  </isd:service>
  
  
  
  
  
  1.1                  xml-soap/java/samples/ejb/ejbtest.java
  
  Index: ejbtest.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 samples.ejb;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import org.apache.soap.util.xml.*;
  import org.apache.soap.*;
  import org.apache.soap.rpc.*;
  
  public class ejbtest {
    static XMLParserLiaison xpl = new XercesParserLiaison ();
  
    public static void main (String[] args) throws Exception {
      if (args.length != 1 ) {
        System.err.println ("Usage: java " + ejbtest.class.getName () +
                            " SOAP-router-URL");
        System.exit (1);
      }
  
      // Process the arguments.
      URL url = new URL (args[0]);
  
      // Build the call.
      Call call = new Call ();
      call.setTargetObjectURI ("urn:ejbhello");
      call.setMethodName ("hello");
      Vector params = new Vector ();
      // params.addElement (new Parameter("symbol", String.class, symbol, null));
      call.setParams (params);
  
      // make the call: note that the action URI is empty because the 
      // XML-SOAP rpc router does not need this. This may change in the
      // future.
      Response resp = call.invoke (/* router URL */ url, /* actionURI */ "" );
  
      // Check the response.
      if (resp.generatedFault ()) {
        Fault fault = resp.getFault ();
        System.out.println ("Ouch, the call failed: ");
        System.out.println ("  Fault Code   = " + fault.getFaultCode ());  
        System.out.println ("  Fault String = " + fault.getFaultString ());
      } else {
        Parameter result = resp.getReturnValue ();
        System.out.println ( "Done" );
      }
    }
  }
  
  
  
  1.1                  xml-soap/java/samples/ejb/hellobean.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-soap/java/src/org/apache/soap/providers/JavaProvider.java
  
  Index: JavaProvider.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.providers ;
  
  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.server.http.* ;
  import org.apache.soap.util.* ;
  
  public class JavaProvider implements Provider {
      private DeploymentDescriptor dd ;
      private Call                 call ;
      private String               targetObjectURI ;
      private HttpServlet          servlet ;
      private HttpSession          session ;
  
      private Object               targetObject ;
  
      public void locate( DeploymentDescriptor dd, 
                          Call call, 
                          String targetObjectURI, 
  			HttpServlet servlet,
  			HttpSession session)
  	throws SOAPException {
        this.dd              = dd ;
        this.call            = call ;
        this.targetObjectURI = targetObjectURI ;
        this.servlet         = servlet ;
        this.session         = session ;
  
        ServletConfig  config  = servlet.getServletConfig();
        ServletContext context = config.getServletContext ();
        ServiceManager serviceManager =
          ServerHTTPUtils.getServiceManagerFromContext (context);
  
        // Default processing for 'java' and 'script' providers
        // call on a valid method name?
        if (!RPCRouter.validCall (dd, call)) {
          throw new SOAPException (Constants.FAULT_CODE_SERVER,
                                   "Method '" + call.getMethodName () +
                                   "' is not supported.");
        }
        
        // get at the target object
        targetObject = ServerHTTPUtils.getTargetObject (serviceManager,
                                                        dd, targetObjectURI,
                                                        servlet, session,
                                                        context);
      };
  
  
      public Response invoke() throws SOAPException {
        // invoke the method on the target object
        return RPCRouter.invoke( dd, call, targetObject );
      };
  };
  
  
  
  1.1                  xml-soap/java/src/org/apache/soap/providers/StatelessEJBProvider.java
  
  Index: StatelessEJBProvider.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.providers;
  
  import java.io.* ;
  import java.util.* ;
  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.* ;
  
  import java.lang.reflect.*;
  import javax.rmi.*;
  import javax.ejb.*;
  import javax.naming.*;
  import javax.naming.Context.*;
  
  public class StatelessEJBProvider implements org.apache.soap.util.Provider {
  
  	private DeploymentDescriptor dd ;
  	private Call                 call ;
  	private String               targetObjectURI ;
  	private HttpServlet          servlet ;
  	private HttpSession          session ;
  
  	private javax.naming.Context contxt = null;
  	private EJBObject remoteObjRef = null;
  	public static java.lang.String CNTXT_PROVIDER_URL = "iiop://localhost:900";
  	public static java.lang.String CNTXT_FACTORY_NAME = "com.ibm.ejs.ns.jndi.CNInitialContextFactory";
  	private java.lang.String methodName = null;
  	private Vector methodParameters = null;
  	private String respEncStyle = null;	
  /**
   * StatelessEJBProvider constructor comment.
   */
  public StatelessEJBProvider() {
  	super();
  }
  
  private void initialize() throws SOAPException {
  
  	if(contxt == null) {
  			
  		java.util.Properties properties = new java.util.Properties(); 
  		properties.put(javax.naming.Context.PROVIDER_URL, CNTXT_PROVIDER_URL);
  		properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, CNTXT_FACTORY_NAME);
  		try {
  			contxt = new javax.naming.InitialContext(properties);
  		} catch (NamingException ne) {
  			// ErrorListener?
  			System.out.println("Naming Exception caught during InitialContext creation @ " + CNTXT_PROVIDER_URL);
  			throw new SOAPException(Constants.FAULT_CODE_SERVER, "Unable to initialize context" );		
  		}
  	}
  		
  }
  
  private void initialize(String url, String factory) throws SOAPException {
  
  	if(contxt == null) {
  			
  		java.util.Properties properties = new java.util.Properties();
  
  		properties.put(javax.naming.Context.PROVIDER_URL, url);
  		properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, factory);
  
  		try {
  			contxt = new javax.naming.InitialContext(properties);
  		} catch (NamingException ne) {
  			// ErrorListener?
  			System.out.println("Naming Exception caught during InitialContext creation @ " + CNTXT_PROVIDER_URL);
  			throw new SOAPException(Constants.FAULT_CODE_SERVER, "Unable to initialize context");		
  		}
  	}
  		
  }
  
  
  /**
   * invoke method comment.
   */
  public org.apache.soap.rpc.Response invoke() throws org.apache.soap.SOAPException {
  		  System.err.println( "=============================================" );
  	  System.err.println("In TemplateProvider.invoke()" );
  
  	Parameter ret = null; 
  	Object[] args = null;
  	Class[] argTypes = null;
  	if (methodParameters != null) {
  		int parametersCount = methodParameters.size ();
  		args = new Object[parametersCount];
  		argTypes = new Class[parametersCount];
  		
  		for (int i = 0; i < parametersCount; i++) {
  			Parameter param = (Parameter) methodParameters.elementAt (i);
  			args[i] = param.getValue ();
  			argTypes[i] = param.getType ();
  			
  			if (respEncStyle == null) {
  				respEncStyle = param.getEncodingStyleURI ();
  			}
  	  	}
  	}
  	
  	if (respEncStyle == null) {
  	  respEncStyle = Constants.NS_URI_SOAP_ENC;
  	}
  
  	try {
  
  		Method m = MethodUtils.getMethod (remoteObjRef, methodName, argTypes);
  		Bean result = new Bean (m.getReturnType (), m.invoke (remoteObjRef, args));
  		
  
  		if (result.type != void.class) {
  		  ret = new Parameter (RPCConstants.ELEM_RETURN, result.type, 
  						   result.value, null);
  		}
  
  
  	} catch (InvocationTargetException e) {
  		System.err.println("Exception Caught upon method invocation attempt: " + e.getMessage());
  		Throwable t = e.getTargetException ();
  	  throw new SOAPException (Constants.FAULT_CODE_SERVER, t.getMessage(), t);
  	}
  	 catch (Throwable t) {
  		System.err.println("Exception Caught upon method invocation attempt: " + t.toString());
  		throw new SOAPException (Constants.FAULT_CODE_SERVER, t.getMessage(), t);
  	}
  		
  
  	  return new Response( targetObjectURI,            // URI
  						   call.getMethodName(),       // Method
  			   (Parameter) ret,           // ReturnValue
  						   null,                       // Params
  			   null,                       // Header
  			   call.getEncodingStyleURI ());                     // encoding
  }
  
  /**
   * locate method comment.
   */
  public void locate(org.apache.soap.server.DeploymentDescriptor dd, org.apache.soap.rpc.Call call, String targetObjectURI, javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpSession session) throws org.apache.soap.SOAPException {
  	
  
  	  System.err.println( "=============================================" );
  	  System.err.println( "In TemplateProvider.locate()" );
  	  System.err.println( "URI: " + targetObjectURI );
  	  System.err.println( "DD.ServiceClass: " + dd.getServiceClass() );
  	  System.err.println( "DD.ProviderClass: " + dd.getProviderClass() );
  	  System.err.println( "Call.MethodName: " + call.getMethodName() );
  
  	  this.dd              = dd ;
  	  this.call            = call ;
  	  this.targetObjectURI = targetObjectURI ;
  	  this.servlet         = servlet ;
  	  this.session         = session ;
  
  	  Hashtable props = dd.getProps();
  
  	
  	String ContxtProviderURL = (String) props.get("ContextProviderURL");
  	String ContxtFactoryName = (String) props.get("FullContextFactoryName");
  	
  	if ((ContxtProviderURL != null) && (ContxtFactoryName != null))
  		initialize(ContxtProviderURL, ContxtFactoryName);
  	else
  		initialize();
  		
  	String homeInterfaceName = (String) props.get("FullHomeInterfaceName");
  	if (homeInterfaceName == null) 
  		throw new SOAPException(Constants.FAULT_CODE_SERVER, "Error in Deployment Descriptor Property Settings");		
  			
  	// From the Deployment Descriptor get the JNDI lookup name that is inside the "java" element...
  	String jndiName = dd.getProviderClass();
  	
  
  	if ((jndiName != null) && (contxt != null)) {
  
  		try {
  
  			// Use service name to locate EJB home object via the contxt
  			// EJBHome home = (EJBHome) contxt.lookup(jndiName);
  			EJBHome home = (EJBHome) PortableRemoteObject.narrow(contxt.lookup(jndiName), Class.forName(homeInterfaceName));
  			// call the 'create' method on the EJB home object, and store the
  			//   ref to the EJB object.
  			Method createMethod = home.getClass().getMethod("create", new Class[0]);
  			remoteObjRef = (EJBObject) createMethod.invoke((Object) home, new Object[0]);
  
  		} catch (Exception e) {
  
  			System.out.println("Exception caught: " + e.toString());
  			throw new SOAPException(Constants.FAULT_CODE_SERVER,"Error in connecting to EJB", e);
  		}
  	}
  
  	// Once previous steps have been successful, then we take the Call Object
  	//  and extract the method name from it, and any parameters, and store them.
  	methodName = call.getMethodName();
  	methodParameters = call.getParams();
  
  
  }
  }
  
  
  
  1.1                  xml-soap/java/src/org/apache/soap/providers/TemplateProvider.java
  
  Index: TemplateProvider.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.providers ;
  
  import java.io.* ;
  import java.util.* ;
  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.* ;
  
  public class TemplateProvider implements Provider {
      private DeploymentDescriptor dd ;
      private Call                 call ;
      private String               targetObjectURI ;
      private HttpServlet          servlet ;
      private HttpSession          session ;
  
      public void locate( DeploymentDescriptor dd, 
                          Call call, 
                          String targetObjectURI, 
  			HttpServlet servlet,
  			HttpSession session)
  	throws SOAPException {
        System.err.println( "=============================================" );
        System.err.println( "In TemplateProvider.locate()" );
        System.err.println( "URI: " + targetObjectURI );
        System.err.println( "DD.ServiceClass: " + dd.getServiceClass() );
        System.err.println( "DD.ProviderClass: " + dd.getProviderClass() );
        System.err.println( "Call.MethodName: " + call.getMethodName() );
  
        Hashtable    props = dd.getProps();
        Enumeration  keys  = props.keys();
  
        System.err.println( "Options:" );
        while ( keys.hasMoreElements() ) {
            String  key   = (String) keys.nextElement();
  	  String  value = (String) props.get( key );
  	  System.err.println( "Key: " + key + "  Value: " + value );
        }
  
        this.dd              = dd ;
        this.call            = call ;
        this.targetObjectURI = targetObjectURI ;
        this.servlet         = servlet ;
        this.session         = session ;
  
        // Add logic to locate/load the service here
      };
  
  
      public Response invoke() throws SOAPException {
        System.err.println( "=============================================" );
        System.err.println("In TemplateProvider.invoke()" );
        
        // Add logic to invoke the service and get back the result here
  
        return new Response( targetObjectURI,            // URI
                             call.getMethodName(),       // Method
  			   (Parameter) null,           // ReturnValue
                             null,                       // Params
  			   null,                       // Header
  			   null );                     // encoding
      };
  };
  
  
  
  1.5       +20 -5     xml-soap/java/src/org/apache/soap/rpc/RPCMessage.java
  
  Index: RPCMessage.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/rpc/RPCMessage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RPCMessage.java	2000/09/01 03:52:50	1.4
  +++ RPCMessage.java	2000/11/07 00:34:59	1.5
  @@ -65,6 +65,7 @@
   import org.apache.soap.*;
   import org.apache.soap.encoding.*;
   import org.apache.soap.server.*;
  +import org.apache.soap.server.http.ServerHTTPUtils;
   
   /**
    * An <code>RPCMessage</code> is the base class that <code>Call</code> and
  @@ -77,6 +78,7 @@
   public class RPCMessage implements Serializer
   {
     protected String targetObjectURI;
  +  protected String fullTargetObjectURI;
     protected String methodName;
     protected Vector params;
     protected Header header;
  @@ -85,7 +87,7 @@
     protected RPCMessage(String targetObjectURI, String methodName,
                          Vector params, Header header, String encodingStyleURI)
     {
  -    this.targetObjectURI  = targetObjectURI;
  +    setTargetObjectURI(targetObjectURI);
       this.methodName       = methodName;
       this.params           = params;
       this.header           = header;
  @@ -94,7 +96,12 @@
   
     public void setTargetObjectURI(String targetObjectURI)
     {
  -    this.targetObjectURI = targetObjectURI;
  +    // Any incoming URI must be the full URI
  +    this.fullTargetObjectURI = targetObjectURI;
  +
  +    // Now, we should splice the URI into the actual resource to connect to,
  +    // and the key.
  +    this.targetObjectURI = ServerHTTPUtils.parseFullTargetObjectURI(targetObjectURI);
     }
   
     public String getTargetObjectURI()
  @@ -102,6 +109,11 @@
       return targetObjectURI;
     }
   
  +  public String getFullTargetObjectURI()
  +  {
  +    return fullTargetObjectURI;
  +  }
  +
     public void setMethodName(String methodName)
     {
       this.methodName = methodName;
  @@ -204,7 +216,7 @@
   
       RPCMessage msg               = (RPCMessage)src;
       boolean    isResponse        = (javaType == Response.class);
  -    String     targetObjectURI   = Utils.cleanString(msg.getTargetObjectURI());
  +    String     targetObjectURI   = Utils.cleanString(msg.getFullTargetObjectURI());
       String     methodName        = msg.getMethodName();
       Vector     params            = msg.getParams();
       String     suffix            = isResponse
  @@ -348,6 +360,7 @@
       SOAPMappingRegistry smr       = null;
       Element   root                = (Element)src;
       boolean   isResponse          = (toClass == Response.class);
  +    String    fullTargetObjectURI = null;
       String    targetObjectURI     = null;
       String    methodName          = null;
       Parameter returnValue         = null;
  @@ -369,7 +382,9 @@
         // Must be a method call or a faultless response.
         String tagName = root.getLocalName();
   
  -      targetObjectURI = root.getNamespaceURI();
  +      // This is the 'full' URI.
  +      fullTargetObjectURI = root.getNamespaceURI();
  +      targetObjectURI = ServerHTTPUtils.parseFullTargetObjectURI(fullTargetObjectURI);
   
         // Determine the XML serialization registry based on whether
         // I'm on the server side or on the client side.
  @@ -481,7 +496,7 @@
                           : (RPCMessage)new Response(targetObjectURI, methodName,
                                                      fault, params, null,
                                                      declMsgEncStyle))
  -                     : (RPCMessage)new Call(targetObjectURI, methodName,
  +                     : (RPCMessage)new Call(fullTargetObjectURI, methodName,
                                               params, null, declMsgEncStyle);
   
       if (msg instanceof Call)
  
  
  
  1.11      +102 -8    xml-soap/java/src/org/apache/soap/server/DeploymentDescriptor.java
  
  Index: DeploymentDescriptor.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/DeploymentDescriptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DeploymentDescriptor.java	2000/10/17 12:03:41	1.10
  +++ DeploymentDescriptor.java	2000/11/07 00:34:59	1.11
  @@ -83,12 +83,17 @@
     public static final byte PROVIDER_JAVA = (byte) 0;
     public static final byte PROVIDER_SCRIPT_FILE = (byte) 1;
     public static final byte PROVIDER_SCRIPT_STRING = (byte) 2;
  +  public static final byte PROVIDER_USER_DEFINED = (byte) 3;
   
     protected String id;
     protected int serviceType = SERVICE_TYPE_RPC;
     protected int scope;
     protected byte providerType = -1;
     protected String providerClass;
  +
  +  protected String serviceClass;     // For user-defined providers
  +  protected Hashtable  props ;
  +
     protected boolean isStatic;
     protected String scriptFilenameOrString;
     protected String scriptLanguage;
  @@ -177,6 +182,25 @@
     }
   
     /**
  +   * Classname used to load provider/service
  +   */
  +  public void setServiceClass (String serviceClass) {
  +    this.serviceClass = serviceClass;
  +  }
  +
  +  public String getServiceClass () {
  +    return serviceClass;
  +  }
  +
  +  public Hashtable getProps() {
  +    return props ;
  +  }
  +
  +  public void setProps(Hashtable props) {
  +    this.props = props ;
  +  }
  +
  +  /**
      * For Java providers, the class providing the service.
      */
     public void setProviderClass (String providerClass) {
  @@ -280,8 +304,16 @@
   
       byte pt = providerType;
       String[] scopes = {"Request", "Session", "Application"};
  -    pw.print ("  <isd:provider type=\"" + 
  -              (pt == DeploymentDescriptor.PROVIDER_JAVA ? "java" : "script") +
  +    String   providerString = null ;
  +
  +    if ( pt == DeploymentDescriptor.PROVIDER_JAVA ) 
  +      providerString = "java" ;
  +    else  if ( pt == DeploymentDescriptor.PROVIDER_USER_DEFINED )
  +      providerString = serviceClass ;
  +    else
  +      providerString = "script" ;
  +
  +    pw.print ("  <isd:provider type=\"" + providerString + 
                 "\" scope=\"" + scopes[scope] + "\" methods=\"");
       for (int i = 0; i < methods.length; i++) {
         pw.print (methods[i]);
  @@ -293,7 +325,8 @@
       if (pt == DeploymentDescriptor.PROVIDER_JAVA) {
         pw.println ("    <isd:java class=\"" + providerClass +
                     "\" static=\"" + (isStatic ? "true" : "false") + "\"/>");
  -    } else {
  +    } else if (pt == DeploymentDescriptor.PROVIDER_SCRIPT_FILE ||
  +               pt == DeploymentDescriptor.PROVIDER_SCRIPT_STRING ) {
         pw.print ("    <isd:script language=\"" + scriptLanguage);
         if (pt == DeploymentDescriptor.PROVIDER_SCRIPT_FILE) {
           pw.println (" source=\"" + scriptFilenameOrString + "\"/>");
  @@ -305,6 +338,10 @@
           pw.println ("    </isd:script>");
         }
       }
  +    else if ( pt == DeploymentDescriptor.PROVIDER_USER_DEFINED ) {
  +      pw.println ("    <isd:" + serviceClass + " class=\"" + providerClass +
  +                  "\" static=\"" + (isStatic ? "true" : "false") + "\"/>");
  +    }
       pw.println ("  </isd:provider>");
   
   	if (faultListener != null) {
  @@ -392,7 +429,7 @@
       String scopeStr = DOMUtils.getAttribute (e, "scope");
       String methodsStr = DOMUtils.getAttribute (e, "methods");
       if ((typeStr == null) ||
  -        (!typeStr.equals ("java") && !typeStr.equals ("script")) ||
  +        // (!typeStr.equals ("java") && !typeStr.equals ("script")) ||
           (scopeStr == null) ||
           (!scopeStr.equals ("Request") &&
            !scopeStr.equals ("Session") && !scopeStr.equals ("Application")) ||
  @@ -436,7 +473,7 @@
         }
         dd.setIsStatic (isStaticBool);
   
  -    } else {
  +    } else if (typeStr.equals ("script")) {
         nl = e.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
                                        "script");
         if ((nl == null) || nl.getLength () != 1) {
  @@ -454,6 +491,63 @@
           dd.setProviderType (DeploymentDescriptor.PROVIDER_SCRIPT_STRING);
           dd.setScriptFilenameOrString (DOMUtils.getChildCharacterData (e));
         }
  +    } else {
  +      // "type" element isn't one of the predefined ones so assume it's the
  +      // class name of a specific provider loader
  +      dd.setProviderType (DeploymentDescriptor.PROVIDER_USER_DEFINED);
  +      dd.setServiceClass (typeStr);
  +
  +      Element saved_E = e ;
  +      nl = e.getElementsByTagNameNS(Constants.NS_URI_XML_SOAP_DEPLOYMENT, 
  +                                    "option" );
  +      for ( int i = 0 ; nl != null && i < nl.getLength() ; i++ ) {
  +        String  key, value ;
  +
  +        e = (Element) nl.item(i);
  +        key   = DOMUtils.getAttribute( e, "key" );
  +        value = DOMUtils.getAttribute( e, "value" );
  +
  +        if ( key == null || key.equals("") )
  +	  throw new IllegalArgumentException("Missing 'key' attribute on " +
  +	                                     "'option' element in deployment " +
  +					     "desriptor" );
  +	if ( dd.props == null ) dd.props = new Hashtable();
  +	dd.props.put( key, value );
  +      }
  +
  +      // Support old 'java' tag
  +      e = saved_E ;
  +      nl = e.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
  +                                     "java");
  +      if ( nl != null ) {
  +        if ( nl.getLength () != 1) {
  +          throw new IllegalArgumentException ("exactly one 'java' element " +
  +                                              "missing in deployment " +
  +                                              "descriptor");
  +        }
  +        e = (Element) nl.item (0);
  +        String className = DOMUtils.getAttribute (e, "class");
  +        if (className == null) {
  +          throw new IllegalArgumentException ("<java> element requires " +
  +                                              "'class' attribute");
  +        }
  +        dd.setProviderClass (className);
  +        String isStatic = DOMUtils.getAttribute (e, "static");
  +        boolean isStaticBool = false;
  +        if (isStatic != null) {
  +          if (isStatic.equals ("false")) {
  +            isStaticBool = false;
  +          } else if (isStatic.equals ("true")) {
  +            isStaticBool = true;
  +          } else {
  +            throw new IllegalArgumentException ("'static' attribute of " +
  +                                                "<java> element must be " +
  +                                                "true or false");
  +          }
  +        }
  +        dd.setIsStatic (isStaticBool);
  +        // End of old 'java' tag
  +      }
       }
   
       if (scopeStr.equals ("Request")) {
  @@ -552,10 +646,10 @@
         body = "class='" + providerClass + "', static='" + isStatic + "', ";
       } else if (providerType == PROVIDER_SCRIPT_FILE) {
         body = "source='" + scriptFilenameOrString + "', ";
  -      body += "language='" + scriptLanguage + "', ";
  -    } else {
  -      body = "script='" + scriptFilenameOrString + "', ";
         body += "language='" + scriptLanguage + "', ";
  +    } else if (providerType == PROVIDER_USER_DEFINED) {
  +      body = "type='" + serviceClass + "', class='" + providerClass ;
  +      body += "', static='" + isStatic + "', ";
       }
   
   	StringBuffer lis = new StringBuffer("[");
  
  
  
  1.4       +3 -1      xml-soap/java/src/org/apache/soap/server/RPCRouter.java
  
  Index: RPCRouter.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/RPCRouter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RPCRouter.java	2000/09/01 03:52:52	1.3
  +++ RPCRouter.java	2000/11/07 00:34:59	1.4
  @@ -10,6 +10,8 @@
   import org.apache.soap.*;
   import org.apache.soap.rpc.*;
   
  +import org.apache.soap.server.http.ServerHTTPUtils;
  +
   /**
    * This class is a transport independent SOAP RPC router. However you
    * do it, if you get a SOAP envelope to me, I will build a Call object
  @@ -25,7 +27,7 @@
       // determine target object URI by looking in the envelope
       Vector bodyEntries = callEnv.getBody ().getBodyEntries ();
       Element mainEntry = (Element) bodyEntries.elementAt (0);
  -    String targetObjectURI = mainEntry.getNamespaceURI ();
  +    String targetObjectURI = ServerHTTPUtils.parseFullTargetObjectURI(mainEntry.getNamespaceURI ());
       
       // call on known entity?
       DeploymentDescriptor dd = serviceManager.query (targetObjectURI);
  
  
  
  1.7       +23 -13    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RPCRouterServlet.java	2000/10/17 12:03:41	1.6
  +++ RPCRouterServlet.java	2000/11/07 00:35:00	1.7
  @@ -106,6 +106,7 @@
       Call call = null;
       Response resp = null;
       String targetID = null;
  +    String fullTargetID = null ;
       int status = res.SC_OK;
       DeploymentDescriptor dd = null;
   
  @@ -116,6 +117,7 @@
           Envelope callEnv = ServerHTTPUtils.readEnvelopeFromRequest (req, res);
           call = RPCRouter.extractCallFromEnvelope (serviceManager, callEnv);
           targetID = call.getTargetObjectURI ();
  +	fullTargetID = call.getFullTargetObjectURI ();
         } catch (IllegalArgumentException e) {
           String msg = e.getMessage ();
           String faultCode =
  @@ -129,21 +131,29 @@
         // not known)
         dd = serviceManager.query (targetID);
   
  -      // call on a valid method name?
  -      if (!RPCRouter.validCall (dd, call)) {
  -        throw new SOAPException (Constants.FAULT_CODE_SERVER,
  -                                 "Method '" + call.getMethodName () + 
  -                                 "' is not supported.");
  +      if ( dd.getProviderType() == DeploymentDescriptor.PROVIDER_JAVA ) {
  +        // Handle Java based services
  +	Provider provider = new org.apache.soap.providers.JavaProvider();
  +
  +        provider.locate( dd, call, fullTargetID, this, session );
  +	resp = provider.invoke();
         }
  -      
  -      // get at the target object
  -      Object targetObject = ServerHTTPUtils.getTargetObject (serviceManager,
  -                                                             dd, targetID,
  -                                                             this, session,
  -                                                             context);
  -      // invoke the method on the target object
  -      resp = RPCRouter.invoke (dd, call, targetObject);
  +      else if (dd.getProviderType() == DeploymentDescriptor.PROVIDER_USER_DEFINED) {
  +        // Handle user-defined providers
  +	Provider provider = ServerHTTPUtils.loadProvider(dd);
  +
  +        provider.locate( dd, call, fullTargetID, this, session );
  +	resp = provider.invoke();
  +      }
  +      else {
  +        // Handle scripts
  +	Provider provider = new org.apache.soap.providers.JavaProvider();
  +
  +        provider.locate( dd, call, fullTargetID, this, session );
  +	resp = provider.invoke();
  +      }
       } catch (Throwable t) {
  +    System.err.println( "\nERR1: " + t.toString() + "\n" );
         // note that we catch runtime errors too with the above .. the
         // idea is to do a SOAP fault for everything that goes out so
         // that if the recepient is expecting to read some XML they'll
  
  
  
  1.5       +180 -121  xml-soap/java/src/org/apache/soap/server/http/ServerHTTPUtils.java
  
  Index: ServerHTTPUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/ServerHTTPUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServerHTTPUtils.java	2000/10/23 19:09:43	1.4
  +++ ServerHTTPUtils.java	2000/11/07 00:35:00	1.5
  @@ -78,6 +78,7 @@
     private static final String SCRIPT_CLASS = "com.ibm.bsf.BSFManager";
     private static final String SCRIPT_INVOKER = 
       "org.apache.soap.server.InvokeBSF";
  +  private static String URI_SEPARATION_CHAR = "@";
   
     /**
      * Look up the service manager or create it from the context. NOTE:
  @@ -162,129 +163,187 @@
      * service, the object's lifecycle is also managed here.
      */
     public static Object getTargetObject (ServiceManager serviceManager,
  -                                 DeploymentDescriptor dd,
  -                                 String targetID,
  -                                 HttpServlet thisServlet,
  -                                 HttpSession session,
  -                                 ServletContext context)
  -       throws SOAPException {
  -    int scope = dd.getScope ();
  -    byte providerType = dd.getProviderType ();
  -    String className;
  -    Object targetObject = null;
  -    if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
  -      className = dd.getProviderClass ();
  -    } else {
  -      // for scripts, we need a new BSF manager basically
  -      className = SCRIPT_CLASS;
  -    }
  -      
  -    // determine the scope and lock object to use to manage the lifecycle
  -    // of the service providing object
  -    Object scopeLock = null;
  -    if (scope == DeploymentDescriptor.SCOPE_REQUEST) {
  -      scopeLock = thisServlet; // no need to register .. create, use and dink
  -    } else if (scope == DeploymentDescriptor.SCOPE_SESSION) {
  -      scopeLock = session;
  -    } else if (scope == DeploymentDescriptor.SCOPE_APPLICATION) {
  -      scopeLock = context;
  -    } else {
  -      throw new SOAPException (Constants.FAULT_CODE_SERVER,
  -                               "Service uses deprecated object scope " +
  -                               "'page': inform provider of error");
  -    }
  +				        DeploymentDescriptor dd,
  +					String targetID,
  +					HttpServlet thisServlet,
  +					HttpSession session,
  +					ServletContext context)
  +	   throws SOAPException {
  +	int scope = dd.getScope ();
  +	byte providerType = dd.getProviderType ();
  +	String className;
  +	Object targetObject = null;
  +	if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
  +	  className = dd.getProviderClass ();
  +	} else if (providerType == DeploymentDescriptor.PROVIDER_SCRIPT_FILE ||
  +	           providerType == DeploymentDescriptor.PROVIDER_SCRIPT_STRING) {
  +	  // for scripts, we need a new BSF manager basically
  +	  className = SCRIPT_CLASS;
  +	} else if (providerType == DeploymentDescriptor.PROVIDER_USER_DEFINED) {
  +	  className = dd.getServiceClass ();
  +	}
  +	else {
  +	  throw new SOAPException(Constants.FAULT_CODE_SERVER,
  +	                          "SOAP error: bad providerType in getTargetObject");
  +	}
  +	  
  +	// determine the scope and lock object to use to manage the lifecycle
  +	// of the service providing object
  +	Object scopeLock = null;
  +	if (scope == DeploymentDescriptor.SCOPE_REQUEST) {
  +	  scopeLock = thisServlet; // no need to register .. create, use and dink
  +	} else if (scope == DeploymentDescriptor.SCOPE_SESSION) {
  +	  scopeLock = session;
  +	} else if (scope == DeploymentDescriptor.SCOPE_APPLICATION) {
  +	  scopeLock = context;
  +	} else {
  +	  throw new SOAPException (Constants.FAULT_CODE_SERVER,
  +				   "Service uses deprecated object scope " +
  +				   "'page': inform provider of error");
  +	}
   
  -    // create the object if necessary
  -    boolean freshObject = false;
  -    
  -    // find the target object on which the requested method should
  -    // be invoked
  -    if (targetID.equals (ServerConstants.SERVICE_MANAGER_SERVICE_NAME)) {
  -      targetObject = serviceManager;
  -    } else {
  -      // locate (or create) the target object and invoke the method
  -      synchronized (scopeLock) {
  -        if (scopeLock == session) {
  -          targetObject = session.getAttribute (targetID);
  -        } else if (scopeLock == context) {
  -          targetObject = context.getAttribute (targetID);
  -        } else {
  -          targetObject = null;
  -        }
  -        if (targetObject == null) {
  -          try {
  -            Class c = Class.forName (className);
  -            if (dd.getIsStatic ()) {
  -              targetObject = c;
  -            } else {
  -              targetObject = c.newInstance ();
  -            }
  -            freshObject = true;
  -          } catch (Exception e) {
  -            String msg;
  -            if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
  -              msg = "Unable to resolve target object: " + e.getMessage ();
  -            } else {
  -              msg = "Unable to load BSF: script services not available " +
  -                "without BSF: " + e.getMessage ();
  -            }
  -            throw new SOAPException (
  -              Constants.FAULT_CODE_SERVER_BAD_TARGET_OBJECT_URI, msg, e);
  -          }
  -        }
  -        // remember the created instance if the scope is not REQUEST;
  -        // in that case the object is to be thrown away after handling
  -        // the request
  -        if (scopeLock == session) {
  -          session.setAttribute (targetID, targetObject);
  -        } else if (scopeLock == context) {
  -          context.setAttribute (targetID, targetObject);
  -        }
  -      }
  -    }
  -      
  -    // if script provider type and first time to it, then load and
  -    // exec the script
  -    if (providerType != DeploymentDescriptor.PROVIDER_JAVA &&
  -        freshObject) {
  -      // find the class that provides the BSF services (done
  -      // this way via reflection to avoid a static dependency on BSF)
  -      Class bc = null;
  -      try {
  -        bc = Class.forName (SCRIPT_INVOKER);
  -      } catch (Exception e) {
  -        String msg = "Unable to load BSF invoker (" + SCRIPT_INVOKER + ")" +
  -          ": script services not available without BSF: " + e.getMessage ();
  -        throw new SOAPException (Constants.FAULT_CODE_SERVER, msg, e);
  -      }
  -      
  -        // get the script string to exec
  -      String script = dd.getScriptFilenameOrString ();
  -      if (providerType == DeploymentDescriptor.PROVIDER_SCRIPT_FILE) {
  -        String fileName = context.getRealPath (script);
  -        try {
  -          script = IOUtils.getStringFromReader (new FileReader (fileName));
  -        } catch (Exception e) {
  -          String msg = "Unable to load script file (" + fileName + ")" +
  -            ": " + e.getMessage ();
  -          throw new SOAPException (Constants.FAULT_CODE_SERVER, msg, e);
  -        }
  -      }
  -      
  -      // exec it
  -      Class[] sig = {DeploymentDescriptor.class,
  -                     Object.class,
  -                     String.class};
  -      try {
  -        Method m = MethodUtils.getMethod (bc, "init", sig, true);
  -        m.invoke (null, new Object[] {dd, targetObject, script});
  -      } catch (Exception e) {
  -        String msg = "Unable to invoke init method of script invoker: " +
  -          "something is wrong (shouldn't happen)";
  -        throw new SOAPException (Constants.FAULT_CODE_SERVER, msg, e);
  -      }
  +	// create the object if necessary
  +	boolean freshObject = false;
  +	
  +	// find the target object on which the requested method should
  +	// be invoked
  +	if (targetID.equals (ServerConstants.SERVICE_MANAGER_SERVICE_NAME)) {
  +	  targetObject = serviceManager;
  +	} else {
  +	  // locate (or create) the target object and invoke the method
  +	  synchronized (scopeLock) {
  +		if (scopeLock == session) {
  +		  targetObject = session.getAttribute (targetID);
  +		} else if (scopeLock == context) {
  +		  targetObject = context.getAttribute (targetID);
  +		} else {
  +		  targetObject = null;
  +		}
  +		if (targetObject == null) {
  +		  try {
  +			Class c = Class.forName (className);
  +			if (dd.getIsStatic ()) {
  +			  targetObject = c;
  +			} else {
  +			  targetObject = c.newInstance ();
  +			}
  +			freshObject = true;
  +		  } catch (Exception e) {
  +			String msg = "" ;
  +			if (providerType == DeploymentDescriptor.PROVIDER_JAVA) {
  +			  msg = "Unable to resolve target object(" + className + 
  +			        "): " + e.getMessage ();
  +			} else if (providerType == DeploymentDescriptor.PROVIDER_SCRIPT_FILE ||
  +			           providerType == DeploymentDescriptor.PROVIDER_SCRIPT_STRING) {
  +			  msg = "Unable to load BSF: script services not available " +
  +				"without BSF: " + e.getMessage ();
  +			}
  +			else if (providerType == DeploymentDescriptor.PROVIDER_USER_DEFINED) {
  +			  msg = "Unable to resolve service class(" + className + 
  +			        "): " + e.getMessage ();
  +			}
  +			throw new SOAPException (
  +			  Constants.FAULT_CODE_SERVER_BAD_TARGET_OBJECT_URI, msg, e);
  +		  }
  +		}
  +		// remember the created instance if the scope is not REQUEST;
  +		// in that case the object is to be thrown away after handling
  +		// the request
  +		if (scopeLock == session) {
  +		  session.setAttribute (targetID, targetObject);
  +		} else if (scopeLock == context) {
  +		  context.setAttribute (targetID, targetObject);
  +		}
  +	  }
  +	}
  +	  
  +	// if script provider type and first time to it, then load and
  +	// exec the script
  +	if ( (providerType == DeploymentDescriptor.PROVIDER_SCRIPT_FILE || 
  +	      providerType == DeploymentDescriptor.PROVIDER_SCRIPT_STRING)
  +	     && freshObject) {
  +	  // find the class that provides the BSF services (done
  +	  // this way via reflection to avoid a static dependency on BSF)
  +	  Class bc = null;
  +	  try {
  +		bc = Class.forName (SCRIPT_INVOKER);
  +	  } catch (Exception e) {
  +		String msg = "Unable to load BSF invoker (" + SCRIPT_INVOKER + ")" +
  +		  ": script services not available without BSF: " + e.getMessage ();
  +		throw new SOAPException (Constants.FAULT_CODE_SERVER, msg, e);
  +	  }
  +	  
  +		// get the script string to exec
  +	  String script = dd.getScriptFilenameOrString ();
  +	  if (providerType == DeploymentDescriptor.PROVIDER_SCRIPT_FILE) {
  +		String fileName = context.getRealPath (script);
  +		try {
  +		  script = IOUtils.getStringFromReader (new FileReader (fileName));
  +		} catch (Exception e) {
  +		  String msg = "Unable to load script file (" + fileName + ")" +
  +			": " + e.getMessage ();
  +		  throw new SOAPException (Constants.FAULT_CODE_SERVER, msg, e);
  +		}
  +	  }
  +	  
  +	  // exec it
  +	  Class[] sig = {DeploymentDescriptor.class,
  +					 Object.class,
  +					 String.class};
  +	  try {
  +		Method m = MethodUtils.getMethod (bc, "init", sig, true);
  +		m.invoke (null, new Object[] {dd, targetObject, script});
  +	  } catch (Exception e) {
  +		String msg = "Unable to invoke init method of script invoker: " +
  +		  "something is wrong (shouldn't happen)";
  +		throw new SOAPException (Constants.FAULT_CODE_SERVER, msg, e);
  +	  }
  +	}
  +
  +	return targetObject;
  +  }  
  +  /**
  +  * gegi: This method will perform the splicing of a full URI. It is currently 
  +  *  the only place where the delimiting character in the URI that triggers the 
  +  *  splicing operation is specified. (This character should later be specified
  +  *  as a constant...
  +  *
  +  * Creation date: (10/23/00 2:54:33 PM)
  +  * @return java.lang.String
  +  * @param fullTargetObjectURI java.lang.String
  +  */
  +  public static String parseFullTargetObjectURI(String fullTargetObjectURI) {
  +         if ( fullTargetObjectURI == null ) return null ;
  +	 int delimIndex = fullTargetObjectURI.indexOf(ServerHTTPUtils.URI_SEPARATION_CHAR);
  +	 if ( (fullTargetObjectURI != null) && (delimIndex != -1) )
  +		 return fullTargetObjectURI.substring(0,delimIndex);
  +	 else
  +		 return fullTargetObjectURI;
  + 	
  +  }
  + 
  +  public static Provider loadProvider(DeploymentDescriptor dd) 
  +           throws SOAPException {
  +    String  className ;
  +    Class   c ;
  +    Object  newObj ;
  + 
  +    className = dd.getServiceClass();
  +    if ( className == null ) return null ;
  + 
  +    try {
  +      c = Class.forName (className);
  +      newObj = c.newInstance();
  +    } catch( Exception exp ) {
  +      throw new SOAPException( Constants.FAULT_CODE_SERVER, 
  +                               "Can't load provider '" + className + "'", exp);
       }
   
  -    return targetObject;
  +    if ( !(newObj instanceof Provider) ) {
  +      System.err.println("NOT PROVIDER");
  +      return null ;
  +    }
  + 
  +    return (Provider) newObj ;
     }
   }
  
  
  
  1.1                  xml-soap/java/src/org/apache/soap/util/Provider.java
  
  Index: Provider.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 javax.servlet.* ;
  import javax.servlet.http.* ;
  import org.apache.soap.* ;
  import org.apache.soap.rpc.* ;
  import org.apache.soap.server.* ;
  
  /**
   * A <code>Provider</code> ...
   *
   * @author Dug (dug@us.ibm.com)
   *
   * A provider's function is split into two pieces, locating the
   * service (which also includes any verification that the service can
   * be execute at all and by the client), and actually running it.
   *
   * Its up to the 'invoke' method to not only call the actual service
   * up to grab and format the repsonse into a SOAP Repsonse object.
   *
   */
  public interface Provider
  {
    public void locate( DeploymentDescriptor dd, 
                        Call                 call,
                        String               targetObjectURI,
  		      HttpServlet          servlet,
  		      HttpSession          session )
                  throws SOAPException ;
    public Response invoke( ) throws SOAPException ;
  }
  
  
  

Mime
View raw message