axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/attachments AttachmentPart.java
Date Sun, 23 Nov 2003 05:02:32 GMT
dims        2003/11/22 21:02:32

  Modified:    java/src/org/apache/axis/attachments AttachmentPart.java
  Log:
  Fix for Bug 24146 - Problems with attachment (SOAP with Attachments) temporary files
  from Werner.Dittmann@icn.siemens.de (Werner Dittmann)
  
  Revision  Changes    Path
  1.40      +34 -18    ws-axis/java/src/org/apache/axis/attachments/AttachmentPart.java
  
  Index: AttachmentPart.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- AttachmentPart.java	23 Nov 2003 03:51:59 -0000	1.39
  +++ AttachmentPart.java	23 Nov 2003 05:02:32 -0000	1.40
  @@ -117,6 +117,11 @@
           datahandler = dh;
           if(dh != null) {
               setMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, dh.getContentType());
  +	    javax.activation.DataSource ds = dh.getDataSource();
  +	    if (ds instanceof ManagedMemoryDataSource) {
  +		extractFilename((ManagedMemoryDataSource)ds); //and get the filename if appropriate
  +
  +	    }
           }
       }
   
  @@ -437,13 +442,17 @@
        * @see #getContent() getContent()
        */
       public void setContent(Object object, String contentType) {
  +        ManagedMemoryDataSource source = null;
           if (object instanceof String) {
               try {
                   String s = (String) object;
                   java.io.ByteArrayInputStream bais =
                           new java.io.ByteArrayInputStream(s.getBytes());
  -                datahandler = new DataHandler(new ManagedMemoryDataSource(bais,
  -                        ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED, contentType, true));
  +                source = new ManagedMemoryDataSource(bais,
  +                        ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED,
  +                        contentType, true);
  +                extractFilename(source);
  +                datahandler = new DataHandler(source);
                   contentObject = object;
                   return;
               } catch (java.io.IOException io) {
  @@ -452,17 +461,19 @@
                           Messages.getMessage("illegalArgumentException00"));
               }
           } else if (object instanceof java.io.InputStream) {
  -                try {
  -                    ManagedMemoryDataSource source = new ManagedMemoryDataSource((java.io.InputStream)object,
  -                                                ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED,
contentType, true);
  -                    datahandler = new DataHandler(source);
  -                    contentObject = object;
  -                    return;
  -                } catch (java.io.IOException io) {
  -                    log.error(Messages.getMessage("javaIOException00"), io);
  -                    throw new java.lang.IllegalArgumentException(
  -                            Messages.getMessage("illegalArgumentException00"));
  -                }
  +            try {
  +                source = new ManagedMemoryDataSource((java.io.InputStream) object,
  +                        ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED,
  +                        contentType, true);
  +                extractFilename(source);
  +                datahandler = new DataHandler(source);
  +                contentObject = object;
  +                return;
  +            } catch (java.io.IOException io) {
  +                log.error(Messages.getMessage("javaIOException00"), io);
  +                throw new java.lang.IllegalArgumentException(Messages.getMessage
  +                        ("illegalArgumentException00"));
  +            }
           } else {
               throw new java.lang.IllegalArgumentException(
                       Messages.getMessage("illegalArgumentException00"));
  @@ -567,16 +578,21 @@
        * is no longer completely usable, at this point
        */
       public synchronized void dispose() {
  -        if(attachmentFile!=null) {
  -            File f=new File(attachmentFile);
  -            //no need to check for existence here.
  -            f.delete();
  +        if (attachmentFile != null) {
  +            javax.activation.DataSource ds = datahandler.getDataSource();
  +            if (ds instanceof ManagedMemoryDataSource) {
  +                ((ManagedMemoryDataSource) ds).delete(); //and delete the file
  +            } else {
  +                File f = new File(attachmentFile);
  +                //no need to check for existence here.
  +                f.delete();
  +            }
               //set the filename to null to stop repeated use
               setAttachmentFile(null);
           }
           //clean up the datahandler, as it will have been
           //invalidated if it was bound to a file; if it wasnt
           //we get to release memory anyway
  -        datahandler=null;
  +        datahandler = null;
       }
   }
  
  
  

Mime
View raw message