rineholt    2002/06/30 19:46:28

  Modified:    java/samples/attachments EchoAttachment.java
                        EchoAttachmentsService.java
               java/src/org/apache/axis/attachments DimeBodyPart.java
                        DimeDelimitedInputStream.java
  Log:
  Update attachments sample to show how to send using DIME format.
  Minor fix for when the attachment is 0 length.
  
  Revision  Changes    Path
  1.16      +26 -5     xml-axis/java/samples/attachments/EchoAttachment.java
  
  Index: EchoAttachment.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/attachments/EchoAttachment.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- EchoAttachment.java       19 Jun 2002 19:11:49 -0000      1.15
  +++ EchoAttachment.java       1 Jul 2002 02:46:27 -0000       1.16
  @@ -91,6 +91,8 @@
   
       Options opts = null;
   
  +    static boolean doTheDIME= false;
  +
       public EchoAttachment( Options opts) {
           this.opts = opts;
       }
  @@ -137,6 +139,10 @@
   
           call.setPassword( opts.getPassword() );
   
  +        if(doTheDIME)
  +            call.setProperty(call.ATTACHMENT_ENCAPSULATION_FORMAT,
  +              call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
  +
   
           Object ret = call.invoke( new Object[] {
                       dhSource
  @@ -207,9 +213,9 @@
   
           
//call.setScopedProperty(MessageContext.HTTP_TRANSPORT_VERSION,HTTPConstants.HEADER_PROTOCOL_V11);
           Hashtable myhttp= new Hashtable();
  -        myhttp.put("dddd","yyy");
  +        myhttp.put("dddd","yyy");     //Send extra soap headers
           myhttp.put("SOAPAction","dyyy");
  -        myhttp.put("SOAPActions","kkk");
  +        myhttp.put("SOAPActions","prova");
           
//myhttp.put(HTTPConstants.HEADER_TRANSFER_ENCODING,HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED);
           call.setScopedProperty(HTTPConstants.REQUEST_HEADERS,myhttp);
   
  @@ -233,6 +239,10 @@
   
           call.setPassword( opts.getPassword() );
   
  +        if(doTheDIME)
  +            call.setProperty(call.ATTACHMENT_ENCAPSULATION_FORMAT,
  +              call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
  +
           Object ret = call.invoke( new Object[] {
                       attachments
                   } 
  @@ -302,13 +312,24 @@
               EchoAttachment echoattachment = new EchoAttachment(opts);
   
               args = opts.getRemainingArgs();
  +            int argpos=0;
   
               if(args == null || args.length == 0){
                   System.err.println("Need a file or directory argument.");
                   System.exit(8);
               }
   
  -            String argFile = args[0];
  +            if( args[0].trim().equalsIgnoreCase("+FDR")){
  +              doTheDIME= true;
  +              ++argpos;
  +            }
  +
  +            if(argpos >= args.length){
  +                System.err.println("Need a file or directory argument.");
  +                System.exit(8);
  +            }
  +
  +            String argFile = args[argpos];
   
               java.io.File source = new java.io.File(argFile);
   
  @@ -318,7 +339,7 @@
               }
   
               if (source.isFile()) {
  -                if (echoattachment.echo(args[0])) {
  +                if (echoattachment.echo(argFile)) {
                       System.out.println("Attachment sent and received ok!");
                       System.exit(0);
                   }
  @@ -328,7 +349,7 @@
                   }
               }
               else { //a directory?
  -                if (echoattachment.echoDir(args[0])) {
  +                if (echoattachment.echoDir(argFile)) {
                       System.out.println("Attachments sent and received ok!");
                       System.exit(0);
                   }
  
  
  
  1.3       +22 -0     xml-axis/java/samples/attachments/EchoAttachmentsService.java
  
  Index: EchoAttachmentsService.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/attachments/EchoAttachmentsService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EchoAttachmentsService.java       17 Nov 2001 00:06:50 -0000      1.2
  +++ EchoAttachmentsService.java       1 Jul 2002 02:46:27 -0000       1.3
  @@ -77,6 +77,17 @@
        */
       public DataHandler echo( DataHandler dh) {
           System.err.println("In echo");
  +
  +        //Attachments are sent by default back as a MIME stream if no attachments 
were
  +        // received.  If attachments are received the same format that was received 
will
  +        // be the default stream type for any attachments sent.
  +
  +        //The following two commented lines would force any attachments sent back.
  +        //  to be in DIME format.
  +
  +        //Message rspmsg=AxisEngine.getCurrentMessageContext().getResponseMessage();
  +        
//rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachments.SEND_TYPE_DIME);
  +        
           if (dh == null ) System.err.println("dh is null");
           else System.err.println("Received \""+dh.getClass().getName()+"\".");
           return dh;
  @@ -88,6 +99,17 @@
        */
       public DataHandler[] echoDir( DataHandler[] attachments) {
           System.err.println("In echoDir");
  +
  +        //Attachments are sent by default back as a MIME stream if no attachments 
were
  +        // received.  If attachments are received the same format that was received 
will
  +        // be the default stream type for any attachments sent.
  +
  +        //The following two commented lines would force any attachments sent back.
  +        //  to be in DIME format.
  +
  +        //Message rspmsg=AxisEngine.getCurrentMessageContext().getResponseMessage();
  +        
//rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachments.SEND_TYPE_DIME);
  +
           if (attachments == null ) System.err.println("attachments is null!");
           else System.err.println("Got " + attachments.length + " attachments!");
           return attachments;
  
  
  
  1.2       +11 -8     xml-axis/java/src/org/apache/axis/attachments/DimeBodyPart.java
  
  Index: DimeBodyPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/DimeBodyPart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DimeBodyPart.java 30 Jun 2002 19:59:04 -0000      1.1
  +++ DimeBodyPart.java 1 Jul 2002 02:46:27 -0000       1.2
  @@ -401,7 +401,6 @@
   
       long getTransmissionSize(long chunkSize) {
           long size = 0;
  -
           size += id.length;
           size += dimePadding(id.length);
           size += type.length;
  @@ -409,15 +408,19 @@
           //no options.
           long dataSize = getDataSize();
   
  -        long fullChunks = dataSize / chunkSize;
  -        long lastChunkSize = dataSize % chunkSize;
  +        if(0 == dataSize){
  +            size+=12; //header size.
  +        }else{
   
  -        if (0 != lastChunkSize) size += 12; //12 bytes for fixed header
  -        size += 12 * fullChunks; //add additional header size for each chunk.
  -        size += fullChunks * dimePadding(chunkSize);
  -        size += dimePadding(lastChunkSize);
  -        size += dataSize;
  +            long fullChunks = dataSize / chunkSize;
  +            long lastChunkSize = dataSize % chunkSize;
   
  +            if (0 != lastChunkSize) size += 12; //12 bytes for fixed header
  +            size += 12 * fullChunks; //add additional header size for each chunk.
  +            size += fullChunks * dimePadding(chunkSize);
  +            size += dimePadding(lastChunkSize);
  +            size += dataSize;
  +        }
           return size;
       }
   
  
  
  
  1.2       +10 -3     
xml-axis/java/src/org/apache/axis/attachments/DimeDelimitedInputStream.java
  
  Index: DimeDelimitedInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/DimeDelimitedInputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DimeDelimitedInputStream.java     30 Jun 2002 19:59:04 -0000      1.1
  +++ DimeDelimitedInputStream.java     1 Jul 2002 02:46:27 -0000       1.2
  @@ -176,6 +176,7 @@
       private final int readFromStream(final byte[] b,
           final int start, final int length) 
           throws IOException {
  +        if (length == 0) return 0;
   
           int br = 0;
           int brTotal = 0;
  @@ -186,12 +187,12 @@
               } catch (IOException e) {
                   streamInError = e;
                   throw e;
  -            };
  +            }
               if (br > 0) brTotal += br;
           }
           while (br > -1 && brTotal < length);
   
  -        return brTotal != 0 ? brTotal : br;
  +        return br > -1 ? brTotal : br;
       }
   
       /**
  @@ -224,7 +225,7 @@
       }
   
       /**
  -     * Read from the boundary delimited stream.
  +     * Read from the DIME stream.
        * @param b is the array to read into.
        * @param off is the offset 
        * @return the number of bytes read. -1 if endof stream.
  @@ -258,8 +259,14 @@
   
           if (0 == len) return 0; //quick.
   
  +        if(recordLength == 0 && bytesRead == 0 &&  !moreChunks){
  +          ++bytesRead; //odd case no data to read -- give back 0 next time -1;
  +          if(ME) theEnd = true;
  +          return 0;
  +        }
           if (bytesRead >= recordLength && !moreChunks) {
               dataPadLength -= readPad(dataPadLength);
  +            if(ME) theEnd = true;
               return -1;
           }
   
  
  
  


Reply via email to