snichol     2002/12/10 09:33:40

  Modified:    java/src/org/apache/soap/providers/com RPCProvider.java
               java/docs changes.html
  Log:
  Submitted by: Leif Nilsson TACMa <[EMAIL PROTECTED]>
  
  We send XML-files through Apache Soap.
  There is a COM-server accessed via Apaches COMProvider.
  The best way to send files as discussed is through attachments.
  The only way I have figured out to do this via the ComProvider is to alter
  the
   org.apache.soap.providers.com.RPCProvider.java code.
  
  I'm sure there is a better way but I will explain what I have done.
    I have added an option for the COmProvider DeploymentDescriptor
  (AttachString), which if present and set to true will cause
    Strings returned from COM-servers to be packaged in a DataHandler object
  using UTF-8 coding.
  
  Scott Nichol added a few mods, including changing the option name to have
  a leading Upper case character.
  
  Revision  Changes    Path
  1.3       +39 -15    xml-soap/java/src/org/apache/soap/providers/com/RPCProvider.java
  
  Index: RPCProvider.java
  ===================================================================
  RCS file: 
/home/cvs/xml-soap/java/src/org/apache/soap/providers/com/RPCProvider.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RPCProvider.java  12 Apr 2001 16:26:53 -0000      1.2
  +++ RPCProvider.java  10 Dec 2002 17:33:40 -0000      1.3
  @@ -56,17 +56,26 @@
    */
   package org.apache.soap.providers.com;
   
  -import java.io.* ;
  -import java.util.* ;
  -import java.text.MessageFormat;
  -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.io.*;
   import java.lang.Math;
  -
  +import java.text.MessageFormat;
  +import java.util.*;
  +import javax.activation.DataHandler;
  +import javax.activation.DataSource;
  +import javax.servlet.*;
  +import javax.servlet.http.*;
  +import org.apache.soap.*;
  +import org.apache.soap.encoding.soapenc.SoapEncUtils;
  +import org.apache.soap.rpc.*;
  +import org.apache.soap.server.*;
  +import org.apache.soap.util.*;
  +import org.apache.soap.util.mime.ByteArrayDataSource;
  +
  +/*
  + * @author jmsnell?
  + * @author dug
  + * @author Leif Nilsson TACMa ([EMAIL PROTECTED])
  + */
   public class RPCProvider implements Provider
   {
     private DeploymentDescriptor dd ;
  @@ -81,6 +90,7 @@
     private ServletContext sc= null;
     private String threadingModel= null;
     private static boolean initLog= false;
  +  private boolean attachString=false;
   
     public void locate( DeploymentDescriptor dd,
                         Envelope env,
  @@ -108,6 +118,7 @@
        }
        
       //This validates that the method name is listed in the deployment descriptor.
  +    // TODO: use RPCRouter.validMessage
       if (!MessageRouter.validMessage (dd, methodName)) {
         String msg=
         Log.msg(Log.ERROR, "msg.comprovider.badMethod", targetObjectURI, methodName);
  @@ -142,10 +153,14 @@
          progid= targetObjectURI;
       }
   
  -    threadingModel=  (String) props.get("threadmodel"); 
  +    threadingModel=  (String) props.get("threadmodel");
       if( null == threadingModel) threadingModel= "MULTITHREADED";
       Log.msg(Log.INFORMATION, "msg.comprovider.info.cominf", progid, threadingModel 
);
   
  +    // Should we send Strings as attachments ?
  +    String attach = (String) props.get("AttachString");
  +    attachString  = (attach != null && SoapEncUtils.decodeBooleanValue(attach));
  +
       this.dd              = dd ;
       this.envelope        = env ;
       this.call            = call ;
  @@ -189,11 +204,20 @@
             }catch( Exception e)
             {
               String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nativeError", 
e.toString());
  -            throw new SOAPException( Constants.FAULT_CODE_SERVER, msg);
  +            throw new SOAPException(Constants.FAULT_CODE_SERVER, msg, e);
             }
             try {
             Parameter pret= null;
  -          if(ret != null) pret= new Parameter(RPCConstants.ELEM_RETURN , 
ret.getClass(), ret, null);
  +          if(ret != null) {
  +             if (attachString && ret instanceof String) {
  +                // We are about to return a String and they should be returned as
  +                //  attachments. Use a DataHandler object.
  +                DataSource  ds  = new ByteArrayDataSource(((String) 
ret).getBytes("UTF-8"), "application/octet-stream");
  +                DataHandler dh  = new DataHandler(ds);
  +                ret = dh;
  +             }
  +             pret= new Parameter(RPCConstants.ELEM_RETURN , ret.getClass(), ret, 
null);
  +          }
                 vp=null; //dereference.
             Response resp = new Response( targetObjectURI,   // URI
                              call.getMethodName(),  // Method
  @@ -211,7 +235,7 @@
             catch( Exception e ) {
               String msg= Log.msg(Log.ERROR, "msg.comprovider.error.exp", 
e.toString());
              if ( e instanceof SOAPException ) throw (SOAPException ) e ;
  -            throw new SOAPException( Constants.FAULT_CODE_SERVER, msg );
  +            throw new SOAPException( Constants.FAULT_CODE_SERVER, msg, e );
             }
   
      Log.msg(Log.SUCCESS, "msg.comprovider.ok", ret == null ? "*null*" : 
ret.toString() );
  @@ -316,7 +340,7 @@
        else if(o  instanceof java.lang.Long) //VT_R8
        { //COM has no long type so promote it to double which can contain it.
         v[os+0] = 5; //VT_R8
  -             v[os+1] = 0;
  +      v[os+1] = 0;
         long x= Double.doubleToLongBits((double)(((Long)o).longValue()));
         v[os+8]= (byte)x;
         v[os+9]= (byte)((x>>>8) & 0xff);
  
  
  
  1.53      +8 -5      xml-soap/java/docs/changes.html
  
  Index: changes.html
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/docs/changes.html,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- changes.html      4 Dec 2002 03:33:01 -0000       1.52
  +++ changes.html      10 Dec 2002 17:33:40 -0000      1.53
  @@ -96,11 +96,14 @@
         <li>Add client support for HTTP redirects.</li>
         <li>Allow additional transport headers to be specified by client.</li>
         <li>Add client support for one-way (as defined in WSDL) calls.</li>
  -      <li>Serialize method return values using their actual type rather than
  -      the declared type when the declared type is not a primitive.  This may
  -      break existing services, e.g. where methods return subclasses of the
  -      declared return type, but a serializer is registered only for the
  -      declared return type.</li>
  +      <li>Add the ability to serialize method return values using their actual
  +      type rather than the declared type (polymorphism) on a per service basis
  +      by specifying
  +      <code>&lt;isd:option key=&quot;PolymorphicSerialization&quot; 
value=&quot;true&quot;/&gt;</code>
  +      within the <code>isd:provider</code> element in the deployment 
descriptor.</li>
  +      <li>Add the ability to return text attachments from COM-based services by 
setting
  +      <code>&lt;isd:option key=&quot;AttachString&quot; 
value=&quot;true&quot;/&gt;</code>
  +      within the <code>isd:provider</code> element in the deployment 
descriptor.</li>
       </ul>
     </li>
   </ul>
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to