[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

Java Object from XML Using Only AppEngine

Greetings AppEngine experts,
   I am working on a standalone Java program that will interact with a Google AppEngine app that I am also working on. It does so using the XMPP chat protocol. On the client-side, I need to be able to "pack" a POJO (Plain Old Java Object) into an XML chat packet (the easy part), and pull it back out on the server-side (the hard part). I will try to explain in as much detail as possible.

  On the client end, this is very easy with the Smack library:
To Set the Value:
msg.setProperty("TheIntVector", myIntVector);
To Get it Back:
Vector<Integer> v = (Vector<Integer>) packet.getProperty("TheIntVector");

  The reason the server-side is not as straightforward is that the JRE for AppEngine is limited to only classes on an approved WhiteList:
        http://code.google.com/appengine/docs/java/jrewhitelist.html
- Google's own XMPP package is much more limited than Smack. I can get the XML chat packet, but the package does not include a way to pull out an Object.
           com.google.appengine.api.xmpp.*
- Also, Easy-To-Use (i.e. one-line-only) XML utilities that I would normally use are not usable in this case because of AppEngine restrictions. I am limited to what's in that list.

The one-size-fits all approach of Smack suits us very well because we need to send a wide variety of types, many of which are custom types in an inheritance hierarchy. This very small part of the project has turned into a hangup because of AppEngine's restrictions. We want to avoid doing a SAX/DOM parsing "mini project" for something that should have only taken 1-2 lines of code. This is where I hope to tap your plentiful brains, Experts.

So my question is this:
   Using Only classes in the Whitelist, what is the simplest (i.e. fewest lines) way to get a Java Object from inside an XML packet?

Here is the XML from the code above.
 
<message id="84HBN-5" to="myapp@appspot.com/SmackE87F5B47" from="myaccount@gmail.com" type="error">
  <body>Vector of Ints Test</body>
  <thread>I8Dw52</thread>
<properties xmlns="http://www.jivesoftware.com/xmlns/xmpp/properties">
  <property>
  <name>TheIntVector</name>
    <value type="java-object">rO0ABXNyABBqYXZhLnV0aWwuVmVjdG9y2Zd9W4A7rwEDAANJABFjYXBhY2l0eUluY3JlbWVudEkADGVsZW1lbnRDb3VudFsAC2VsZW1lbnREYXRhdAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwAAAAAAAAAAV1cgATW0xqYXZhLmxhbmcuT2JqZWN0O5DOWJ8QcylsAgAAeHAAAAAKc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAxzcQB+AAUAAAAic3EAfgAFAAAAOHNxAH4ABQAAAE5zcQB+AAUAAABacHBwcHB4
    </value>
  </property>
</properties>
</message>

Open in new window

0
tau161
Asked:
tau161
  • 5
  • 5
5 Solutions
 
ValeriCommented:
According to me XStream is all you need
http://xstream.codehaus.org/
0
 
tau161Author Commented:
Hello Valeri. Thank you for responding.
   I initially ruled out XStream because of incompatibility issues. Just looked it up again after seeing your post. Again I found mention of requests (~2009) for a patch to make XStream AppEngine compatible, but I can't find any mention online of the XStream developers actually releasing an out-of-the-box  AppEngine-friendly version.
0
 
ValeriCommented:
I was thinking that XStream uses very simple /reflection / classes and it will work everywhere without any problems, but as I can see it's not true :-(
Here is a workaround for G App Engine, hope it will help you:
http://softwaresuperglue.blogspot.com/2009/09/google-app-engine-gae-for-java-and.html
sorry that I recommended you this library! I didn't know about the problems with GAE.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tau161Author Commented:
That link looks like exactly what I need. Thank you.
One question, though. It references a patch for XStream. I have a copy of the patch file now, but I can find no instructions on the XStream site (or elsewhere) for how to actually apply the patch. There are plenty of links to posts about such-and-such a patch for such-and-such a problem, but they all skip over the act of integrating the patch. Have you had to do this before? If so, how?
0
 
ValeriCommented:
Hi,
such as patches are applied by cvs/svn as I know. But I've never applied any patches. It describes in which classes which lines to be removed and which lines to be inserted. But I read that this patch has helped of some people to start their apps with GAE, but was completely useless for some other people...:-( It's not sure that it will help you.
But I found this article for you:
http://milen.commsen.com/2010/07/more-simple-than-xstream.html
it refers to this project:
http://simple.sourceforge.net/
You can try to apply the patch and to test your app, OR to try this "Simple" library.
0
 
tau161Author Commented:
Apologies for the long delay. I got caught up in an unrelated project.
   I applied the patch to the version listed on the patch download page. Unfortunately it gave me several merge conflicts. I tried resolving them line by line, but had no success. I found some posts where other users met with the same conflicts even though they were also using the correct patch on the correct version, but no solutions to that problem were ever posted. Thank you for taking the time to answer.
   I am still convinced that you are right, and that XStream+Patch is exactly what I am looking for. I just need to find a solution to the 'apply' conflicts.
0
 
ValeriCommented:
May be it's better to use Simple!
http://simple.sourceforge.net/
0
 
ValeriCommented:
May be you have missed my previous message. I mean this one #34301817.
In this article http://milen.commsen.com/2010/07/more-simple-than-xstream.html one developer explains more about Simple and that it works perfectly with GAE.
Hope it will help you to fix your problem. He says that Simple is faster than XStream as well.
XStream is also good, but obviously it has problems with GAE.
0
 
tau161Author Commented:
I'm going to go ahead and award the points.  Valeri, thank you for all help.  Eventually I will get back to this project and, it does indeed look like Simple should work fine for that.
0
 
tau161Author Commented:
Answers accepted.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now