dims        2002/12/22 07:40:26

  Modified:    java/src/org/apache/axis/attachments AttachmentPart.java
               java/test/saaj TestAttachment.java
  Log:
  Patch for Bug 15593 - AttachmentPart.getSize() reports wrong value
  from [EMAIL PROTECTED] (Taras Shkvarchuk)
  
  Revision  Changes    Path
  1.33      +3 -17     
xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java
  
  Index: AttachmentPart.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- AttachmentPart.java       11 Dec 2002 22:38:08 -0000      1.32
  +++ AttachmentPart.java       22 Dec 2002 15:40:26 -0000      1.33
  @@ -64,6 +64,7 @@
   import javax.activation.DataHandler;
   import javax.xml.soap.SOAPException;
   import java.util.Iterator;
  +import java.io.ByteArrayOutputStream;
   
   /**
    * Class AttachmentPart
  @@ -83,12 +84,6 @@
       private javax.xml.soap.MimeHeaders mimeHeaders =
               new javax.xml.soap.MimeHeaders();
   
  -    /** Field contentId           */
  -    private String contentId;
  -
  -    /** Field contentLocation           */
  -    private String contentLocation;
  -
       /** Field contentObject */
       private Object contentObject;
   
  @@ -198,7 +193,6 @@
        *     Sets Content-Id of this part.
        *      already defined.
        *     @param newCid new Content-Id
  -     *     @returns void
        */
       public void setContentId(String newCid) {
           setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, newCid);
  @@ -451,17 +445,14 @@
       public int getSize() throws SOAPException {
           if (datahandler == null)
               return 0;
  -        ByteBuffer bout = new ByteBuffer();
  +        ByteArrayOutputStream bout = new ByteArrayOutputStream();
           try {
               datahandler.writeTo(bout);
           } catch (java.io.IOException ex) {
               log.error(Messages.getMessage("javaIOException00"), ex);
               throw new SOAPException(Messages.getMessage("javaIOException01", 
ex.getMessage()), ex);
           }
  -        byte bytes[] = bout.getBytes();
  -        if (bytes != null)
  -            return bytes.length;
  -        return -1;
  +        return bout.size();
       }
   
       /**
  @@ -477,11 +468,6 @@
           return mimeHeaders.getHeader(name);
       }
   
  -    private class ByteBuffer extends java.io.ByteArrayOutputStream {
  -        byte[] getBytes() {
  -            return super.buf;
  -        }
  -    }
       /**
        * Content ID.
        *
  
  
  
  1.7       +39 -0     xml-axis/java/test/saaj/TestAttachment.java
  
  Index: TestAttachment.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/saaj/TestAttachment.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestAttachment.java       5 Jul 2002 12:34:49 -0000       1.6
  +++ TestAttachment.java       22 Dec 2002 15:40:26 -0000      1.7
  @@ -5,6 +5,12 @@
   import javax.xml.soap.SOAPConnection;
   import javax.xml.soap.SOAPConnectionFactory;
   import javax.xml.soap.SOAPMessage;
  +import javax.activation.DataHandler;
  +import javax.activation.DataSource;
  +import java.io.InputStream;
  +import java.io.IOException;
  +import java.io.OutputStream;
  +import java.io.ByteArrayInputStream;
   
   public class TestAttachment extends junit.framework.TestCase {
   
  @@ -76,10 +82,43 @@
            }
           assertTrue(nAttachments==2);
       }
  +    
  +    public void testBadAttSize() throws Exception {
  +        MessageFactory factory = MessageFactory.newInstance();
  +        SOAPMessage message = factory.createMessage();
  +
  +        class Src implements DataSource{
  +            InputStream m_src;
  +            String m_type;
  +
  +            public Src(InputStream data, String type){
  +                m_src=data;
  +                m_type=type;
  +            }
  +            public String getContentType(){
  +                return m_type;
  +            }
  +            public InputStream getInputStream() throws IOException{
  +                m_src.reset();
  +                return m_src;
  +            }
  +            public String getName(){
  +                return "Some-Data";
  +            }
  +            public OutputStream getOutputStream(){
  +                throw new UnsupportedOperationException("I don't give output 
streams");
  +            }
  +        }
  +        ByteArrayInputStream ins=new ByteArrayInputStream(new byte[5]);
  +        DataHandler dh=new DataHandler(new Src(ins,"text/plain"));
  +        AttachmentPart part = message.createAttachmentPart(dh);
  +        assertEquals("Size should match",5,part.getSize());
  +    }
   
       public static void main(String[] args) throws Exception {
           test.saaj.TestAttachment tester = new test.saaj.TestAttachment("TestSAAJ");
           tester.testMultipleAttachments();
           tester.testStringAttachment();
  +        tester.testBadAttSize();
       }
   }
  
  
  


Reply via email to