axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bu...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils JavaUtils.java
Date Tue, 13 Aug 2002 15:17:14 GMT
butek       2002/08/13 08:17:13

  Modified:    java/src/org/apache/axis/encoding
                        DefaultTypeMappingImpl.java
               java/src/org/apache/axis/providers/java RPCProvider.java
               java/src/org/apache/axis/utils JavaUtils.java
  Log:
  Fix for http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11519.
  AXIS no longer requires activation.jar and mail.jar to run.  It DOES
  require them to build, however.
  
  Revision  Changes    Path
  1.44      +19 -15    xml-axis/java/src/org/apache/axis/encoding/DefaultTypeMappingImpl.java
  
  Index: DefaultTypeMappingImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DefaultTypeMappingImpl.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- DefaultTypeMappingImpl.java	13 Aug 2002 06:03:27 -0000	1.43
  +++ DefaultTypeMappingImpl.java	13 Aug 2002 15:17:13 -0000	1.44
  @@ -121,9 +121,11 @@
   
           // Since the last-registered type wins, I want to add the mime
           // String FIRST.
  -        myRegister(Constants.MIME_PLAINTEXT, java.lang.String.class,
  -                new JAFDataHandlerSerializerFactory(),
  -                new JAFDataHandlerDeserializerFactory(), false);
  +        if (JavaUtils.isAttachmentSupported()) {
  +            myRegister(Constants.MIME_PLAINTEXT, java.lang.String.class,
  +                    new JAFDataHandlerSerializerFactory(),
  +                    new JAFDataHandlerDeserializerFactory(), false);
  +        }
   
           // SOAP Encoded strings are treated as primitives.
           // Everything else is not.
  @@ -360,18 +362,20 @@
   
           // Register all the supported MIME types
           // (note that MIME_PLAINTEXT was registered near the top)
  -        myRegister(Constants.MIME_IMAGE, java.awt.Image.class,
  -                new JAFDataHandlerSerializerFactory(),
  -                new JAFDataHandlerDeserializerFactory(), false);
  -        myRegister(Constants.MIME_MULTIPART, javax.mail.internet.MimeMultipart.class,
  -                new JAFDataHandlerSerializerFactory(),
  -                new JAFDataHandlerDeserializerFactory(), false);
  -        myRegister(Constants.MIME_SOURCE, javax.xml.transform.Source.class,
  -                new JAFDataHandlerSerializerFactory(),
  -                new JAFDataHandlerDeserializerFactory(), false);
  -        myRegister(Constants.MIME_DATA_HANDLER, javax.activation.DataHandler.class,
  -                new JAFDataHandlerSerializerFactory(),
  -                new JAFDataHandlerDeserializerFactory(), false);
  +        if (JavaUtils.isAttachmentSupported()) {
  +            myRegister(Constants.MIME_IMAGE, java.awt.Image.class,
  +                    new JAFDataHandlerSerializerFactory(),
  +                    new JAFDataHandlerDeserializerFactory(), false);
  +            myRegister(Constants.MIME_MULTIPART, javax.mail.internet.MimeMultipart.class,
  +                    new JAFDataHandlerSerializerFactory(),
  +                    new JAFDataHandlerDeserializerFactory(), false);
  +            myRegister(Constants.MIME_SOURCE, javax.xml.transform.Source.class,
  +                    new JAFDataHandlerSerializerFactory(),
  +                    new JAFDataHandlerDeserializerFactory(), false);
  +            myRegister(Constants.MIME_DATA_HANDLER, javax.activation.DataHandler.class,
  +                    new JAFDataHandlerSerializerFactory(),
  +                    new JAFDataHandlerDeserializerFactory(), false);
  +        }
   
           // xsd:token
           myRegister(Constants.XSD_TOKEN, org.apache.axis.types.Token.class,
  
  
  
  1.84      +51 -8     xml-axis/java/src/org/apache/axis/providers/java/RPCProvider.java
  
  Index: RPCProvider.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/providers/java/RPCProvider.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- RPCProvider.java	9 Aug 2002 13:56:24 -0000	1.83
  +++ RPCProvider.java	13 Aug 2002 15:17:13 -0000	1.84
  @@ -70,6 +70,7 @@
   import org.apache.axis.message.SOAPEnvelope;
   import org.apache.axis.message.SOAPBodyElement;
   import org.apache.axis.soap.SOAPConstants;
  +import org.apache.axis.utils.ClassUtils;
   import org.apache.axis.utils.JavaUtils;
   
   import org.apache.axis.components.logger.LogFactory;
  @@ -82,6 +83,7 @@
   
   import java.io.IOException;
   
  +import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
   
   import java.util.Vector;
  @@ -230,8 +232,9 @@
                   value = JavaUtils.convert(value,
                                             sigType);
   
  -                if (value instanceof DataHandler) {
  -                    value = getDataFromDataHandler((DataHandler) value, paramDesc);
  +                if (value != null && value.getClass().getName().equals(
  +                        "javax.activation.DataHandler")) {
  +                    value = getDataFromDataHandler(value, paramDesc);
                   }
   
                   rpcParam.setValue(value);
  @@ -351,12 +354,16 @@
                       if ("Image".equals(MIMEName)) {
                       }
                       else if ("PlainText".equals(MIMEName)) {
  -                        value = new DataHandler(
  -                                new PlainTextDataSource("out", (String) value));
  +                        value = instantiateDataHandler(
  +                            "org.apache.axis.attachments.PlainTextDataSource",
  +                            "java.lang.String",
  +                            value);
                       }
                       else if ("Multipart".equals(MIMEName)) {
  -                        value = new DataHandler(new MimeMultipartDataSource(
  -                                "out", (MimeMultipart) value));
  +                        value = instantiateDataHandler(
  +                            "org.apache.axis.attachments.MultipartDataSource",
  +                            "javax.mail.internet.MimeMultipart",
  +                            value);
                       }
                       else if ("Source".equals(MIMEName)) {
                       }
  @@ -369,7 +376,43 @@
           resEnv.addBodyElement(resBody);
       }
   
  -    private Object getDataFromDataHandler(DataHandler handler, ParameterDesc paramDesc)
{
  +    /**
  +     * This method is the same as:
  +     *   new DataHandler(new DataSource("out", value));
  +     * but we want to be able to instantiate an RPCProvider without
  +     * requiring activation.jar and mail.jar.  If we use the raw
  +     * new statement, we get an error on instantiation of RPCProvider.
  +     */
  +    private Object instantiateDataHandler(String dataSourceName,
  +            String valueClass, Object value) {
  +        try {
  +            // Instantiate the DataSource
  +            Class dataSource = ClassUtils.forName(dataSourceName);
  +            Class[] dsFormalParms = {String.class,
  +                    ClassUtils.forName(valueClass)};
  +            Object[] dsActualParms = {"out", value};
  +            Constructor ctor = dataSource.getConstructor(dsFormalParms);
  +            Object ds = ctor.newInstance(dsActualParms);
  +
  +            // Instantiate the DataHandler
  +            Class dataHandler = ClassUtils.forName(
  +                    "javax.activation.DataHandler");
  +            Class[] dhFormalParms = {ClassUtils.forName(
  +                    "javax.activation.DataSource")};
  +            Object[] dhActualParms = {ds};
  +            ctor = dataHandler.getConstructor(dhFormalParms);
  +            value = ctor.newInstance(dhActualParms);
  +        }
  +        catch (Throwable t) {
  +            // If we have a problem, just return the input value
  +        }
  +        return value;
  +    } // instantiateDataHandler
  +
  +    /**
  +     * Get the data from the DataHandler.
  +     */
  +    private Object getDataFromDataHandler(Object handler, ParameterDesc paramDesc) {
           Object value = handler;
           QName qname = paramDesc.getTypeQName();
           if (qname != null &&
  @@ -378,7 +421,7 @@
                    qname.equals(Constants.MIME_MULTIPART) ||
                    qname.equals(Constants.MIME_SOURCE))) {
               try {
  -                value = handler.getContent();
  +                value = ((DataHandler) handler).getContent();
               }
               catch (IOException ioe) {
                   // If there are any problems, just return the DataHandler.
  
  
  
  1.69      +32 -1     xml-axis/java/src/org/apache/axis/utils/JavaUtils.java
  
  Index: JavaUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/JavaUtils.java,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- JavaUtils.java	12 Aug 2002 22:52:13 -0000	1.68
  +++ JavaUtils.java	13 Aug 2002 15:17:13 -0000	1.69
  @@ -254,7 +254,8 @@
           }
   
           // Convert an AttachmentPart to the given destination class.
  -        if (arg instanceof AttachmentPart || arg instanceof DataHandler) {
  +        if (isAttachmentSupported() &&
  +                (arg instanceof AttachmentPart || arg instanceof DataHandler)) {
               try {
                   String destName = destClass.getName();
                   if (destClass == String.class
  @@ -1120,4 +1121,34 @@
               return null;
           }
       } // mimeToJava
  +
  +    //avoid testing and possibly failing everytime.
  +    private static boolean checkForAttchmentSupport = true;
  +    private static boolean attachmentSupportEnabled = false;
  +
  +    /**
  +     * Determine whether attachments are supported by checking if the following
  +     * classes are available:  javax.activation.DataHandler,
  +     * javax.mail.internet.MimeMultipart.
  +     */
  +    public static synchronized boolean isAttachmentSupported() {
  +
  +        if (checkForAttchmentSupport) {
  +            //aviod testing and possibly failing everytime.
  +            checkForAttchmentSupport = false;
  +            try {
  +                // Attempt to resolve DataHandler and MimeMultipart and
  +                // javax.xml.transform.Source, all necessary for full
  +                // attachment support
  +                ClassUtils.forName("javax.activation.DataHandler");
  +                ClassUtils.forName("javax.mail.internet.MimeMultipart");
  +                attachmentSupportEnabled = true;
  +            } catch (Throwable t) {
  +            }
  +        }
  +
  +        log.debug(JavaUtils.getMessage("attachEnabled") + "  " +
  +                attachmentSupportEnabled);
  +        return attachmentSupportEnabled;
  +    } // isAttachmentSupported
   }
  
  
  

Mime
View raw message