Serialize Applet to a web server via Servlet Problem

P

pcouas

Hi,

I try to Serialise an Applet on my WebServer, i convert Object to
ByteArray, before sending it to webserver.
There is 2050 bytes in byte array on my applet before sending it, and
2062 bytes in byte array on tomcat !

Where is my mistake ?
Regards
Philippe



Applet
void WriteApplet(String filename)
{
ObjectOutputStream out;
System.out.println("Debut Test WRITE APPLET...");

//Serialisation de la frame
try
{
String m_URL=new
String("http://172.16.0.101:8080/test/servlet/servletgraph.XXServlet");
String string4=m_URL;
System.out.println("w01 "+string4);

URL u=new URL(string4);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(this);
oos.flush();
oos.close();
byte b[] = baos.toByteArray();

HttpURLConnection urlc = (java.net.HttpURLConnection)
u.openConnection();
// Set the Post (true) or Get (false) method.
urlc.setDoOutput(true);
urlc.setDoInput(true);
urlc.setUseCaches(false);
urlc.setAllowUserInteraction(false);

urlc.setRequestProperty("Content-Type",
"application/octet-stream");

String lengthString = String.valueOf(baos.size());
urlc.setRequestProperty("Content-Length", lengthString);
System.out.println("Object is avant ecriture " + lengthString + "
bytes");

out = new ObjectOutputStream(urlc.getOutputStream());
out.write(b);

if (urlc.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("Error...");
} else {
System.out.println("I have now access to the stream...");
// blaha balaaha blaahahaha
}

out.flush();
out.close();
System.out.println("Fin Test WRITE APPLET...");
}
catch (IOException ioe) {
System.err.println(ioe);
ioe.printStackTrace();
}
}

-------------------------------------------------------------------------

Servlet
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
System.out.println("XXServlet doPost X1 "+new Date());
boolean debug=true;

InputStream in = req.getInputStream();
byte[] bufimage=null;
bufimage = new byte[4 * 1024]; // 4K buffer
int len;
RandomAccessFile f = new
java.io.RandomAccessFile(req.getRealPath("/")+"xxservlet", "rw");
int size = req.getIntHeader("content-length");
bufimage = new byte[size]; // 4K buffer
if(debug) System.out.println("XXServlet bytearray02 "+size);
int nb=0;
while ((len = in.read(bufimage, 0, bufimage.length)) != -1)
{
if(debug) System.out.println("XXServlet bytearray03
content-length "+len);
f.write(bufimage, 0, len); //Fichier
nb=+len;

}
if(debug) System.out.println("XXServlet bytearray05 "+nb);

f.close();

if(debug) System.out.println("XXServlet write04 ");


}
}
 
R

Roedy Green

There is 2050 bytes in byte array on my applet before sending it, and
2062 bytes in byte array on tomcat !

Why not dump it at both ends to see the differences.
 
P

pcouas

Hi,


My Java Applet Code give me Object is avant ecriture 2383 bytes
String lengthString = String.valueOf(baos.size());



And when i use EtherALL for viewing flow, i have 2062 ???
POST /infodev/servlet/servletgraph.XXServlet HTTP/1.1

Content-Type: application/octet-stream

Method: POST

Content-Length: 2062

User-Agent: Java1.3.1

Host: 172.16.0.101:8080

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

Connection: keep-alive



.....z........sr..applet8.Applet6..s.a
......L..button1t..Ljava/awt/Button;xr..java.applet.Applet..[=.&.....L..accessibleContextt.'Ljavax/accessibility/AccessibleContext;xr..java.awt.Panel.$*[email protected]...'...I..containerSerializedDataVersionI..ncomponents[..componentt..[Ljava/awt/Component;L.
dispatchert.
Ljava/awt/LightweightDispatcher;L..layoutMgrt..Ljava/awt/LayoutManager;L..maxSizet..Ljava/awt/Dimension;xr..java.awt.Component...Y.<.....I..componentSerializedDataVersionZ..enabledJ..eventMaskZ..hasFocusI..heightZ..isPackedZ..nameExplicitlySetZ.
newEventsOnlyZ..validZ..visibleI..widthI..xI..yL..accessibleContextq.~..L.
backgroundt..Ljava/awt/Color;L.
changeSupportt."Ljava/beans/PropertyChangeSupport;L..cursort..Ljava/awt/Cursor;L.
dropTargett..Ljava/awt/dnd/DropTarget;L..fontt..Ljava/awt/Font;L.
foregroundq.~..L..localet..Ljava/util/Locale;L..minSizeq.~..L..namet..Ljava/lang/String;L..peerFontq.~..L..popupst..Ljava/util/Vector;L..prefSizeq.~..xp..........................$........ppppppppppsr.
jaz....va.awt.Font..5...Vs...I..fontSerializedDataVersionF..pointSizeI..sizeI..styleL..fRequestedAttributest..Ljava/util/Hashtable;[email protected]...%!J.....F.
loadFactorI..thresholdxp?fff....w.........sr..java.awt.font.TextAttributekx..
..
F...xr./java.text.AttributedCharacterIterator$Attribute..t&.G.\...L..nameq.~..xpt..familyt..Dialogsq.~..t..transformsr.
java.awt.font.TransformAttribute...0...Z...L..transformt..Ljava/awt/geom/AffineTransform;xpsr..java.awt.geom.AffineTransform.x..J..b...D..m00D..m01D..m02D..m10D..m11D..m12xp?...............................?...............xsq.~..t..sizesr..java.lang.Float.....<[email protected].~..xpppsr..java.awt.ComponentOrientation...E..c....I..orientationxp....px........ur..[Ljava.awt.Component;...
....u...xp....sr..java.awt.Button.:..x.S....I..buttonSerializedDataVersionL.
actionCommandq.~..L..labelq.~..xq.~.
...........................I.......Apsr..java.awt.Color......3u...F..falphaI..valueL..cst..Ljava/aHTTP/1.1
200 OK

Content-Length: 0

Date: Fri, 23 Dec 2005 07:35:36 GMT

Server: Apache Tomcat/4.1.30 (HTTP/1.1 Connector)



Regards
Philippe
 
P

pcouas

No, i have created a Socket on port 8080 with host 172.16.0.101, and
that's ok
Flow is not truncated

Regards
Philippe
 
P

pcouas

Hi,

I can use my socket from application, but from IE my WriteObject has an
Error
How could i found my Error .
Same Program could running from my IDE, but not from IE
Why ?

Regards
Philippe

Erreur java.awt.EventQueue
java.io.NotSerializableException: java.awt.EventQueue
at java.io_ObjectOutputStream.writeObject0(Unknown Source)
at java.io_ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io_ObjectOutputStream.writeSerialData(Unknown Source)
at java.io_ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io_ObjectOutputStream.writeObject0(Unknown Source)
at java.io_ObjectOutputStream.writeArray(Unknown Source)
at java.io_ObjectOutputStream.writeObject0(Unknown Source)
at java.io_ObjectOutputStream.access$100(Unknown Source)
at java.io_ObjectOutputStream$PutFieldImpl.writeFields(Unknown Source)
at java.io_ObjectOutputStream.writeFields(Unknown Source)
at java.awt.Container.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io_ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io_ObjectOutputStream.writeSerialData(Unknown Source)
at java.io_ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io_ObjectOutputStream.writeObject0(Unknown Source)
at java.io_ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io_ObjectOutputStream.writeSerialData(Unknown Source)
at java.io_ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io_ObjectOutputStream.writeObject0(Unknown Source)
at java.io_ObjectOutputStream.writeObject(Unknown Source)
at applet8.Applet8e6.WritePostObjectSocket(Applet8e6.java:396)
at applet8.Applet8e6.WriteApplet(Applet8e6.java:375)
at
applet8.Applet8e6_this_mouseAdapter.mousePressed(Applet8e6.java:952)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Sourc
 
R

Roedy Green

I can use my socket from application, but from IE my WriteObject has an
Error
How could i found my Error .
Same Program could running from my IDE, but not from IE
Why ?

Regards
Philippe

Erreur java.awt.EventQueue
java.io.NotSerializableException

It says you tried to write out some object that did not implement the
Serializable interface. You can't write objects to a file in an
Applet without signing the Applet.
 
R

Roedy Green

at applet8.Applet8e6.WriteApplet(Applet8e6.java:375)

looks like you tried to serialise the entire applet. That means the
whole thing must be serializable. Try writing out just the pieces you
need.
 
P

pcouas

Yes i tried to Serialize all Applet, I could serialize it when i launch
my program like an Application, but i not from Internet Explorer.

Regards
Philippe
 
P

pcouas

Ok , next week i implement an Writing method only for Each Component in
Frame Applet and not Applet itself.
My applet is signed

Regards
Philippe
 
P

pcouas

I have tried, that's Work and my CustomerPropertyEditor too
I have saved each component in a séparate byteArray File


Youppi, Philippe
 
T

Thomas Hawtin

pcouas said:
Yes i tried to Serialize all Applet, I could serialize it when i launch
my program like an Application, but i not from Internet Explorer.

Does it make any sense to serialise an applet? When you deserialise,
what are you going to do with it? As far as I can see, you can't go and
put it back into a page.

Although it was all the rage in 1997, I don't think serialising
components is a particularly useful thing to do. Letting the data go
outside of the current JVM instance makes it much more difficult to
change the code, and breaks on Swing version changes. I guess you might
want to keep hold of the state of lots of hidden screens within an
application, or perhaps help with in place upgrading.

Tom Hawtin
 
P

Paulus de Boska

As Roedy pointed out, you're code,in a jar, has to be signed if you
want to be able to write from an applet. Furthermore, don't know if
this helps, but I noticed this in your doPost method :
nb=+len;
where you probably meant :
nb += len ;
 
P

pcouas

I have tried, that's Work and my CustomerPropertyEditor too
I have saved each component in a séparate byteArray File


My problem is resolved Thanks
Youppi, Philippe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top