aspose file tools*
The moose likes Tomcat and the fly likes InputStream problem on Tomcat version 5.5 and later... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "InputStream problem on Tomcat version 5.5 and later..." Watch "InputStream problem on Tomcat version 5.5 and later..." New topic
Author

InputStream problem on Tomcat version 5.5 and later...

Ariffin Ahmad
Ranch Hand

Joined: Aug 16, 2001
Posts: 84
hi there.....

have this weird problem that haunting me for sometime now.
the situation:

i'm using servlet tunneling technique to communicate between my C
application and my Java based web application.

as shown in code below, i'm pooling the blocking read of InputStream in
order to get incoming data from my remote C application.

while it working fine on Tomcat version 5.0.30 and earlier, the method
doesnt seems to work on Tomcat version 5.5 and later as the read
function doesnt block anymore and always return '-1' immediately
(similar situation as when connection get diconnected/timeout).

the code:


any suggestion?...
[ June 25, 2008: Message edited by: Ariffin Ahmad ]
Ariffin Ahmad
Ranch Hand

Joined: Aug 16, 2001
Posts: 84
found out the reason.

seems like i need to set Content-Length in HTTP header.
but the problem that i have now is I'm intended to have a persistent socket connection, from my C application to this servlet.
hence, the content length is unknown, or should i say, unlimited.

any suggestion to my problem?...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
I'm intended to have a persistent socket connection, from my C application to this servlet.


So you are opening a Http connection from the C app and keeping it open indefinately? That would appear to be contrary to the HTTP style, maybe you need custom socket programming.

What happens if you just specify some really large content length?

Bill
Ariffin Ahmad
Ranch Hand

Joined: Aug 16, 2001
Posts: 84
i realized that it is contrary to the HTTP style.
but, i need to do it that way since i want to eliminate the headache of having to deal with firewall rules and what so ever.

custom socket programming not really practical, since i still need the tomcat to do portal hosting service for me.

lets me describe more about my situation:
i have a machine at home that will keep sending events to portal. at the
same time, the portal may also send some instruction to the machine.
this machine will be at lots of home, and each one of them will keep
updating(through events) the portal on whatever activities going on there.

the machine owner then, can access the portal and then view the updates
sent by his machine. then he may send some instruction to his machine,
through the portal.

i believe it is possible to assign a very large number to the content-length, but the communication between the machine and the portal will still meet the limit of the content-length at some point. and when that happen, nothing can be read on the servlet anymore.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
I am wondering if the Grizzly approach to server IO would solve your problem. As I understand it, it has a different implementation of request input streams.

Bill
Ariffin Ahmad
Ranch Hand

Joined: Aug 16, 2001
Posts: 84
thanks for the link.
i will look into it.

by the way.
my understanding is, HTTP 1.1 is a persistent connection by default.
is there any way for me to get the main input/output stream from my servlet for that socket HTTP 1.1 connection?
HttpServletRequest seems to only return input stream for request on that servlet, ie: i can only read for defined content-length and after that read() will return -1, even though HTTP 1.1 connection still there.

cheers....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InputStream problem on Tomcat version 5.5 and later...