Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java Object from XML Using Only AppEngine

Posted on 2010-11-23
10
Medium Priority
?
628 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 2000 total points
ID: 34249063
According to me XStream is all you need
http://xstream.codehaus.org/
0
 

Author Comment

by:tau161
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.
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 2000 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:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tau161
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?
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 2000 total points
ID: 34301817
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
 

Author Comment

by:tau161
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.
0
 
LVL 16

Assisted Solution

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

Assisted Solution

by:Valeri
Valeri earned 2000 total points
ID: 34449385
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
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.
0
 

Author Closing Comment

by:tau161
ID: 34487589
Answers accepted.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

636 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