tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk.Din...@netformfive.de
Subject servlet-chaining problem
Date Wed, 30 Jan 2002 14:58:09 GMT

Hi !

I have the following scenario:

Servet A :    performs a synchronous call to another servlet B, located at
some other server.
                      Servlet B produces binary output, that may be further
processed or directly
                      routed back to the browser (as shown in the code
example).

     URL url = new URL("<url to servlet B with arguments>");

     URLConnection connection = url.openConnection();
     BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
     OutputStream f = response.getOutputStream();
     int a=0;
     while ( (a=in.read()) != -1 )
      {
         f.write(a);
      }
      in.close();
      f.close();


Servlet B:   performs some businesslogic, using server B's local
ressources.
           In this exaple an MS-Excel Document is generated and returned as
binary data.

        response.setContentType("application/x-msexcel");

          ... some action that produces File excel;
          File excel= new File(....)

          OutputStream f = response.getOutputStream();

           BufferedInputStream bis = new BufferedInputStream (new
FileInputStream(excel));
           int a=0;
           while ( (a=bis.read()) != -1 )
           {
              f.write(a);
           }
           bis.close();
           f.close();

problem/question:

If I use the URL of B directly, the generated excel-doc is displayed
correcty
If I modify Servlet B to return standard HTML/Text Output and call Servlet
A, everything works fine all well.

But: if i use the combination as shown in the code, after calling servlet
A, excel pop's up but immediately
crashes. So i suppose there is something going wrong with the binary output
of servlet B ?

Any help appreceated,

Regards,
Dirk


--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message