You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by wc...@locus.apache.org on 2000/11/29 00:03:59 UTC

cvs commit: xml-soap/java/src/org/apache/soap/server/http RPCRouterServlet.java ServerHTTPUtils.java

wcloeten    00/11/28 15:03:59

  Modified:    java/src/org/apache/soap/server/http RPCRouterServlet.java
                        ServerHTTPUtils.java
  Log:
  server-side multipart MIME support
  
  Revision  Changes    Path
  1.10      +74 -103   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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- RPCRouterServlet.java	2000/11/15 13:38:32	1.9
  +++ RPCRouterServlet.java	2000/11/28 23:03:56	1.10
  @@ -54,6 +54,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
   package org.apache.soap.server.http;
   
   import java.io.*;
  @@ -66,6 +67,7 @@
   import org.apache.soap.rpc.*;
   import org.apache.soap.server.*;
   import org.apache.soap.encoding.*;
  +import org.apache.soap.transport.*;
   import org.apache.soap.util.* ;
   import org.apache.soap.util.xml.* ;
   
  @@ -87,6 +89,7 @@
    * @author Steven McDowall <sj...@aptest.com>
    * @author Eric M. Dashofy (edashofy@ics.uci.edu) 
    * @author Kevin J. Mitchell (kevin.mitchell@xmls.com)
  + * @author Wouter Cloetens (wcloeten@raleigh.ibm.com)
    */
   public class RPCRouterServlet extends HttpServlet {
     /*
  @@ -109,16 +112,14 @@
     //    </init-param>
     // </servlet>
     private static final String ENVELOPE_EDITOR_FACTORY =
  -    "EnvelopeEditorFactory";
  +      "EnvelopeEditorFactory";
     private static final String XML_PARSER = "XMLParser";
   
  -  private static final String TRANSPORT_HOOK_EXTENSION =
  -    "org.apache.soap.TransportHookExtension";
  -
     private EnvelopeEditor editor = null;
     private XMLParserLiaison xpl = new XercesParserLiaison();
     public void init() {
  -    if (System.getProperties().getProperty(TRANSPORT_HOOK_EXTENSION) != null) {
  +      if (System.getProperties().
  +          getProperty(Constants.TRANSPORT_HOOK_EXTENSION) != null) {
         EnvelopeEditorFactory factory =
           (EnvelopeEditorFactory)createObject(ENVELOPE_EDITOR_FACTORY);
         if (factory != null) {
  @@ -129,7 +130,7 @@
               String name = (String)enum.nextElement();
               if (!ENVELOPE_EDITOR_FACTORY.equals(name) &&
                   !XML_PARSER.equals(name))
  -              props.setProperty(name, getServletConfig().getInitParameter(name));
  +              props.put(name, getServletConfig().getInitParameter(name));
             }
             editor = factory.create(props);
           } catch (SOAPException e) {
  @@ -170,7 +171,7 @@
     public void doGet (HttpServletRequest req, HttpServletResponse res)
       throws ServletException, IOException {
       PrintWriter out = res.getWriter ();
  -	
  +
       res.setContentType("text/html");
       out.println("<html><head><title>SOAP RPC Router</title></head>");
       out.println ("<body><h1>SOAP RPC Router</h1>");
  @@ -180,33 +181,6 @@
   
     public void doPost (HttpServletRequest req, HttpServletResponse res)
       throws ServletException, IOException {
  -    /*
  -     * Begin Transport-Hook-Extension
  -     */
  -    // Invokes EnvelopeEditor (editIncoming)
  -    Reader in;
  -    int contentLength;
  -    String opt = System.getProperties().getProperty(TRANSPORT_HOOK_EXTENSION) ;
  -    if (opt != null && editor != null) {
  -      try {
  -        StringWriter sout = new StringWriter();
  -        editor.editIncoming(req.getReader(), sout);
  -        String xml = sout.getBuffer().toString();
  -        in = new StringReader(xml);
  -        contentLength = xml.length();
  -      } catch (SOAPException e) {
  -        e.printStackTrace();
  -        // SOAPException must be handled here.
  -        return;
  -      }
  -    } else {
  -      in = req.getReader();
  -      contentLength = req.getContentLength();
  -    }
  -    /*
  -     * End Transport-Hook-Extension
  -     */
  -
       ServletConfig config = getServletConfig();
       ServletContext context = config.getServletContext ();
   
  @@ -220,8 +194,8 @@
       int status = res.SC_OK;
       DeploymentDescriptor dd = null;
   
  +    SOAPContext ctx = new SOAPContext();
       try {
  -
         // extract the call
         try {
           /*
  @@ -234,8 +208,9 @@
           Envelope callEnv =
             ServerHTTPUtils.readEnvelopeFromRequest(xpl,
                                                     req.getContentType(),
  -                                                  contentLength,
  -                                                  in,
  +                                                  req.getContentLength(),
  +                                                  req.getInputStream(),
  +                                                  editor,
                                                     res);
           if (callEnv == null)
             return;
  @@ -253,38 +228,42 @@
             : Constants.FAULT_CODE_CLIENT;
           throw new SOAPException (faultCode, msg, e);
         }
  -      
  +
         // get the deployment descriptor for this service (will except if
         // not known)
         dd = serviceManager.query (targetID);
   
  +      Provider provider;
         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();
  -      } else if (dd.getProviderType() == DeploymentDescriptor.PROVIDER_USER_DEFINED) {
  +        provider = new org.apache.soap.providers.JavaProvider();
  +      } 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();
  +        provider = ServerUtils.loadProvider(dd);
         } else {
           // Handle scripts
  -        Provider provider = new org.apache.soap.providers.JavaProvider();
  -
  -        provider.locate( dd, call, fullTargetID, this, session );
  -        resp = provider.invoke();
  +        provider = new org.apache.soap.providers.JavaProvider();
         }
  +      provider.locate( dd, call, fullTargetID, this, session );
  +
  +      // Build a new context for the response. The call has already been rebuilt
  +      // and its parameters hold references to DataHandlers, so we can discard
  +      // the MimeMultipart and BodyPart objects
  +      ctx.setSOAPContext();
  +
  +      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
         // get it. If not, it doesn't hurt.
         SOAPException e = null;
  -      if (t instanceof SOAPException) e = (SOAPException)	t; else e = new SOAPException(Constants.FAULT_CODE_SERVER + ".Exception:", "", t);
  +      if (t instanceof SOAPException)
  +        e = (SOAPException)	t;
  +      else
  +        e = new SOAPException(Constants.FAULT_CODE_SERVER +
  +                              ".Exception:", "", t);
   
         Fault fault = new Fault (e);
         fault.setFaultActorURI (req.getRequestURI ());
  @@ -295,64 +274,56 @@
         if (fault.getFaultCode().startsWith (Constants.FAULT_CODE_CLIENT)) {
           status = ServerConstants.SC_BAD_REQUEST;
         } else {
  -	      status = res.SC_INTERNAL_SERVER_ERROR;
  +	status = res.SC_INTERNAL_SERVER_ERROR;
         }
   
  -      String respEncStyle = call.getEncodingStyleURI(); 
  -      if(respEncStyle == null) respEncStyle = Constants.NS_URI_SOAP_ENC; 
  +      String respEncStyle = null;
  +      if(call != null)
  +          respEncStyle = call.getEncodingStyleURI();
  +      if(respEncStyle == null)
  +        respEncStyle = Constants.NS_URI_SOAP_ENC;
   
         resp = new Response (null, null, fault, null, null, respEncStyle);
       }
  -  
  -    // create a writer to direct stuff to so that we can set the
  -    // content length
  -    ByteArrayOutputStream bytes = new ByteArrayOutputStream (4096);
  -    OutputStreamWriter osw = new OutputStreamWriter (bytes, "UTF8");
  -    PrintWriter out = new PrintWriter (osw, true);
  -    
  -    // put the response envelope out
  -    try {
  -      Envelope respEnvelope = resp.buildEnvelope ();
  -      SOAPMappingRegistry smr = (call != null
  -                                 ? call.getSOAPMappingRegistry ()
  -                                 : new SOAPMappingRegistry());
  -      
  -      respEnvelope.marshall (out, smr);
  -    } catch (Exception e) {
  -      throw new ServletException ("Error building response envelope", e);
  -    }
   
  -    // close the temporary writer to flush stuff out
  -    out.close ();
  +    try
  +    {
  +        // Generate response.
  +	SOAPMappingRegistry smr = (call != null
  +                                   ? call.getSOAPMappingRegistry ()
  +                                   : new SOAPMappingRegistry());
  +        Envelope env = resp.buildEnvelope();
  +        StringWriter sw = new StringWriter();
  +        env.marshall(sw, smr);
  +        String envelopeString = sw.toString();
  +        TransportMessage sres = new TransportMessage(envelopeString, ctx, null);
  +        sres.editOutgoing(editor);
  +
  +        // Generate response byte array.
  +        sres.save();
  +
  +        // Write.
  +        res.setStatus(status);
  +        res.setContentType(sres.getContentType());
  +        for (Enumeration headers = sres.getHeaderNames();
  +             headers.hasMoreElements(); ) {
  +            String name = (String)headers.nextElement();
  +            res.setHeader(name, sres.getHeader(name));
  +        }
   
  -    /*
  -     * Begin Transport-Hook-Extension
  -     */
  -    // Translates response from server application with EnvelopeEditor
  -    opt = System.getProperties().getProperty(TRANSPORT_HOOK_EXTENSION);
  -    if (opt != null && editor != null) {
  -      byte[] data = bytes.toByteArray();
  -      in = new InputStreamReader(new ByteArrayInputStream(data));
  -      bytes = new ByteArrayOutputStream();
  -      Writer tout = new OutputStreamWriter(bytes);
  -      try {
  -        editor.editOutgoing(in, tout);
  -      } catch (SOAPException e) {
  +        res.setContentLength(sres.getContentLength());
  +        OutputStream outStream = res.getOutputStream();
  +        PrintWriter out = new PrintWriter(
  +                           new OutputStreamWriter (outStream, "UTF8"));
  +        sres.writeTo(outStream);
  +        out.println(StringUtils.lineSeparator);
  +        out.flush();
  +    }
  +    // NOTE: fix this to return server-side SOAP exceptions instead.
  +    catch (Exception e)
  +    {
           e.printStackTrace();
  -        // SOAPException must be handled here.
  -        return;
  -      }
  -      tout.flush();
  -      tout.close();
  +        throw new ServletException ("Error building response envelope: " + e);
       }
  -    /*
  -     * End Transport-Hook-Extension
  -     */
  -
  -    // ship the stuff out
  -    res.setContentType (Constants.HEADERVAL_CONTENT_TYPE_UTF8);
  -    res.setContentLength (bytes.size ());
  -    res.setStatus(status);
  -    bytes.writeTo (res.getOutputStream ());
     }
   }
  
  
  
  1.8       +141 -230  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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ServerHTTPUtils.java	2000/11/08 12:58:24	1.7
  +++ ServerHTTPUtils.java	2000/11/28 23:03:57	1.8
  @@ -61,12 +61,16 @@
   import java.util.*;
   import java.lang.reflect.*;
   import javax.servlet.* ;
  -import javax.servlet.http.* ;
  -import org.w3c.dom.* ;
  +import javax.servlet.http.*;
  +import org.w3c.dom.*;
   import org.apache.soap.*;
   import org.apache.soap.server.*;
  -import org.apache.soap.util.* ;
  -import org.apache.soap.util.xml.* ;
  +import org.apache.soap.util.*;
  +import org.apache.soap.util.xml.*;
  +import javax.activation.*;
  +import javax.mail.*;
  +import javax.mail.internet.*;
  +import org.apache.soap.transport.EnvelopeEditor;
   
   /**
    * Any utility stuff for HTTP SOAP stuff. 
  @@ -110,78 +114,26 @@
      * @exception IOException if something fails while sending an
      *            error response
      */
  -  static Envelope readEnvelopeFromRequest (
  -    /*
  -     * Begin Transport-Hook-Extension
  -     */
  -                                           //HttpServletRequest req,
  -                                           XMLParserLiaison xpl,
  +  static Envelope readEnvelopeFromRequest (XMLParserLiaison xpl,
                                              String contentType,
                                              int contentLength,
  -                                           Reader requestReader,
  -    /*
  -     * End Transport-Hook-Extension
  -     */
  +                                           InputStream requestStream,
  +                                           EnvelopeEditor editor,
                                              HttpServletResponse res) 
          throws SOAPException, IOException {
  -    /*
  -     * Begin Transport-Hook-Extension
  -     */
  -    //String contentType = req.getContentType ();
  -    //int contentLength = req.getContentLength ();
  -    /*
  -     * End Transport-Hook-Extension
  -     */
  -
  -    if ((contentType == null) ||
  -        !contentType.equals (Constants.HEADERVAL_CONTENT_TYPE)) {
  -      res.sendError (res.SC_BAD_REQUEST, "Content type must be: '" + 
  -                     Constants.HEADERVAL_CONTENT_TYPE + "'.");
  -      return null;
  -    } else if (contentLength < 0) {
  -      res.sendError (res.SC_BAD_REQUEST, "Content length must be specified.");
  -      return null;
  -    }
  -
  -    // read the stuff
  -    /*
  -     * Begin Transport-Hook-Extension
  -     */
  -    //Reader requestReader = req.getReader ();
  -    /*
  -     * End Transport-Hook-Extension
  -     */
  -    char[] payload = new char[contentLength];
  -    int    offset = 0;
  -    int    bytesRead = 0;
  -    
  -    // We're done reading when we get all the content OR when the stream
  -    // returns a -1.
  -    while ((offset < contentLength) && (bytesRead >= 0)) {
  -      bytesRead = requestReader.read (payload, offset, contentLength - offset);
  -      offset += bytesRead;
  -    }
  -
  -    // Parse the stuff
  -    /*
  -     * Begin Transport-Hook-Extension
  -     */
  -    //XMLParserLiaison xpl = new XercesParserLiaison ();
  -    /*
  -     * End Transport-Hook-Extension
  -     */
  -    Document doc = xpl.read ("SOAP Envelope", new CharArrayReader (payload));
  -    if (doc == null) {
  -      throw new SOAPException (Constants.FAULT_CODE_CLIENT, "parsing error");
  -    }
  -    
       try {
  -      return Envelope.unmarshall (doc.getDocumentElement ());
  +        return ServerUtils.readEnvelopeFromInputStream (xpl, requestStream,
  +                                                        contentLength,
  +                                                        contentType, editor);
       } catch (IllegalArgumentException e) {
         String msg = e.getMessage ();
         res.sendError (res.SC_BAD_REQUEST, "Error unmarshalling envelope: " +
                        msg);
         return null;
  +    } catch (MessagingException me) {
  +      res.sendError (res.SC_BAD_REQUEST, "Error unmarshalling envelope: " +
  +                     me);
  +      return null;
       }
     }
   
  @@ -191,172 +143,131 @@
      * 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 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(" + 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;
  -  }  
  - 
  -  public static Provider loadProvider(DeploymentDescriptor dd) 
  -           throws SOAPException {
  -    String  className ;
  -    Class   c ;
  -    Object  newObj ;
  - 
  -    className = dd.getServiceClass();
  -    if ( className == null ) return null ;
  -
  -    if ( "java" == className ) 
  -      className = "org.apache.soap.providers.JavaProvider" ;
  -    else if ( "script" == className )
  -      className = "org.apache.soap.providers.JavaProvider" ;
  +                                 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");
  +    }
   
  -    try {
  -      c = Class.forName (className);
  -      newObj = c.newInstance();
  -    } catch( Exception exp ) {
  -      throw new SOAPException( Constants.FAULT_CODE_SERVER, 
  -                               "Can't load provider '" + className + "'", exp);
  +    // 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);
  +          targetObject = session.getValue (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.putValue (targetID, targetObject);
  +          // 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);
  +      }
       }
   
  -    if ( !(newObj instanceof Provider) )
  -      throw new SOAPException( Constants.FAULT_CODE_SERVER, 
  -                               "'" + className + "' isn't a provider");
  - 
  -    return (Provider) newObj ;
  +    return targetObject;
     }
   }