HTTP POST from applet to server (XML data)

Hi everybody,

This is my first post to this forum, also I’m reading it since some time. I really appreciate your work here.

First allow me to present the context :

A Java Applet, stored as Applet Resource in the database, allows the user to graphically edit relations between entities stored in database (something similar to Microsoft Visio). The applet gets the data from the database as XML, then allows the user to edit it.

The user should be able to save his work state on the server and resume it later. For this, the applet is able to serialize its state to XML. The generated XML is sent by HTTP POST to server and retrieved when the user decides to resume working.

Everything works fine till now, but I will really appreciate your oppinions and comments.

Also, there are a few things I do not fully understand…

  1. – Security issues –

The access to database is set to “No Access” both for Default and Annonymous. If I start the applet from local (appletviewer under Eclipse), when I try to access the XML data on the server, the server answers with the login page (and this is absolutely normal). However, if I start the applet from the server (embedded in a form), it seems that the applet requests to XML on the server are somehow “authenticated” by the browser. What I mean, is that I have login only once, when I open the form from the server, and then all the applet requests works fine without authentication. This is great for me, but I do not quite understand how this works.

The code I’m using is below :

URL url1 = new URL(“http://myServer/database.nsf/ViewXML?readviewentries&count=-1”);

InputStream in = url1.openStream();

Sniffering the network, I found “POST /Test/cont10143326.nsf/POSTform!OpenForm HTTP/1.1 cookie: DomAuthSessId=12B0D15AE0194C9745EEB1EC6F545818”.It seems that the authentication cookie is automatically included. I still do not understand how this works…I would say that the JVM should make its own requests. It seems that the JVM is closely colaborating with the browser :-?..

  1. – HTTP POST issues –

I’m using a RichText field (“xmlDoc”) included in the “POSTform” form. The XML is generated by the appplet and than POSTed to this form.

URL url = new URL (“http://myServer/database.nsf/POSTform?CreateDocument”);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod(“POST”);

conn.setDoInput (true);

conn.setUseCaches (false);

DataOutputStream out = new DataOutputStream( conn.getOutputStream() );

out.writeBytes (“xmlDoc=” + XMLdata);

out.flush ();

out.close ();

Retrieving the XML information is done by accesing the saved document with a form having its “Content Type” set to HTML and the only the field “xmlDoc” on it.

Another alternative would be to post to “/POSTform?OpenDocument” and including the “__click=0” field. …out.writeBytes (“__click=0&xmlDoc=” + XMLdata); .

As this is the first time I’m using these technologies, I’d really like to hears your oppinions, comments, better alternatives.

Thanks in advance,

Viorel