AW: Hi Ho - Problem with ServletOutputStream in Tomcat
Ok thx for all your help - i found the problem - or more correct i read the infos a 10th time about InputStreamReader - and now i found the info about conversion of the characters -- i am veerrryy blind thx Wolfgang Kremser -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Gesendet: Freitag, 16. Februar 2001 09:12 An: [EMAIL PROTECTED] Betreff: AW: Hi Ho - Problem with ServletOutputStream in Tomcat well i use a HTTPUrlConnection - and theres a getInputStream method which brings me my inputstream. I dont see any info about char-conversion with this method here's the missing code snippet --- InputStreamReader brInput = new InputStreamReader(HttpUrlCon.getInputStream()); --- greetings Wolfgang -Ursprüngliche Nachricht- Von: Randy Layman [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 14. Februar 2001 16:28 An: [EMAIL PROTECTED] Betreff: RE: Hi Ho - Problem with ServletOutputStream in Tomcat What kind of translation is happening? Are you getting a few extra bytes here and there, are all (or some) shifting by a few bits? Just guess - I don't see where you get your inpustream, make sure that you aren't using a stream that expects to work with characters and is doning some form of character translation. (Any class that has a readLine or readString method is suspect to fiddling with the bytes). Randy -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 8:39 AM To: [EMAIL PROTECTED] Subject: AW: Hi Ho - Problem with ServletOutputStream in Tomcat thx for your info i used write but my next problem is that the binary content gets somehow translated and isnt the same as before - for example gif images arent displayed correctly --- pdf are displayed wrong -- and so on ... well i dont have a clue why. greetings Wolfgang -Ursprüngliche Nachricht- Von: Samson, Lyndon [IT] [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 14. Februar 2001 14:32 An: '[EMAIL PROTECTED]' Betreff: RE: Hi Ho - Problem with ServletOutputStream in Tomcat This is true, I wrote a multipart/form-data parser and the only character set which preserved binary data was ISO-8859-1. Conversions between bytes and characters only work with this encType, your input and output should both use this if you use characters to store binary data. Output streams are supposed to output bytes, the print in the ServletOutputStream method converts a char to a byte array, you'd be better off using the write(byte[] b) method of the base OutputStream class. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 12:45 PM To: [EMAIL PROTECTED] Subject: Hi Ho - Problem with ServletOutputStream in Tomcat I ve created an Servlet that routes Requests and Responses to and from another Server. When i try to get a Image through this Servlet i get an Error 500. I coded the app as described in the j2ee docu for sending binary data. maybee a little code snipplet and the error trace helps to understand http://127.0.0.1:8080/maria/portal/zmr/javalogo52x88.gif this is the url -- http://127.0.0.1:8080 - is my Tomcat instance /maria/portal - is my proxy servlet /zmr/javalogo52x88.gif is the image i want to display in my browser -> but /zmr is another webapplication on another tomcat server heres the code for the binary data receiving and sending to the client // Setting the Headers for the Client same as the Servlet received them from the other server while ((strHeaderKey = HttpUrlCon.getHeaderFieldKey(iCounter)) != null) { strHeaderValue = HttpUrlCon.getHeaderField(iCounter); LogIt("ResponseHeader - Value: " + strHeaderKey + " - " + strHeaderValue); response.setHeader(strHeaderKey,strHeaderValue); iCounter +=1; } // figuring out which type of data the servlet is getting if (HttpUrlCon.getContentType().equals("text/html")) { // Text or HTML -> thats where i use the PrintWriter PrintWriter out = response.getWriter(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } else { try { // Everything else assuming its binary data so i use ServletOutputStream ServletOutputStream out = ((ServletResponse)response).getOutputStream(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } catch (IOException e) { this.log("IOException !!",e); } } heres the
AW: Hi Ho - Problem with ServletOutputStream in Tomcat
well i use a HTTPUrlConnection - and theres a getInputStream method which brings me my inputstream. I dont see any info about char-conversion with this method here's the missing code snippet --- InputStreamReader brInput = new InputStreamReader(HttpUrlCon.getInputStream()); --- greetings Wolfgang -Ursprüngliche Nachricht- Von: Randy Layman [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 14. Februar 2001 16:28 An: [EMAIL PROTECTED] Betreff: RE: Hi Ho - Problem with ServletOutputStream in Tomcat What kind of translation is happening? Are you getting a few extra bytes here and there, are all (or some) shifting by a few bits? Just guess - I don't see where you get your inpustream, make sure that you aren't using a stream that expects to work with characters and is doning some form of character translation. (Any class that has a readLine or readString method is suspect to fiddling with the bytes). Randy -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 8:39 AM To: [EMAIL PROTECTED] Subject: AW: Hi Ho - Problem with ServletOutputStream in Tomcat thx for your info i used write but my next problem is that the binary content gets somehow translated and isnt the same as before - for example gif images arent displayed correctly --- pdf are displayed wrong -- and so on ... well i dont have a clue why. greetings Wolfgang -Ursprüngliche Nachricht- Von: Samson, Lyndon [IT] [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 14. Februar 2001 14:32 An: '[EMAIL PROTECTED]' Betreff: RE: Hi Ho - Problem with ServletOutputStream in Tomcat This is true, I wrote a multipart/form-data parser and the only character set which preserved binary data was ISO-8859-1. Conversions between bytes and characters only work with this encType, your input and output should both use this if you use characters to store binary data. Output streams are supposed to output bytes, the print in the ServletOutputStream method converts a char to a byte array, you'd be better off using the write(byte[] b) method of the base OutputStream class. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 12:45 PM To: [EMAIL PROTECTED] Subject: Hi Ho - Problem with ServletOutputStream in Tomcat I ve created an Servlet that routes Requests and Responses to and from another Server. When i try to get a Image through this Servlet i get an Error 500. I coded the app as described in the j2ee docu for sending binary data. maybee a little code snipplet and the error trace helps to understand http://127.0.0.1:8080/maria/portal/zmr/javalogo52x88.gif this is the url -- http://127.0.0.1:8080 - is my Tomcat instance /maria/portal - is my proxy servlet /zmr/javalogo52x88.gif is the image i want to display in my browser -> but /zmr is another webapplication on another tomcat server heres the code for the binary data receiving and sending to the client // Setting the Headers for the Client same as the Servlet received them from the other server while ((strHeaderKey = HttpUrlCon.getHeaderFieldKey(iCounter)) != null) { strHeaderValue = HttpUrlCon.getHeaderField(iCounter); LogIt("ResponseHeader - Value: " + strHeaderKey + " - " + strHeaderValue); response.setHeader(strHeaderKey,strHeaderValue); iCounter +=1; } // figuring out which type of data the servlet is getting if (HttpUrlCon.getContentType().equals("text/html")) { // Text or HTML -> thats where i use the PrintWriter PrintWriter out = response.getWriter(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } else { try { // Everything else assuming its binary data so i use ServletOutputStream ServletOutputStream out = ((ServletResponse)response).getOutputStream(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } catch (IOException e) { this.log("IOException !!",e); } } heres the error trace i get when i try to process it - 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Content-Type - image/gif 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Content-Length - 1495 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Last-Modified - Tue, 13 Feb 2001 10:07:22 GMT 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader -
AW: Hi Ho - Problem with ServletOutputStream in Tomcat
ok thanx for your info -- i didnt notice that ServletOutputStream has a write method :) and about speed - its my first catch -- i ll improve speed after i know that this way works .) greetings Wolfgang Kremser -Ursprüngliche Nachricht- Von: Randy Layman [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 14. Februar 2001 13:48 An: [EMAIL PROTECTED] Betreff: RE: Hi Ho - Problem with ServletOutputStream in Tomcat I think your problem might be because you are trying to print bytes cast to characters. Try using the write method instead. Also, to get a speed up I would suggest reading and writing arrays of bytes at a time (maybe 500 to 2000 bytes) - it greatly reduces the number of system calls involved. Randy -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 7:45 AM To: [EMAIL PROTECTED] Subject: Hi Ho - Problem with ServletOutputStream in Tomcat I ve created an Servlet that routes Requests and Responses to and from another Server. When i try to get a Image through this Servlet i get an Error 500. I coded the app as described in the j2ee docu for sending binary data. maybee a little code snipplet and the error trace helps to understand http://127.0.0.1:8080/maria/portal/zmr/javalogo52x88.gif this is the url -- http://127.0.0.1:8080 - is my Tomcat instance /maria/portal - is my proxy servlet /zmr/javalogo52x88.gif is the image i want to display in my browser -> but /zmr is another webapplication on another tomcat server heres the code for the binary data receiving and sending to the client // Setting the Headers for the Client same as the Servlet received them from the other server while ((strHeaderKey = HttpUrlCon.getHeaderFieldKey(iCounter)) != null) { strHeaderValue = HttpUrlCon.getHeaderField(iCounter); LogIt("ResponseHeader - Value: " + strHeaderKey + " - " + strHeaderValue); response.setHeader(strHeaderKey,strHeaderValue); iCounter +=1; } // figuring out which type of data the servlet is getting if (HttpUrlCon.getContentType().equals("text/html")) { // Text or HTML -> thats where i use the PrintWriter PrintWriter out = response.getWriter(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } else { try { // Everything else assuming its binary data so i use ServletOutputStream ServletOutputStream out = ((ServletResponse)response).getOutputStream(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } catch (IOException e) { this.log("IOException !!",e); } } heres the error trace i get when i try to process it - 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Content-Type - image/gif 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Content-Length - 1495 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Last-Modified - Tue, 13 Feb 2001 10:07:22 GMT 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Servlet-Engine - Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0; Windows 2000 5.0 x86; java.vendor=Sun Microsystems Inc.) 2001-02-14 01:26:43 - path="/maria" :proxy: IOException !! - java.io.IOException: Not an ISO 8859_1 character:^ at org.apache.tomcat.core.BufferedServletOutputStream.print(BufferedServletOutp utStream.java:221) at javax.servlet.ServletOutputStream.print(ServletOutputStream.java:177) at at.gv.bmi.maria.proxy.ReturnData(proxy.java:201) at at.gv.bmi.maria.proxy.doGet(proxy.java:63) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404) at org.apache.tomcat.core.Handler.service(Handler.java:286) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79 7) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743) at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC onnectionHandler.java:210) at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416) at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498) at java.lang.Thread.run(Thread.java:484) please help me, its important and i dont know how to solve this proble
AW: Hi Ho - Problem with ServletOutputStream in Tomcat
thx for your info i used write but my next problem is that the binary content gets somehow translated and isnt the same as before - for example gif images arent displayed correctly --- pdf are displayed wrong -- and so on ... well i dont have a clue why. greetings Wolfgang -Ursprüngliche Nachricht- Von: Samson, Lyndon [IT] [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 14. Februar 2001 14:32 An: '[EMAIL PROTECTED]' Betreff: RE: Hi Ho - Problem with ServletOutputStream in Tomcat This is true, I wrote a multipart/form-data parser and the only character set which preserved binary data was ISO-8859-1. Conversions between bytes and characters only work with this encType, your input and output should both use this if you use characters to store binary data. Output streams are supposed to output bytes, the print in the ServletOutputStream method converts a char to a byte array, you'd be better off using the write(byte[] b) method of the base OutputStream class. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 14, 2001 12:45 PM To: [EMAIL PROTECTED] Subject: Hi Ho - Problem with ServletOutputStream in Tomcat I ve created an Servlet that routes Requests and Responses to and from another Server. When i try to get a Image through this Servlet i get an Error 500. I coded the app as described in the j2ee docu for sending binary data. maybee a little code snipplet and the error trace helps to understand http://127.0.0.1:8080/maria/portal/zmr/javalogo52x88.gif this is the url -- http://127.0.0.1:8080 - is my Tomcat instance /maria/portal - is my proxy servlet /zmr/javalogo52x88.gif is the image i want to display in my browser -> but /zmr is another webapplication on another tomcat server heres the code for the binary data receiving and sending to the client // Setting the Headers for the Client same as the Servlet received them from the other server while ((strHeaderKey = HttpUrlCon.getHeaderFieldKey(iCounter)) != null) { strHeaderValue = HttpUrlCon.getHeaderField(iCounter); LogIt("ResponseHeader - Value: " + strHeaderKey + " - " + strHeaderValue); response.setHeader(strHeaderKey,strHeaderValue); iCounter +=1; } // figuring out which type of data the servlet is getting if (HttpUrlCon.getContentType().equals("text/html")) { // Text or HTML -> thats where i use the PrintWriter PrintWriter out = response.getWriter(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } else { try { // Everything else assuming its binary data so i use ServletOutputStream ServletOutputStream out = ((ServletResponse)response).getOutputStream(); int iByte; while ((iByte = brInput.read()) != -1) { out.print((char) iByte); } } catch (IOException e) { this.log("IOException !!",e); } } heres the error trace i get when i try to process it - 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Content-Type - image/gif 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Content-Length - 1495 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Last-Modified - Tue, 13 Feb 2001 10:07:22 GMT 2001-02-14 01:26:43 - path="/maria" :proxy: ResponseHeader - Value: Servlet-Engine - Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0; Windows 2000 5.0 x86; java.vendor=Sun Microsystems Inc.) 2001-02-14 01:26:43 - path="/maria" :proxy: IOException !! - java.io.IOException: Not an ISO 8859_1 character:^ at org.apache.tomcat.core.BufferedServletOutputStream.print(BufferedServletOutp utStream.java:221) at javax.servlet.ServletOutputStream.print(ServletOutputStream.java:177) at at.gv.bmi.maria.proxy.ReturnData(proxy.java:201) at at.gv.bmi.maria.proxy.doGet(proxy.java:63) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404) at org.apache.tomcat.core.Handler.service(Handler.java:286) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79 7) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743) at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC onnectionHandler.java:210) at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:4