Hi Franz,

here is an example code for sending large attachments: 

server side code:

    public void upload(String name, Date date, DataHandler handler)
        throws IOException
    {
        System.out.println("start uploading...");
        System.out.println("name " + name);
        System.out.println("date " + date.toString());

        String uploadDir = createUploadDir();

        String fileName  = uploadDir + File.separator + name;
        System.out.println("fileName: " + fileName);


        BufferedInputStream in   =
            new
BufferedInputStream(handler.getDataSource().getInputStream());
       
        BufferedOutputStream out =
            new BufferedOutputStream(new FileOutputStream(fileName));
        byte[] data              = new byte[1024 * 8];
        int size                 = 0;
        while ((size = in.read(data)) != -1)
        {
            out.write(data, 0, size);
        }

        File file = new File(fileName);
        file.setLastModified(date.getTime());
        in.close();
        out.close();

        System.out.println("uploading done...");
    }


Client side code:


public static void main(String[] args) throws Exception
    {
        
        String filename              = "jakarta.zip";
        
        DataHandler dhSource = new DataHandler(new
FileDataSource(filename));

        System.out.println("contentType:  " + dhSource.getContentType());
        
        Service service = new Service();
        Call call       = (Call)service.createCall();
        call.setTargetEndpointAddress(
            new
URL("http://localhost:8080/axis/services/FileUploadService";));
        call.setOperationName(
            new QName("http://webservice.ttp.confuoco";, "upload"));
        call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("date", XMLType.XSD_DATETIME, ParameterMode.IN);
        QName qnameAttachment =
            new QName("http://webservice.ttp.confuoco";, "DataHandler");
        call.registerTypeMapping(
            dhSource.getClass(),
            qnameAttachment,
            JAFDataHandlerSerializerFactory.class,
            JAFDataHandlerDeserializerFactory.class);
        call.addParameter("handler", qnameAttachment, ParameterMode.IN);
        call.setReturnType(XMLType.AXIS_VOID);
        Hashtable chunkedTable = new Hashtable();
        chunkedTable.put(
            HTTPConstants.HEADER_TRANSFER_ENCODING,
            HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED);

        call.setProperty(
            MessageContext.HTTP_TRANSPORT_VERSION,
            HTTPConstants.HEADER_PROTOCOL_V11);
        call.setProperty(HTTPConstants.REQUEST_HEADERS, chunkedTable);

        call.setProperty(
            Call.ATTACHMENT_ENCAPSULATION_FORMAT,
            Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
        call.invoke(new Object[]{ filename, new Date(), dhSource });
    }

Hope it helps.

Ferruh








-----Ursprüngliche Nachricht-----
Von: Franz Graf [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 1. Juli 2005 22:39
An: [email protected]
Betreff: Re: Size of Attachments?

Great! Thank you Roy. That was the hint I needed.

Regards Franz

> This could be a temporary file storage problem:
> 
> Attachments larger than 16kb are flushed to disk instead of just kept in
> memory. 
> Check out your WEB-INF/server-config.wsdd file and the
> attachments.Directory property setting to see where Axis puts the
> attachment files:
> 
> <globalConfiguration>
>   <parameter name="attachments.Directory" value="/data/attachments"/>
> 
> 
> Regards
> 
> Roy Willy Haug
> 
>> -----Original Message-----
>> From: Franz Graf [mailto:[EMAIL PROTECTED] 
>> Sent: 29. juni 2005 22:46
>> To: [email protected]
>> Subject: Size of Attachments?
>> 
>> Hello all,
>> 
>> I want to send a file to my soap-server by using the 
>> call.addAttachmentPart(). Everything is fine as long as my 
>> attachment is less than 16384 bytes. When I add an attachment 
>> >16k the server tells me that it received 0 bytes.
>> 
>> How can i send bigger data? I've found quite some postings 
>> from people sending quite some MB - but not how.
>> 
>> Greetings Franz

Reply via email to