ServletOutputStream & shtml files???

T

TomG

Hi,

I have code in a struts action that opens input and output streams,
then creates a URL connection. The file is read in chuncks and
streamed to the user's browser. We use this method to conceal the
source of the files and to check entitlements before giving the user
the file. The code works fine with html, .doc, .xls, & .pdf. However,
most .shtml files return only the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

A few files, usually 5 or 6K are processed correctly. Here is the
heart of the code. If anyone has any suggestion, please let me know.
(sorry about the formatting)

sUrl = sCRBaseURLRoot + sDocPath;
java.io.InputStream in=null;
ServletOutputStream stream = null;

try{
URL u = new URL(sUrl);
URLConnection c = u.openConnection();
c.connect();

in = new DataInputStream(c.getInputStream());
int i = 1;
stream = response.getOutputStream();

while ((sHeaderField=c.getHeaderField(i))!=null) {
sHeaderFieldKey=c.getHeaderFieldKey(i);
if (sHeaderFieldKey.equals("Server")) {
} else if (sHeaderFieldKey.equals("Date")) {
} else if (sHeaderFieldKey.equals("Connection")) {
} else {
response.setHeader(sHeaderFieldKey ,sHeaderField);
i++;
}

response.setContentLength(c.getContentLength());
if (sDocPath.toUpperCase().indexOf("DOWNLOAD") == -1) {
response.setHeader("Content-disposition", ":inline;filename=\"" +
filename + "\"");
response.setHeader("Content-Disposition", "attachment; filename=" +
filename);


int bytes_read;
// int BUFSIZE = 8192;
int BUFSIZE = 1634;
byte[] buffer = new byte[BUFSIZE];
while((bytes_read=in.read(buffer,0,BUFSIZE))!=-1) {
stream.write(buffer,0,bytes_read);
}
stream.flush();
stream.close();
 
M

marcus

My first reaction is you are using a webserver in addition to your
servlet engine, like apache->jk_mod->tomcat. The webserver sees the
shtml extension, attemps to filter the stream *after* it leaves your
servlet engine, doesn't like what it sees and cr*ps out. Hm, log file?
It might be as simple as removing from apache (or the equivalent)
"Options +Includes " which disables ssi.

you do know shtml causes the webserver to invoke ssi, right, and filter
the file? It might be very difficult to properly daisy-chain an ssi
file through the servlet engine and back through the webserver for the
includes. perhaps you can perform the includes in the servlet, after
disabling ssi on the server?

-- clh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top