Stream Binary Data via a Servlet using a dynamic source

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
Joost
Ebase User
Posts: 49
Joined: Fri Sep 14, 2007 6:14 pm
Location: The Netherlands

Stream Binary Data via a Servlet using a dynamic source

#1

Postby Joost » Fri Jan 11, 2008 2:51 pm

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?
0 x

ehmd
Ebase User
Posts: 53
Joined: Thu Sep 13, 2007 9:02 am
Contact:

#2

Postby ehmd » Mon Jan 14, 2008 10:14 am

Try changing the code to ensure caching is switched off :-

Code: Select all


           URL url	= new URL(urlstr);
           URLConnection urlc= url.openConnection();
           urlc.useCaches(false);


Regards,


Mark
0 x

User avatar
Joost
Ebase User
Posts: 49
Joined: Fri Sep 14, 2007 6:14 pm
Location: The Netherlands

#3

Postby Joost » Tue Jan 15, 2008 1:55 pm

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.
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#4

Postby dvanhussel » Wed Jan 16, 2008 8:53 am

Hi Joost,

I would like to use similar functionality. Unfortunatly my experience with compiling servlets from source files is somewhat lacking :oops:
Is it possible for us (the City of Haarlem) to use the servlet you have made?

Kind regards,

David
0 x

User avatar
Joost
Ebase User
Posts: 49
Joined: Fri Sep 14, 2007 6:14 pm
Location: The Netherlands

#5

Postby Joost » Wed Jan 16, 2008 1:37 pm

dvanhussel wrote:compiling servlets from source files
0. Download java source file using link near bottom of devx page.
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>
After the Ebase webcontext has been restarted, the servlet may now be reached at the following location:
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

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#6

Postby dvanhussel » Thu Jan 17, 2008 9:14 am

Thanks for your reply!

I have the 'example-servlet' running now.
0 x


Who is online

Users browsing this forum: No registered users and 72 guests