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();
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();