You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/04/24 04:17:41 UTC

cvs commit: ws-axis/java/test/functional TestAttachmentsSample.java

dims        2005/04/23 19:17:41

  Modified:    java/src/org/apache/axis/attachments DimeBodyPart.java
               java/test/functional TestAttachmentsSample.java
  Log:
  Fix for zero size attachment and minor code cleanup.
  
  Revision  Changes    Path
  1.27      +7 -8      ws-axis/java/src/org/apache/axis/attachments/DimeBodyPart.java
  
  Index: DimeBodyPart.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/attachments/DimeBodyPart.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DimeBodyPart.java	23 Apr 2005 21:37:38 -0000	1.26
  +++ DimeBodyPart.java	24 Apr 2005 02:17:41 -0000	1.27
  @@ -226,7 +226,8 @@
           } else if (data instanceof DynamicContentDataHandler) {
               send(os, position, (DynamicContentDataHandler) data, maxchunk);
           } else if (data instanceof DataHandler) {
  -            DynamicContentDataHandler dh2 = new DynamicContentDataHandler(((DataHandler)data).getDataSource());
  +            DataSource source = ((DataHandler)data).getDataSource();
  +            DynamicContentDataHandler dh2 = new DynamicContentDataHandler(source);
               send(os, position, dh2, maxchunk);
           }
       }
  @@ -272,8 +273,6 @@
           final long maxchunk) throws java.io.IOException {
           java.io.InputStream in = null;
           try {
  -            byte chunknext = 0;
  -
               long dataSize = getDataSize();
               in = dh.getInputStream();
               byte[] readbuf = new byte[64 * 1024];
  @@ -327,13 +326,13 @@
       		byte[] buffer2 = new byte[myChunkSize]; 
       		
       		int bytesRead1 = 0 , bytesRead2 = 0;
  -    		byte chunknext = 0;
  -    		
  +
       		bytesRead1 = in.read(buffer1);
       		
       		if(bytesRead1 < 0) {
  -    			//no data all.should we be sending an empty dime record?
  -    			throw new IOException("No data found to send in DIME message");
  +                sendHeader(os, position, 0, (byte) 0);
  +                os.write(pad, 0, dimePadding(0));
  +                return;
       		}
       		
       		do {
  @@ -346,7 +345,7 @@
       				break;
       			}
       			
  -    			sendChunk(os, position, buffer1, 0, bytesRead1, (byte)CHUNK);
  +    			sendChunk(os, position, buffer1, 0, bytesRead1, CHUNK);
   
       			//now that we have written out buffer1, copy buffer2 into to buffer1
       			System.arraycopy(buffer2,0,buffer1,0,myChunkSize);
  
  
  
  1.13      +6 -0      ws-axis/java/test/functional/TestAttachmentsSample.java
  
  Index: TestAttachmentsSample.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/functional/TestAttachmentsSample.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestAttachmentsSample.java	25 Feb 2004 14:02:55 -0000	1.12
  +++ TestAttachmentsSample.java	24 Apr 2005 02:17:41 -0000	1.13
  @@ -52,6 +52,12 @@
          assertEquals("Didn't process attachment correctly", res, true) ;
       }
       
  +    public void doTestAttachmentsDimeLeaveEmpty() throws Exception {
  +        Options opts = new Options( new String[]{});
  +        boolean res = new EchoAttachment(opts).echo(true, "samples/attachments/leaveempty.txt");
  +       assertEquals("Didn't process attachment correctly", res, true) ;
  +    }
  +
       public void doTestAttachments2() throws Exception {
           Options opts = new Options( new String[]{});
           boolean res = new EchoAttachment(opts).echoDir(false, "samples/attachments");