Andrea
Andrea

Reputation: 436

Java applet post to read zope database

I have a plone/zope application: in this application I put a Java applet to do certain data evaluations. What I need to know is if I can get the applet query the zope database.

As a try I created a script in the ZMI and through a POST request I call that script in the applet. It works in the eclipse framework, but I don't know if this will work in a production environment (I think yes because it's a signed applet). Anyway, the POST request is done in the following code:

String data = URLEncoder.encode("__ac_name", "UTF-8") + "=" + URLEncoder.encode("admin", "UTF-8");
        data += "&" + URLEncoder.encode("__ac_password", "UTF-8") + "=" + URLEncoder.encode("password", "UTF-8");
        data += "&" + URLEncoder.encode("form.submitted", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");

URL url = new URL("http://xx.xx.xx.xx:8081/myPloneWebsite/testQueryScript");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while((line = rd.readLine()) != null)
{
    System.out.println(line);
}
wr.close();
rd.close();

I also would like to add some parameters to that script: I know how to do in this java code (just need to replicate username-password structure), but don't know how to handle those in python. A param would be an ID: get all data from object with ID=xx. The script I created is the following, that cycles on all the objects with given conditions:

catalog = context.portal_catalog
brains = catalog(portal_type='Permesso di costruire', review_state='S9')
for b in brains:
   obj = b.getObject()
   print "%s\t%s" % (b.Title, obj.elenco_progettisti())

return printed

Even better would be if there was a way to make the applet read and write on the Zope database without printing and formatting every attribute...

Upvotes: 0

Views: 182

Answers (1)

Alex
Alex

Reputation: 4345

if I can get the applet query the zope database

No. Not easily. Maybe not at all. One theoretical way to query the zope database with a Java Applet is:

  • Expose the database to the network, via ZEO
  • Connect to ZEO from the Java Applet

But that approach may not be worth the effort.

As for parameters, how about query string parameters? E.g.:

Your Python script can process query string parameters if you add the parameter name(s) to the parameters field e.g.:

enter image description here

aclark@Alexs-MacBook-Pro:~/ > curl http://localhost:8080/test\?foo=bar
This is the Script (Python) "test" in http://localhost:8080
bar

Upvotes: 2

Related Questions