1 22 package org.jboss.test.webservice.jbws801; 23 24 import java.io.InputStream ; 25 import java.rmi.RemoteException ; 26 import java.util.Iterator ; 27 28 import javax.xml.rpc.ServiceException ; 29 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 30 import javax.xml.rpc.server.ServiceLifecycle ; 31 import javax.xml.rpc.server.ServletEndpointContext ; 32 import javax.xml.soap.AttachmentPart ; 33 import javax.xml.soap.SOAPMessage ; 34 35 public class LargeAttachmentImpl implements LargeAttachment, ServiceLifecycle 36 { 37 private ServletEndpointContext context; 38 39 public long sendLargeFile() throws RemoteException 40 { 41 long count = 0; 42 SOAPMessage message = ((SOAPMessageContext ) context.getMessageContext()).getMessage(); 43 try 44 { 45 byte[] buffer = new byte[1024]; 46 for (Iterator iter = message.getAttachments(); iter.hasNext(); ) 47 { 48 AttachmentPart part = (AttachmentPart ) iter.next(); 49 50 InputStream inputStream = part.getDataHandler().getInputStream(); 51 int read = 0; 52 do 53 { 54 count += read; 55 read = inputStream.read(buffer); 56 } 57 while (read != -1); 58 } 59 } 60 catch (Exception e) 61 { 62 throw new RemoteException (e.getMessage()); 63 } 64 65 System.out.println("[Size = " + count + "]"); 66 return count; 67 } 68 69 70 72 public void init(Object context) throws ServiceException 73 { 74 this.context = (ServletEndpointContext )context; 75 } 76 77 public void destroy() 78 { 79 this.context = null; 80 } 81 } 82 | Popular Tags |