File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Maximum size of attachments? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Maximum size of attachments?" Watch "Maximum size of attachments?" New topic
Author

Maximum size of attachments?

Buzz Andersen
Ranch Hand

Joined: Aug 28, 2001
Posts: 54
I am working on a program that uses Apache SOAP with attachments to transfer files. It seems to work great with most files, until I get to one that is around 26 MB, and then I get an "OutOfMemoryError" (with no stack trace) when I use call.invoke() on the client side.
Does this mean that there is a limit on the attachment size, or am I simply doing something wrong? Here is my client code:
DataSource ds = new ByteArrayDataSource(new File(path), null);
DataHandler dh = new DataHandler(ds);
MimeBodyPart mbp = new MimeBodyPart();
mbp.setDataHandler(dh);
mbp.setFileName(path);
mbp.setHeader(org.apache.soap.Constants.HEADER_CONTENT_LOCATION, "Attachment-1");

Call call = new Call();
call.addBodyPart(mbp);
call.setTargetObjectURI ("urn:point-methods");
call.setMethodName ("addAttachment");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

Vector params = new Vector();
params.addElement(new Parameter("filename", String.class, new File(path).getName(), null));
call.setParams(params);
URL url = new URL ("http://localhost:80/soap/servlet/rpcrouter");
Response resp = call.invoke(url, "");

if (resp.generatedFault()) {
Fault fault = resp.getFault();
System.out.println("Fault code: " + fault.getFaultCode());
System.out.println("Fault string: " + fault.getFaultString());
}
Thanks in advance for your help!
Buzz
[ May 08, 2002: Message edited by: Buzz Andersen ]
Buzz Andersen
Ranch Hand

Joined: Aug 28, 2001
Posts: 54
Alright--update: I decided that maybe I should look at some of Apache's samples in case I was just doing something wrong with my code. I stripped down Apache's MimeTest example (which is distributed with SOAP) into the following:
String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
URL url = new URL("http://localhost:80/soap/servlet/rpcrouter");
try {
// Build the call.
Call call = new Call();
call.setTargetObjectURI("urn:point-methods");
call.setMethodName("addMime");
call.setEncodingStyleURI(encodingStyleURI);
Vector params = new Vector();

DataSource ds = new ByteArrayDataSource(new File(args[0]), null);
DataHandler dh = new DataHandler(ds);
params.addElement(new Parameter("filename", String.class, new File(args[0]).getName(), null));
params.addElement(new Parameter("addedfile", javax.activation.DataHandler.class, dh, null));
call.setParams(params);
// Invoke the call.
Response resp;
try {
resp = call.invoke(url, "");
} catch (SOAPException e) {
System.err.println("Caught SOAPException (" + e.getFaultCode() + "): " + e.getMessage());
e.printStackTrace();
return;
}
// Check the response.
if (!resp.generatedFault()) {

} else {
Fault fault = resp.getFault();
System.err.println("Generated fault: ");
System.err.println (" Fault Code = " + fault.getFaultCode());
System.err.println (" Fault String = " + fault.getFaultString());
}
} catch(Exception e) {
e.printStackTrace();
}
But I STILL get the OutOfMemoryError! Is this some sort of inherent limitation in MIME or in Apache SOAP, or what? It's a little hard to tell because I'm not getting a stack trace!
Buzz
[ May 08, 2002: Message edited by: Buzz Andersen ]
Buzz Andersen
Ranch Hand

Joined: Aug 28, 2001
Posts: 54
Alright, another update (for the benefit of posterity):
I should have realized this before, but the problem was that the VM's heap size was not big enough to handle reading that big of a file completely into memory. Adding "-Xms32m -Xmx128m" to both the client and server-side VM arguments seems to fix the problem.
I guess the upshot is that, if you want to transfer arbitrarily large files, maybe SOAP is not the way to do it since it requires you to read the whole darn file into memory at once (rather than buffering as you would with an FTP program or what have you).
Does anyone know if there is some way around this problem of having to read everything into memory?
Buzz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maximum size of attachments?