Hi, I'm using mod-jk (v1.2.40) on CentOS Linux server to pass requests from
Apache web server (v2.4.9) to GlassFish (v3.1.2) application server. I'm using
a java 7 servlet (shown below) on my application server to enable a client to
download a PDF file via HTTPS.
Things work fine when this file size is less than about 4 MB. When the file is
larger than 4 MB, I see the following errors in the mod_jk.log file:
[info] init_jk::mod_jk.c (3383): mod_jk/1.2.40 initialized
[error] ajp_connection_tcp_get_message::jk_ajp_common.c (1313): wrong message
format 0xcad5 from ::1:8009
[error] ajp_get_reply::jk_ajp_common.c (2204): (worker1) Tomcat is down or
network problems. Part of the response has already been sent to the client
[info] ajp_service::jk_ajp_common.c (2673): (worker1) sending request to tomcat
failed (recoverable), because of protocol error (attempt=1)
[info] ajp_process_callback::jk_ajp_common.c (2000): Writing to client aborted
or client network problems
[info] ajp_service::jk_ajp_common.c (2673): (worker1) sending request to tomcat
failed (unrecoverable), because of client write error (attempt=2)
[info] jk_handler::mod_jk.c (2799): Aborting connection for worker=worker1
I'm not an expert here, and wondered if anyone could decode this to find root
cause and solution. There are no errors in Apache or GlassFish log files. When
I run the client Google Chrome browser (for example), it appears to download
the first 4 MB and then report "network error". Other browsers behave
similarly. Mod_jk appears to have the only log file reporting an error.
Other miscellaneous thoughts:
1. My server doesn't have a firewall limiting file size.
2. My client router/modem doesn't limit file download size (I download much
larger files often).
3. As far as I'm aware, the Java code below doesn't restrict the file size
download (can anyone confirm? perhaps mod-jk is complaining about the header or
content type?).
4. GlassFish timeout is 15 minutes, and the browser stops downloading after
perhaps 10 seconds.
I'm running out of things to check. What could it be? Any help is MUCH
appreciated. Thanks.
---------- Java Servlet ----------
public class GetFile extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String filename ="init_java";
try {
// get user parameters
filename = req.getParameter("fileId"); // complete path to file
//res.setContentType("video/mp4"); //not working
res.setContentType("application/x-download");
File file=new File(filename);
if (file.exists()) {
res.setHeader("Content-Disposition", "inline;
filename=\""+filename+"\"");
res.setHeader("Cache-Control", "cache, must-revalidate");
//res.setHeader("Pragma", "public"); // not sure when to use
returnFile(filename, res.getOutputStream());
} else {
//error handling goes here
}
} catch (Exception e) {
...
} finally {
...
}
}
private static void returnFile(String filename, OutputStream out) throws
FileNotFoundException, IOException {
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(filename));
byte[] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
out.write(buf, 0, bytesRead);
}
out.flush();
} finally {
if (in != null) in.close();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]