wood burning stoves 2.0*
The moose likes JSF and the fly likes File download - Different behaviour of Windows & Linux server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "File download - Different behaviour of Windows & Linux server" Watch "File download - Different behaviour of Windows & Linux server" New topic
Author

File download - Different behaviour of Windows & Linux server

Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
I am trying to show a PDF from a NAS server to the end user on clicking a link in my web app. The first part is to write it to a temporary location in Linux, then the other part is to provide a handle to the file(filename) to a servlet which streams the data.

This implementation works fine in Windows , where it pops up the file "Open /Save" dialog, but fails to give any response in Linux and I get a 404 page.

Any tips or ideas will be highly appreciated.

P.S: I am closing the file output streams as soon as I am done writing into the file. I have also verified that the files are actually created in Linux folder.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Geeks , still no reply ??
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

But 404 means "Not Found". That means it's nothing to do with PDF, it's just that your Linux server is configured differently and fails to serve the URL with which you request the PDF. I expect that is happening here:
the other part is to provide a handle to the file(filename) to a servlet which streams the data

so it would be the URL which requests that servlet.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Thanks for your efforts Paul Clapham.

I am actually not getting a FileNotFoundException in the server logs, but its just that the page is not getting loaded.
I verified the path of the file location by printing them in logs. This is what makes it confusing :(


Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Guys, still I have not found the solution for this issue.

The following is the representation of LOC that I am using in the web component ( JSF bean). The below code works fine in Windows and there are no syntax errors.




Please provide your valuable inputs. I am at this issue for a long time. I even tried SOP statements to print the byte array in JSF Bean within the getData().
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Ajeeth Kumar wrote:I even tried SOP statements to print the byte array in JSF Bean within the getData().


And you didn't see any output from them? Then that means the code you posted isn't being called, and isn't part of the problem. Instead it's something in your configuration which is sending the 404 error instead of calling that code.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
I could see that the SOP prints the byte array , but somehow it is being prevented from redirecting it to the "File Open/save" dialog as it happens in Windows.

In Mozilla Firefox, nothing happens on the screen and I stay on the same page.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Then it's still something to do with the environment you're running that code in, and nothing in particular to do with I/O or streams in general.

Is that environment something we have a forum for here? It might be more practical if we moved the question to that forum, if that's the case.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
I am running it on JBoss 5 server on Linux machine.

I have also verified that the service end point configs have been set to support MTOM messages.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Actually, reading more carefully, I see you mentioned JSF. Could be something to do with JSF, something to do with JBoss. Pity we can't put the question into both forums at once, but let's try JSF first.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Thanks Paul. I hope to find some solution to this issue.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

JSF should not be used for raw output. In JSF, the response stream is built from a tree-structured View definition where the specifications of the various page elements using a plug-in renderer component attuned to the destination media (usually HTTP). So if you attempt to grab the HttpOutputStream and jam stuff in it directly, your results are unpredictable whether the server's JBoss, Tomcat or WebLogic, and irrespective of the underlying operating system.

You can construct PDFs in a JSF application, but the actual PDF creation and output needs to be done by a non-JSF servlet or JSP. JSF is not one of those iron frameworks where every URL has to be routed through JSF.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Tim Holloway wrote:JSF should not be used for raw output. In JSF, the response stream is built from a tree-structured View definition where the specifications of the various page elements using a plug-in renderer component attuned to the destination media (usually HTTP). So if you attempt to grab the HttpOutputStream and jam stuff in it directly, your results are unpredictable whether the server's JBoss, Tomcat or WebLogic, and irrespective of the underlying operating system.

You can construct PDFs in a JSF application, but the actual PDF creation and output needs to be done by a non-JSF servlet or JSP. JSF is not one of those iron frameworks where every URL has to be routed through JSF.


Thanks for your suggestion Tim. But that didnt solve the issue

I tweaked the response header content type to binary instead of chunked and it solved the issue.
Not sure why it failed earlier because chunked should be used when the response content is supposed to be streamed in a buffered fashion.

I am posting my resolution here so that it will be useful for people who are facing similar issues. If anybody has a better solution please reply back
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File download - Different behaviour of Windows & Linux server