Name: rlT66838 Date: 11/11/99
Currently I'm working on WinNT4.0 (build 1381, Service Pack 3) with JDK 1.1.8
using JRE1.2.1 / 1.2.2 Plugin.
Web Server : Netscape Enterprise Server 4.6
Servlet engine : JRun vers. 2.3.3 (with build 153 )
Our applet is trying to send a String, int and bytearray to the servlet.
IOException occurs at the servlet side when it is trying to read int from the applet.
But this works well without using the plugin when running on Netscape.
Similar problem occurs too when using the plugin on either Netscape 4.51 and IE4.0.
The code of the sample applet, TestApplet.java :
--------------------------------------------------------------------------------
import java.util.*;
import java.net.*;
import java.applet.Applet;
import java.io.*;
public class TestApplet extends Applet{
public void init(){
System.out.println("-- TestApplet init");
}
public void start(){
try{
String servletURL = getParameter("URL");
URL url = new URL(servletURL);
System.out.println("-- Opening connection to " + servletURL + "servlet");
URLConnection urlCon = url.openConnection();
urlCon.setDoOutput(true);
System.out.println("-- Getting output stream");
OutputStream os = urlCon.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
// preparing the bytrearray to send across
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 100; i++)
sb.append("Testing");
oos.writeObject(sb.toString());
oos.flush(); // flush to the underlying ByteArrayStream
byte[] reqByteArray = baos.toByteArray();
int size = reqByteArray.length;
System.out.println("-- Applet writing String to servlet (1)");
dos.writeUTF("TESTING1");
System.out.println("-- Applet writing int to servlet (1)");
dos.writeInt(size);
System.out.println("-- Applet writing byte array to servlet (1)");
dos.write(reqByteArray, 0, size); // write the byte array
System.out.println("-- Applet writing String to servlet (2)");
dos.writeUTF("TESTING2");
System.out.println("-- Applet writing int to servlet (2)");
dos.writeInt(size);
System.out.println("-- Applet writing byte array to servlet (2)");
dos.write(reqByteArray, 0, size); // write the byte array
dos.flush();
InputStream is = urlCon.getInputStream();
DataInputStream dis = new DataInputStream(is);
int intResult = dis.readInt();
dos.close();
dis.close();
}catch(Exception e){
System.out.println("Exception occurs ....");
e.printStackTrace();
}
}
} //end class
--------------------------------------------------------------------------------
The code of the servlet, TestServlet.java :
--------------------------------------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet {
public void init(){
System.out.println("TestServlet - init ");
}
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try{
System.out.println("TestServlet - service");
InputStream is = req.getInputStream();
DataInputStream dis = new DataInputStream(is);
String data = dis.readUTF();
System.out.println("TestServlet reading String from applet :" + data);
int size = dis.readInt();
System.out.println("TestServlet reading int from applet :" + size);
byte[] block = null;
if (size > 0){
System.out.println("byte array size > 0");
block = new byte[size];
dis.readFully(block); // reads the section content
System.out.println("TestServlet reading byte array from applet (1) ");
}
System.out.println("size of byte array read(1) =" + block.length);
OutputStream os = res.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
System.out.println("TestServlet writing int to applet");
dos.writeInt(3); // writes the number
System.out.println("TestServlet flush");
System.out.println("-- Applet flush");
dos.flush();
dis.close();
dos.close();
}catch(IOException ioe){
System.out.println(" ~ IOException occurs in servlet ~");
ioe.printStackTrace();
throw new IOException();
}catch(Exception e){
System.out.println(" ~ Exception occurs in servlet ~");
e.printStackTrace();
throw new IOException();
}
}
}
--------------------------------------------------------------------------------
The exception occurs while reading int from the applet as shown below in the JRun Servlet standard error log, stderr.log :
**********************************************************************************
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:363)
at TestServlet.service(TestServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.livesoftware.jrun.JRun.runServlet(Compiled Code)
at com.livesoftware.jrun.JRunGeneric.handleConnection(JRunGeneric.java:116)
at com.livesoftware.jrun.JRunGeneric.handleProxyConnection(JRunGeneric.java:78)
at com.livesoftware.jrun.service.proxy.JRunProxyServiceHandler.handleRequest(JRunProxyServiceHandler.java:102)
at com.livesoftware.jrun.service.ThreadConfigHandler.run(Compiled Code)
***********************************************************************************
And output from the servlet as recoreded in the JRun stdout.log :
***********************************************************************************
TestServlet - service
TestServlet reading String from applet (1) :TESTING1
IOException occurs in servlet
***********************************************************************************
The printout from the Plugin console is shown as below :
***********************************************************************************
Java(TM) Plug-in
Using JRE version 1.2.1
User home directory = C:\WINDOWS
Proxy Configuration: no proxyJAR cache disabled.
Opening http://192.168.11.92:90/secured/TestApplet.class no proxy
No holding
CacheHandler trying caching. http://192.168.11.92:90/secured/TestApplet.class
CacheHandler file name: C:\Program Files\Netscape\Users\kyong\cache\M0U0KO1C.CLA
Got cached copy
-- TestApplet init
-- Opening connection to http://192.168.11.92:90/servlet/TestServlet servlet
-- Getting output stream
Opening http://192.168.11.92:90/servlet/TestServlet no proxy
-- Applet writing String to servlet (1)
-- Applet writing int (size of byte array) to servlet (1)
-- Applet writing byte array to servlet (1)
-- Applet writing String to servlet (2)
-- Applet writing int (size of byte array) to servlet (2)
-- Applet writing byte array to servlet (2)
-- Applet flush
Exception occurs ....
java.io.FileNotFoundException: http://192.168.11.92:90/servlet/TestServlet
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Compiled Code)
at
sun.plugin.protocol.jdk12.http.HttpURLConnection.getInputStream(HttpURLConnection.java:222)
at TestApplet.start(Compiled Code)
at sun.applet.AppletPanel.run(Compiled Code)
at java.lang.Thread.run(Thread.java:479)
****************************************************************************************
(Review ID: 93949)
======================================================================