Using the code from http://www.devx.com/getHelpOn/Article/1 ... 54?pf=true I have managed to serve files dynamically. The idea is I will be able to store uploaded and generated files anywhere on the server and still be able to serve them via the web. They don't have to be in a web accessible directory anymore. Of course some modification of the supplied class will be needed.
Unfortunately the files I wish to serve aren't static files, but are served dynamically by yet another system over HTTP. I wish to relay those files through my servlet, because the other system is an internal system.
The thing is the getContentLength() method issued on the file served by the other server returns -1. My servlet expects me to set the content length with the correct positive value.
I wonder how I could solve this issue?
Stream Binary Data via a Servlet using a dynamic source
Moderators: Jon, Steve, Ian, Dave
- Joost
- Ebase User
- Posts: 49
- Joined: Fri Sep 14, 2007 6:14 pm
- Location: The Netherlands
-
- Ebase User
- Posts: 53
- Joined: Thu Sep 13, 2007 9:02 am
- Contact:
Try changing the code to ensure caching is switched off :-
Regards,
Mark
Code: Select all
URL url = new URL(urlstr);
URLConnection urlc= url.openConnection();
urlc.useCaches(false);
Regards,
Mark
0 x
- Joost
- Ebase User
- Posts: 49
- Joined: Fri Sep 14, 2007 6:14 pm
- Location: The Netherlands
The problem seems to be the URL I'm accessing doesn't set the ContentLength of the file that is sent.
It seems that the receiving end doesn't require it as well. So, available or not, I do not set it at all. If available I use it for the byte array. If not I use the value 2048 to initialize the array.
Seems to work in my situation.
It seems that the receiving end doesn't require it as well. So, available or not, I do not set it at all. If available I use it for the byte array. If not I use the value 2048 to initialize the array.
Seems to work in my situation.
0 x
- dvanhussel
- Ebase User
- Posts: 161
- Joined: Fri Oct 19, 2007 12:45 pm
- Location: Haarlem, the Netherlands
- Joost
- Ebase User
- Posts: 49
- Joined: Fri Sep 14, 2007 6:14 pm
- Location: The Netherlands
0. Download java source file using link near bottom of devx page.dvanhussel wrote:compiling servlets from source files
1. Put the StreamingContent.java file in "UfsServer\tomcat\webapps\ufs\WEB-INF\classes".
2. Cd to this classes directory.
3. Run C:\Progra~1\Java\jdk1.5.0_14\bin\javac -classpath ../../../../common/lib/servlet-api.jar StreamingContent.java
On my system I've installed the java JDK into the specified location.
Add the following to the bottom of WEB-INF/web.xml
Code: Select all
<servlet>
<servlet-name>StreamingContent</servlet-name>
<servlet-class>StreamingContent</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StreamingContent</servlet-name>
<url-pattern>/servlet/StreamingContent</url-pattern>
</servlet-mapping>
http://localhost:3030/ufs/servlet/StreamingContent
Please let me know if this answers your question?
btw. The Ebase lib folder contains cos.jar which among others contains functions to stream local and remote files. These functions could be used to enhance/replace the devx solution.
0 x
- dvanhussel
- Ebase User
- Posts: 161
- Joined: Fri Oct 19, 2007 12:45 pm
- Location: Haarlem, the Netherlands
Who is online
Users browsing this forum: No registered users and 41 guests