Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Serialize Applet to a web server via Servlet Problem

Reply
Thread Tools

Serialize Applet to a web server via Servlet Problem

 
 
pcouas
Guest
Posts: n/a
 
      12-22-2005
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 ");


}
}

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      12-22-2005
On 22 Dec 2005 09:24:01 -0800, "pcouas" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
 
pcouas
Guest
Posts: n/a
 
      12-23-2005
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.$*1.......xr. .java.awt.Container@..s...'...I..containerSerializ edDataVersionI..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..comp onentSerializedDataVersionZ..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..fontSerializedData VersionF..pointSizeI..sizeI..styleL..fRequestedAtt ributest..Ljava/util/Hashtable;L..nameq.~..xp....A@..........sr..java.u til.Hashtable...%!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..t ransformsr.
java.awt.font.TransformAttribute...0...Z...L..tran sformt..Ljava/awt/geom/AffineTransform;xpsr..java.awt.geom.AffineTransfor m.x..J..b...D..m00D..m01D..m02D..m10D..m11D..m12xp ?...............................?...............xs q.~..t..sizesr..java.lang.Float.....<.....F..value xr..java.lang.Number...........xpA@..xq.~..xpppsr. .java.awt.ComponentOrientation...E..c....I..orient ationxp....px........ur..[Ljava.awt.Component;...
....u...xp....sr..java.awt.Button.:..x.S....I..but tonSerializedDataVersionL.
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

 
Reply With Quote
 
pcouas
Guest
Posts: n/a
 
      12-23-2005
It seems HttpConnection flow is cutted or formated for 2062 bytes ???

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-23-2005
On 23 Dec 2005 00:53:13 -0800, "pcouas" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>It seems HttpConnection flow is cutted or formated for 2062 bytes ???


are you using readAvailable? See
http://mindprod.com/jgloss/readeverything.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
pcouas
Guest
Posts: n/a
 
      12-23-2005
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

 
Reply With Quote
 
pcouas
Guest
Posts: n/a
 
      12-23-2005
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(Unkn own Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unk nown 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.writeField s(Unknown Source)
at java.io.ObjectOutputStream.writeFields(Unknown Source)
at java.awt.Container.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknow n Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unk nown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unkn own Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unk nown 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(A pplet8e6.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.pumpOneEventForHierar chy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Sourc

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-23-2005
On 23 Dec 2005 11:29:04 -0800, "pcouas" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-23-2005
On 23 Dec 2005 11:29:04 -0800, "pcouas" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
pcouas
Guest
Posts: n/a
 
      12-24-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serialize Applet on Remote Server with HTTP connection on Servlet pcouas Java 0 12-16-2005 11:25 AM
applet to applet - servlet model Tedy Java 1 08-04-2005 11:08 AM
[Applet] Image-Upload to Server via Applet+PHP Roland Poellinger Java 1 03-12-2005 07:23 AM
serialize to SQL Server Blob instead of XML serialize Gordz ASP .Net 3 06-07-2004 07:46 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM



Advertisments