You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Vineet Chopra <in...@gmail.com> on 2005/03/31 05:56:16 UTC

Closed Input Stream across firewall

I am using a web application deployed on Tomcat 4.0 to receive and
route incoming XML messages to destination web application
also deployed on Tomcat 4.0. A firewall exists between these servers.
All firewall policies are enabled for incoming and outgoing traffic.

The ServletInputStream is already closed before I use it to create an
object of InputStreamReader. Thus I am not able to read the stream.

I did a snoop on the ports of these server which displayed the relay
of request XML reaching the destination port and invoking the servlet
in the
destination web application but failing to read the XML since the
input stream has been closed.

Can you give me any leads as to how to debug the problem.

On 31 Mar 2005 03:34:31 -0000, tomcat-user-help@jakarta.apache.org
<to...@jakarta.apache.org> wrote:
> Hi! This is the ezmlm program. I'm managing the
> tomcat-user@jakarta.apache.org mailing list.
>
> I'm working for my owner, who can be reached
> at tomcat-user-owner@jakarta.apache.org.
>
> Acknowledgment: I have added the address
>
>   incivincis@gmail.com
>
> to the tomcat-user mailing list.
>
> Welcome to tomcat-user@jakarta.apache.org!
>
> Please save this message so that you know the address you are
> subscribed under, in case you later want to unsubscribe or change your
> subscription address.
>
> --- Administrative commands for the tomcat-user list ---
>
> I can handle administrative requests automatically. Please
> do not send them to the list address! Instead, send
> your message to the correct command address:
>
> To subscribe to the list, send a message to:
>   <to...@jakarta.apache.org>
>
> To remove your address from the list, send a message to:
>   <to...@jakarta.apache.org>
>
> Send mail to the following for info and FAQ for this list:
>   <to...@jakarta.apache.org>
>   <to...@jakarta.apache.org>
>
> Similar addresses exist for the digest list:
>   <to...@jakarta.apache.org>
>   <to...@jakarta.apache.org>
>
> To get messages 123 through 145 (a maximum of 100 per request), mail:
>   <to...@jakarta.apache.org>
>
> To get an index with subject and author for messages 123-456 , mail:
>   <to...@jakarta.apache.org>
>
> They are always returned as sets of 100, max 2000 per request,
> so you'll actually get 100-499.
>
> To receive all messages with the same subject as message 12345,
> send an empty message to:
>   <to...@jakarta.apache.org>
>
> The messages do not really need to be empty, but I will ignore
> their content. Only the ADDRESS you send to is important.
>
> You can start a subscription for an alternate address,
> for example "john@host.domain", just add a hyphen and your
> address (with '=' instead of '@') after the command word:
> <to...@jakarta.apache.org>
>
> To stop subscription for this address, mail:
> <to...@jakarta.apache.org>
>
> In both cases, I'll send a confirmation message to that address. When
> you receive it, simply reply to it to complete your subscription.
>
> If despite following these instructions, you do not get the
> desired results, please contact my owner at
> tomcat-user-owner@jakarta.apache.org. Please be patient, my owner is a
> lot slower than I am ;-)
>
> --- Enclosed is a copy of the request I received.
>
> Return-Path: <in...@gmail.com>
> Received: (qmail 3674 invoked by uid 99); 31 Mar 2005 03:34:31 -0000
> X-ASF-Spam-Status: No, hits=0.4 required=10.0
>        tests=DNS_FROM_RFC_ABUSE,RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS
> X-Spam-Check-By: apache.org
> Received-SPF: pass (hermes.apache.org: domain of incivincis@gmail.com designates 64.233.170.204 as permitted sender)
> Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.204)
>  by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 30 Mar 2005 19:34:30 -0800
> Received: by rproxy.gmail.com with SMTP id j1so271025rnf
>        for <to...@jakarta.apache.org>; Wed, 30 Mar 2005 19:34:28 -0800 (PST)
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
>        s=beta; d=gmail.com;
>        h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references;
>        b=SjSbgg3bwIsKNMvudI4c6o2FXu9Lh/80ecJFi1RVR5IxGylotlu9xOc77pfXBAtdGmFW1uoRndrHJPcmda2LbpEHGBBPdxFAtLdniarva5JrJ1L62w6AyauwuzWnm0jq4kwW1DPpqhmxlW4yC4TT/4oVebmqw/yCPjWcFUZM51g=
> Received: by 10.38.79.42 with SMTP id c42mr1051757rnb;
>        Wed, 30 Mar 2005 19:34:28 -0800 (PST)
> Received: by 10.38.11.45 with HTTP; Wed, 30 Mar 2005 19:34:27 -0800 (PST)
> Message-ID: <5c...@mail.gmail.com>
> Date: Thu, 31 Mar 2005 09:04:27 +0530
> From: Vineet Chopra <in...@gmail.com>
> Reply-To: Vineet Chopra <in...@gmail.com>
> To: tomcat-user-sc.1112239606.nogdkcacncmfjpiepdpf-incivincis=gmail.com@jakarta.apache.org
> Subject: Re: confirm subscribe to tomcat-user@jakarta.apache.org
> In-Reply-To: <11...@jakarta.apache.org>
> Mime-Version: 1.0
> Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
> References: <11...@jakarta.apache.org>
> X-Virus-Checked: Checked
>
> On 31 Mar 2005 03:26:46 -0000, tomcat-user-help@jakarta.apache.org
> <to...@jakarta.apache.org> wrote:
> > Hi! This is the ezmlm program. I'm managing the
> > tomcat-user@jakarta.apache.org mailing list.
> >
> > I'm working for my owner, who can be reached
> > at tomcat-user-owner@jakarta.apache.org.
> >
> > To confirm that you would like
> >
> >   incivincis@gmail.com
> >
> > added to the tomcat-user mailing list, please send
> > an empty reply to this address:
> >
> >   tomcat-user-sc.1112239606.nogdkcacncmfjpiepdpf-incivincis=gmail.com@jakarta.apache.org
> >
> > Usually, this happens when you just hit the "reply" button.
> > If this does not work, simply copy the address and paste it into
> > the "To:" field of a new message.
> >
> > or click here:
> >        mailto:tomcat-user-sc.1112239606.nogdkcacncmfjpiepdpf-incivincis=gmail.com@jakarta.apache.org
> >
> > This confirmation serves two purposes. First, it verifies that I am able
> > to get mail through to you. Second, it protects you in case someone
> > forges a subscription request in your name.
> >
> > Some mail programs are broken and cannot handle long addresses. If you
> > cannot reply to this request, instead send a message to
> > <to...@jakarta.apache.org> and put the
> > entire address listed above into the "Subject:" line.
> >
> > --- Administrative commands for the tomcat-user list ---
> >
> > I can handle administrative requests automatically. Please
> > do not send them to the list address! Instead, send
> > your message to the correct command address:
> >
> > To subscribe to the list, send a message to:
> >   <to...@jakarta.apache.org>
> >
> > To remove your address from the list, send a message to:
> >   <to...@jakarta.apache.org>
> >
> > Send mail to the following for info and FAQ for this list:
> >   <to...@jakarta.apache.org>
> >   <to...@jakarta.apache.org>
> >
> > Similar addresses exist for the digest list:
> >   <to...@jakarta.apache.org>
> >   <to...@jakarta.apache.org>
> >
> > To get messages 123 through 145 (a maximum of 100 per request), mail:
> >   <to...@jakarta.apache.org>
> >
> > To get an index with subject and author for messages 123-456 , mail:
> >   <to...@jakarta.apache.org>
> >
> > They are always returned as sets of 100, max 2000 per request,
> > so you'll actually get 100-499.
> >
> > To receive all messages with the same subject as message 12345,
> > send an empty message to:
> >   <to...@jakarta.apache.org>
> >
> > The messages do not really need to be empty, but I will ignore
> > their content. Only the ADDRESS you send to is important.
> >
> > You can start a subscription for an alternate address,
> > for example "john@host.domain", just add a hyphen and your
> > address (with '=' instead of '@') after the command word:
> > <to...@jakarta.apache.org>
> >
> > To stop subscription for this address, mail:
> > <to...@jakarta.apache.org>
> >
> > In both cases, I'll send a confirmation message to that address. When
> > you receive it, simply reply to it to complete your subscription.
> >
> > If despite following these instructions, you do not get the
> > desired results, please contact my owner at
> > tomcat-user-owner@jakarta.apache.org. Please be patient, my owner is a
> > lot slower than I am ;-)
> >
> > --- Enclosed is a copy of the request I received.
> >
> > Return-Path: <in...@gmail.com>
> > Received: (qmail 96729 invoked by uid 99); 31 Mar 2005 03:26:46 -0000
> > X-ASF-Spam-Status: No, hits=2.0 required=10.0
> >        tests=DNS_FROM_RFC_ABUSE,MISSING_SUBJECT,RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS
> > X-Spam-Check-By: apache.org
> > Received-SPF: pass (hermes.apache.org: domain of incivincis@gmail.com designates 64.233.170.205 as permitted sender)
> > Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.205)
> >  by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 30 Mar 2005 19:26:45 -0800
> > Received: by rproxy.gmail.com with SMTP id j1so269786rnf
> >        for <to...@jakarta.apache.org>; Wed, 30 Mar 2005 19:26:43 -0800 (PST)
> > DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
> >        s=beta; d=gmail.com;
> >        h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding;
> >        b=Eu28T/W3MjcrY7xK1v+7hR+odWbwwVGnkFIHlbmU579ys3LZS28vPOFLAOi+XEw7G0RQu7OLfU8jRK9o5wAfTjNrmWvgHp9gSRIsAsGFVSt7klsp88VsiGF/Cfj/1Wur/D/1gCA0DqAmex46h+UGSo8dTac5nUHuLhV2IiOuvdk=
> > Received: by 10.38.203.29 with SMTP id a29mr1060151rng;
> >        Wed, 30 Mar 2005 19:26:43 -0800 (PST)
> > Received: by 10.38.11.45 with HTTP; Wed, 30 Mar 2005 19:26:43 -0800 (PST)
> > Message-ID: <5c...@mail.gmail.com>
> > Date: Thu, 31 Mar 2005 08:56:43 +0530
> > From: Vineet Chopra <in...@gmail.com>
> > Reply-To: Vineet Chopra <in...@gmail.com>
> > To: tomcat-user-subscribe@jakarta.apache.org
> > Subject:
> > Mime-Version: 1.0
> > Content-Type: text/plain; charset=ISO-8859-1
> > Content-Transfer-Encoding: 7bit
> > X-Virus-Checked: Checked
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Closed Input Stream across firewall

Posted by Tim Funk <fu...@joedog.org>.
My only guess is the firewall times the connection out on inactivity. So if 
the servlet needs to do additional processing before the response is sent and 
the time is too long - the firewall might drop the connection.

-Tim

Vineet Chopra wrote:

> I am not calling getParameter method, instead request.getInputStream()
> to read the incoming XML is the first line of code after a few logging
> statements.
> 
> Code for the sender servlet is as follows - 
> 
> URL url = new URL(destinationURL);
> URLConnection conn = url.openConnection();	
> conn.setDoInput(true);
> conn.setDoOutput(true);
> PrintWriter writer = new PrintWriter(conn.getOutputStream());
> writer.println(data.toString());
> writer.flush();
> writer.close();
> 		
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(conn.getInputStream()));
> 
> String aLine;
> StringBuffer strBuf = null;
> if(reader!=null){
>           strBuf = new StringBuffer();
>           while( (aLine = reader.readLine() )!= null){
>                strBuf.append(readline);
>           }
>           reader.close();
> }
> 
> Code for the receiver servlet - 
> 
> protected void doGet(HttpServletRequest request,HttpServletResponse
> response) throws ServletException, IOException {
> StringBuffer xmlData = new StringBuffer("");
> try{
> 
> BufferedReader reader=new BufferedReader(new
> InputStreamReader(request.getInputStream()));
> 
> String aLine = "";
> while((aLine=reader.readLine())!=null){
>              xmlData.append(aLine);
> }
> 
> //exception thrown here.
> reader.close();
> 		
> PrintWriter writer = null;
> String rmessage = null;
> 		
> //build responseXML and assigned to rmessage
> 		
> if(rmessage!=null){
> writer = new PrintWriter(response.getOutputStream());
> writer.println(rmessage);
> writer.flush();
> writer.close();
> }
> }catch(Exception exp){
> exp.printStackTrace();	
> }
> }
> 
> -------------------------------------------------------
> It all started with getting an IOException: Cannot close the same
> input stream twice at line statement : reader.close(). This was raised
> because we were using Tomcat 4.0 which uses the deprecated http
> connector.
> 
> But the root of the problem is that the ServletInputStream itself is
> closed, even before building a InputStreamReader object.
> 
> Dilemma is that alls working well in the development environment and
> only production is giving the problem, thus suspected the firewall.
> 
> 
> 
> On Mar 31, 2005 5:02 PM, Tim Funk <fu...@joedog.org> wrote:
> 
>>The firewall is not the problem. If you are using
>>ServletRequest.getInputStream() - you cannot use
>>ServletRequest.getParameter(). Odds are something is calling getParameter()
>>which in turn getParameter() reads the input stream and makes it unavailable.
>>
>>-Tim
>>
>>Vineet Chopra wrote:
>>
>>>I am using a web application deployed on Tomcat 4.0 to receive and
>>>route incoming XML messages to destination web application
>>>also deployed on Tomcat 4.0. A firewall exists between these servers.
>>>All firewall policies are enabled for incoming and outgoing traffic.
>>>
>>>The ServletInputStream is already closed before I use it to create an
>>>object of InputStreamReader. Thus I am not able to read the stream.
>>>
>>>I did a snoop on the ports of these server which displayed the relay
>>>of request XML reaching the destination port and invoking the servlet
>>>in the
>>>destination web application but failing to read the XML since the
>>>input stream has been closed.
>>>
>>>Can you give me any leads as to how to debug the problem.
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Closed Input Stream across firewall

Posted by Vineet Chopra <in...@gmail.com>.
I am not calling getParameter method, instead request.getInputStream()
to read the incoming XML is the first line of code after a few logging
statements.

Code for the sender servlet is as follows - 

URL url = new URL(destinationURL);
URLConnection conn = url.openConnection();	
conn.setDoInput(true);
conn.setDoOutput(true);
PrintWriter writer = new PrintWriter(conn.getOutputStream());
writer.println(data.toString());
writer.flush();
writer.close();
		
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));

String aLine;
StringBuffer strBuf = null;
if(reader!=null){
          strBuf = new StringBuffer();
          while( (aLine = reader.readLine() )!= null){
               strBuf.append(readline);
          }
          reader.close();
}

Code for the receiver servlet - 

protected void doGet(HttpServletRequest request,HttpServletResponse
response) throws ServletException, IOException {
StringBuffer xmlData = new StringBuffer("");
try{

BufferedReader reader=new BufferedReader(new
InputStreamReader(request.getInputStream()));

String aLine = "";
while((aLine=reader.readLine())!=null){
             xmlData.append(aLine);
}

//exception thrown here.
reader.close();
		
PrintWriter writer = null;
String rmessage = null;
		
//build responseXML and assigned to rmessage
		
if(rmessage!=null){
writer = new PrintWriter(response.getOutputStream());
writer.println(rmessage);
writer.flush();
writer.close();
}
}catch(Exception exp){
exp.printStackTrace();	
}
}

-------------------------------------------------------
It all started with getting an IOException: Cannot close the same
input stream twice at line statement : reader.close(). This was raised
because we were using Tomcat 4.0 which uses the deprecated http
connector.

But the root of the problem is that the ServletInputStream itself is
closed, even before building a InputStreamReader object.

Dilemma is that alls working well in the development environment and
only production is giving the problem, thus suspected the firewall.



On Mar 31, 2005 5:02 PM, Tim Funk <fu...@joedog.org> wrote:
> The firewall is not the problem. If you are using
> ServletRequest.getInputStream() - you cannot use
> ServletRequest.getParameter(). Odds are something is calling getParameter()
> which in turn getParameter() reads the input stream and makes it unavailable.
> 
> -Tim
> 
> Vineet Chopra wrote:
> > I am using a web application deployed on Tomcat 4.0 to receive and
> > route incoming XML messages to destination web application
> > also deployed on Tomcat 4.0. A firewall exists between these servers.
> > All firewall policies are enabled for incoming and outgoing traffic.
> >
> > The ServletInputStream is already closed before I use it to create an
> > object of InputStreamReader. Thus I am not able to read the stream.
> >
> > I did a snoop on the ports of these server which displayed the relay
> > of request XML reaching the destination port and invoking the servlet
> > in the
> > destination web application but failing to read the XML since the
> > input stream has been closed.
> >
> > Can you give me any leads as to how to debug the problem.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Closed Input Stream across firewall

Posted by Tim Funk <fu...@joedog.org>.
The firewall is not the problem. If you are using 
ServletRequest.getInputStream() - you cannot use 
ServletRequest.getParameter(). Odds are something is calling getParameter() 
which in turn getParameter() reads the input stream and makes it unavailable.

-Tim

Vineet Chopra wrote:
> I am using a web application deployed on Tomcat 4.0 to receive and
> route incoming XML messages to destination web application
> also deployed on Tomcat 4.0. A firewall exists between these servers.
> All firewall policies are enabled for incoming and outgoing traffic.
> 
> The ServletInputStream is already closed before I use it to create an
> object of InputStreamReader. Thus I am not able to read the stream.
> 
> I did a snoop on the ports of these server which displayed the relay
> of request XML reaching the destination port and invoking the servlet
> in the
> destination web application but failing to read the XML since the
> input stream has been closed.
> 
> Can you give me any leads as to how to debug the problem.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org