tags:

views:

188

answers:

2

I've got a java function that generates digital signatures for xml files. Here's an excerpt that is giving me some trouble:

String boundary = MultiPartFormOutputStream.createBoundary();
HttpURLConnection urlConn = (HttpURLConnection)MultiPartFormOutputStream.createConnection(new URL(url + "/sign"));
urlConn.setRequestProperty("Accept", "*/*");
urlConn.setRequestProperty("Content-Type", MultiPartFormOutputStream.getContentType(boundary));
urlConn.setRequestProperty("Cache-Control", "no-cache");
urlConn.setDOInput(true);
urlConn.setDoOutput(true);

MultiPartFOrmOutputStream up = new MultiPartFormOutputStream(urlCOnn.getOutputStream(), boundary);
up.writeField(SignServletParams.detachedParam, "1");
up.writeFile(SignServletParams.xmlParam, "text/xml", "xml_file.xml", XMLUtil.toEncodedStream(doc);
up.close();

Document ret = null;
String connRead = "";
BufferedReader down = new BufferedReader(new InputStreamReader(urlCOnn.getINputStream()));

If I try and upload small xml files it works fine, however, if the xml file is larger (has a few thousand nodes), I get an IOException where the BufferedReader down is being created. The exception message just states that the server returned a 500 status. I checked the Apache server logs and it reports the following:

Input filter: failed to create temporary file: "file name"

I've inherited this code from someone else that wrote it, so I'm still trying to piece everything together, but any insight as to why the function works for small files and fails for larger ones would be appreciated.

A: 

I'm a noob so sorry if this is a stupid answer, but could you on the "uploaders-side" split the file into parts if necessary, and on the "server-side" merge them again?

Johannes
A: 

Thanks for the suggestion Johannes, but I figured out what the problem was and I am very silly. It turns out that the directory for temporary file creation specified by the mod_security config file didn't exist. Changing it to a real directory path fixed everything.