Hi, list:
I'm running a web application hosted in Tomcat 4.1,
with IIS redirector enabled. There has been no problem
with jsp browsing so far, but I have a serious problem
when posting binary data to a servlet in this
environment. Basically, a random 36byte sequence is
inserted near 56k in the data stream, which corrupts
the data received from POST. I have setup a test
environment to reproduce the problem as follows:
((Test Environment))
Win2000 Server SP4
IIS 5.0.2195.6700
J2SDK 1.4.1_02
Tomcat 4.1.27
iis_redirector.dll 2.0.2 and 2.0.1
((jk2.properties))
No setting, all comments, same as the one from the
Tomcat installation
((workers2.properties))
[logger.file:0]
# level: EMERG or ERROR or INFO or DEBUG
level=DEBUG
file=${serverRoot}/logs/jk2.log
[shm:]
info=Scoreboard. Required for reconfiguration and
status with multiprocess servers
file=${serverRoot}/logs/jk2.shm
size=1048576
debug=5
# Define the communication channel
[channel.socket:localhost:8009]
info=Ajp13 forwarding over socket
tomcatId=localhost:8009
debug=5
# Map the Tomcat examples webapp to the Web server uri
space
[uri:/examples/*]
info=Map the whole webapp
debug=5
((examples context web.xml))
...
<servlet>
<servlet-name>BinaryPostTest</servlet-name>
<servlet-class>test.BinaryPostServlet</servlet-class>
</servlet>
...
<servlet-mapping>
<servlet-name>BinaryPostTest</servlet-name>
<url-pattern>/posttest</url-pattern>
</servlet-mapping>
((test.BinaryPostServlet))
package test;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BinaryPostServlet
extends HttpServlet
{
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>" + "Binary post test servlet" +
"</title>");
out.println("</head>");
out.println("<body>");
out.println("Please post data to this servlet, with
entity header 'File-Name'");
out.println("</body>");
out.println("</html>");
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String fileName = request.getHeader("File-Name");
if(fileName == null)
fileName = "file" + System.currentTimeMillis() +
".dat";
fileName = "C:/temp/" + fileName;
FileOutputStream fout = new
FileOutputStream(fileName, false);
InputStream in = request.getInputStream();
byte[] buffer = new byte[1024];
int read = in.read(buffer, 0, buffer.length);
while(read != -1)
{
fout.write(buffer, 0, read);
read = in.read(buffer, 0, buffer.length);
}
fout.close();
in.close();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>" + "Binary post test servlet" +
"</title>");
out.println("</head>");
out.println("<body>");
out.println("File saved to " + fileName);
out.println("</body>");
out.println("</html>");
}
}
((Java application who does the POST))
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.HttpURLConnection;
public class BinaryPostTester
{
public static void main(String[] args)
{
try
{
if(args.length != 2)
{
System.out.println("Usage: java
test.BinaryPostTester FilePathName URL");
return;
}
File file = new File(args[0]);
URL url = new URL(args[1]);
HttpURLConnection conn =
(HttpURLConnection)url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("File-Name",
file.getName());
conn.setRequestProperty("Content-Type",
"application/octet-stream");
conn.setRequestProperty("Content-Length",
String.valueOf(file.length()));
conn.setRequestMethod("POST");
conn.connect();
System.out.println("Connected to " + url);
OutputStream out = conn.getOutputStream();
FileInputStream fin = new FileInputStream(file);
byte[] buffer = new byte[1024];
int read = fin.read(buffer, 0, buffer.length);
while(read != -1)
{
out.write(buffer, 0, read);
read = fin.read(buffer, 0, buffer.length);
}
out.close();
fin.close();
System.out.println("Response Code is: " +
conn.getResponseCode());
System.out.println("Response is: " +
conn.getResponseMessage());
conn.disconnect();
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}
((File to POST))
server/lib/tomcat-util.jar from the Tomcat 4.1.27
installation
((Test Procedure))
1. Setup iis_redirector.dll per JK2 documentation
2. Compile the servlet and the tester
3. Install the servlet to the examples context
4. Test "http://servername:8080/examples/posttest" to
make sure the servlet is installed properly
5. Test "http://servername:80/examples/posttest" to
make sure IIS redirector is working
6. Run tester with file tomcat-util.jar and url
"http://servername:80/examples/posttest", the servlet
should receive the data and write them to a file under
C:/Temp directory in the server
7. Compare the original file with the file uploaded to
the server, in my case, the uploaded file has a 36byte
sequence inserted at 56940, which makes the two files
different.
((Logs))
I probably messed up the JK2's log configuration,
since no log entry is written to the jk2.log, but in
my production environment (Win2000 Server SP2, IIS
5.0.2195.6670, J2SDK 1.4.1_01, Tomcat 4.1.18,
iis_redirector.dll 2.0.2) I was able to get the logs
working. Here's the entries concerning the upload
process:
[Thu Aug 07 15:59:50 2003] (debug ) [jk_isapi_plugin.c
(473)] HttpExtensionProc started
[Thu Aug 07 15:59:50 2003] (debug ) [jk_isapi_plugin.c
(482)] HttpExtensionProc got a worker for name
ajp13:localhost:8009
[Thu Aug 07 15:59:50 2003] (debug ) [jk_isapi_plugin.c
(497)] HttpExtensionProc: new rpool
[Thu Aug 07 15:59:50 2003] ( info ) [jk_endpoint.c
(95)] workerEnv.init() create slot epStat.0
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 6 getChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 4 sendHeaders
[Thu Aug 07 15:59:50 2003] (debug )
[jk_handler_response.c (155)] handler.response()
Header[0] [Content-Type] = [text/html]
[Thu Aug 07 15:59:50 2003] (debug )
[jk_handler_response.c (155)] handler.response()
Header[1] [Content-Length] = [128]
[Thu Aug 07 15:59:50 2003] (debug )
[jk_handler_response.c (172)] handler.response():
status=200 headers=2
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(93)] Into jk_ws_service_t::head
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 3 sendChunk
[Thu Aug 07 15:59:50 2003] (debug ) [jk_service_iis.c
(227)] Into jk_ws_service_t::write
[Thu Aug 07 15:59:50 2003] (debug ) [jk_workerEnv.c
(430)] workerEnv.dispatch() Calling 5 endResponse
[Thu Aug 07 15:59:50 2003] (debug ) [jk_isapi_plugin.c
(515)] HttpExtensionProc service() returned OK
This is the first upload I did after IIS restart, if I
try a second upload, I usually get this error in the
log:
[Thu Aug 07 15:50:53 2003] (debug ) [jk_isapi_plugin.c
(473)] HttpExtensionProc started
[Thu Aug 07 15:50:53 2003] (debug ) [jk_isapi_plugin.c
(482)] HttpExtensionProc got a worker for name
ajp13:localhost:8009
[Thu Aug 07 15:50:53 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:52:08 2003] (error ) [jk_worker_ajp13.c
(389)] ajp13.service() Error sending initial post -1
0 0
[Thu Aug 07 15:50:53 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
[Thu Aug 07 15:50:53 2003] (debug ) [jk_service_iis.c
(168)] Into jk_ws_service_t::read
......
The file still got uploaded, and is corrupted as
before.
OK that's all the information I have right now, before
I finish this super long message, I should mention
that I have searched the list for similar problems,
and found a very similar problem is reported by Joakim
Strom on 2002-12-02 in the post "Large files corrupted
-- possible bug in isapi_redirector2.dll?", however no
one replied to his message.
Jim
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]