Java Object from XML Using Only AppEngine

Posted on 2010-11-23
Last Modified: 2012-05-10
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:
- 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.
- 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="" from="" type="error">
  <body>Vector of Ints Test</body>
<properties xmlns="">

Open in new window

Question by:tau161
  • 5
  • 5
LVL 16

Accepted Solution

Valeri earned 500 total points
ID: 34249063
According to me XStream is all you need

Author Comment

ID: 34260861
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.
LVL 16

Assisted Solution

Valeri earned 500 total points
ID: 34261490
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:
sorry that I recommended you this library! I didn't know about the problems with GAE.

Author Comment

ID: 34298232
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?
LVL 16

Assisted Solution

Valeri earned 500 total points
ID: 34301817
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:
it refers to this project:
You can try to apply the patch and to test your app, OR to try this "Simple" library.
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


Author Comment

ID: 34443551
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.
LVL 16

Assisted Solution

Valeri earned 500 total points
ID: 34446996
May be it's better to use Simple!
LVL 16

Assisted Solution

Valeri earned 500 total points
ID: 34449385
May be you have missed my previous message. I mean this one #34301817.
In this article 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.

Author Comment

ID: 34487576
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.

Author Closing Comment

ID: 34487589
Answers accepted.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
recursion example 16 111
XML XSL Choose example 3 19
how to add new optional parameter to JSP 1 29
Oracle SQL syntax check  without executing 6 37
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now