Solved

Java Object from XML Using Only AppEngine

Posted on 2010-11-23
10
615 Views
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:
        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
Comment
Question by:tau161
  • 5
  • 5
10 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
Comment Utility
According to me XStream is all you need
http://xstream.codehaus.org/
0
 

Author Comment

by:tau161
Comment Utility
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
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 500 total points
Comment Utility
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
 

Author Comment

by:tau161
Comment Utility
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
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 500 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:tau161
Comment Utility
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
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 500 total points
Comment Utility
May be it's better to use Simple!
http://simple.sourceforge.net/
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 500 total points
Comment Utility
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
 

Author Comment

by:tau161
Comment Utility
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
 

Author Closing Comment

by:tau161
Comment Utility
Answers accepted.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 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

16 Experts available now in Live!

Get 1:1 Help Now