-
April 21st, 2010, 05:33 AM
#1
Applet-Servlet Communication EOFException
Hi! i´ve been searching and searching through forums because it seems this problem is very common, but none of the solutions i´ve seen so far suits me, so i´m here looking for some help because i´ve been stuck one week with this. First of all sorry if my english isn´t the best... i´m a bit rusty...
Well, i had some code that worked perfectly, but i needed to perform some changes because i needed the servlet to send more info to the applet, and here started the problems, when i made the changes it started to throw EOFException when i was trying to read the InputStream, and furthermore when i came back to the original code it started to throw the exception in the same place too :banghead:
So here i am... don´t know what to do now and i entrust to you to give me some tips.
Here comes some code.
Applet:
Code:
public ListasComponentesSeleccionables cargarListasComponentes( ) throws IOException, ClassNotFoundException {
String serv = "/Desaladora/cargarListasComponentesApplet.do";
String host = Principal.documentBase.getHost( );
URL direccion = new URL( "http", host, 8080, serv );
// Create conection
URLConnection connection = direccion.openConnection( );
connection.setDoInput( true );
connection.setDoOutput( true );
connection.setUseCaches( false );
connection.setRequestProperty( "Content-Type", "application/x-java-serialized-object" );
ObjectOutputStream output;
output = new ObjectOutputStream( connection.getOutputStream( ) );
output.writeObject( new Boolean(true) );
output.flush( );
output.close( );
ObjectInputStream input = new ObjectInputStream( connection.getInputStream( ) ); //<-- Here is the problem
ListasComponentesSeleccionables response = new ListasComponentesSeleccionables( );
response = ( ListasComponentesSeleccionables ) input.readObject( );
return response;
}
Servlet:
Code:
public class CargarListasComponentesAppletAction extends Action {
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response ) throws ServletException, IOException, Exception {
InitialContext context = new InitialContext();
SensorManagerService sensor_service;
ActuatorManagerService actuator_service;
Globals.LOGGER_SECURITY.debug( "Entering ACTION 'CargarListasComponentesAppletAction'" );
response.setContentType("application/x-java-serialized-object");
try
{
ObjectInputStream bufferentrada = new ObjectInputStream(request.getInputStream());
Boolean peticionOK = (Boolean)bufferentrada.readObject();
ObjectOutputStream buffersalida = new ObjectOutputStream(response.getOutputStream());
sensor_service = ( SensorManagerService ) context.lookup( "desaladora/SensorManagerServiceBean/local" );
ArrayList<AlarmConnectedSensorDTO> sensorList = sensor_service.findAllSensorsToAlarms();
actuator_service = ( ActuatorManagerService ) context.lookup( "desaladora/ActuatorManagerServiceBean/local" );
ArrayList<AlarmConnectedActuatorDTO> actuatorList = actuator_service.findAllActuatorsToAlarms();
buffersalida.writeObject( crearListasSeleccionables(sensorList, actuatorList) );
buffersalida.flush();
}
catch(Exception e)
{
System.out.println("Error en la trasmision de datos");
}
return null;
}
private ListasComponentesSeleccionables crearListasSeleccionables(ArrayList<AlarmConnectedSensorDTO> sensorList, ArrayList<AlarmConnectedActuatorDTO> actuatorList) {
Vector<Integer> vectorSensores = new Vector<Integer>();
Vector<Integer> vectorActuadores = new Vector<Integer>();
for(AlarmConnectedSensorDTO sensor : sensorList) {
vectorSensores.add(sensor.getIdSensor( ));
}
for(AlarmConnectedActuatorDTO actuator : actuatorList) {
vectorActuadores.add(actuator.getIdActuator( ));
}
ListasComponentesSeleccionables listasComponentesSeleccionables = new ListasComponentesSeleccionables(vectorSensores, vectorActuadores);
return listasComponentesSeleccionables;
}
}
Thank you for your time
-
April 21st, 2010, 07:12 AM
#2
Re: Applet-Servlet Communication EOFException
i´ve been running some test in another computer, and that code simply works, but it doesn´t work in the machine i usually work.
Maybe someway the stream get corrupt? the info i´ve been trying to send and started throwing the exception may still be in the stream? I don´t know what to think right now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|