| By Yakov Fain | Article Rating: |
|
| July 28, 2011 11:45 AM EDT | Reads: |
3,704 |
This was an interesting bug… I was working on a Web application, where Adobe Flex client was sending an instance of an ActionScript WrapperObject to the Java server, which was supposed to invoke some JBDC code to run an SQL Insert statement saving the data from the Java version of WrapperObject in the database. I wrote all the pieces of Flex, Java, and SQL and started Tomcat in Eclipse IDE.
The Web browser displayed my window, I filled out the form populating the ActionScript WrapperObject and pressed the button Save. Nothing happened. No errors and no data inserted in the database.
Well, need to start debugging…Let’s see what could have gotten wrong:
- I didn’t properly populate the ActionScript WrapperObject
- I didn’t properly configure the Java class/method so the front end didn’t even call it.
- I didn’t code the database portion properly.
But why there is no errors? Starting the Flex part in the debug mode quickly revealed that the WrapperObject was properly populated and the asynchronous request to the Java server has been sent.
Great. The next question is, “Have I called the proper endpoint (the destination) on the Java side and if the correct method has been really invoked?” Started an HTTP/AMF sniffer, which confirmed that I was calling a method on the endpoint mapped to the class Customer shown below. On the Java side, the class hierarchy looked as follows:
class _Customer {
…
public boolean saveData( WrapperObject wrapper){
// an empty method
}
}
class Customer extends _Customer{
public boolean saveData (WrapperObject wrapper) {
// the code saving data in DBMS was here
}
}
Without leaving Eclipse IDE, restarted Tomcat in the debug mode and put a breakpoint in the caller of Java’s saveData. Interesting… The debugger brought me inside the empty method of _Customer.saveData. Do you see any spelling errors in the method signatures? Me neither. This was about time to use a Java annotation @Override, which I was always underestimating. Changed the class Customer to look like this:
class Customer extends _Customer{
@Override
public boolean saveData (WrapperObject wrapper) {
// the code saving data in DBMS was here
}
}
Sure enough, the Java compiler immediately told me that the method saveData has to override the one from the superclass. But I did override it, didn’t I?
The problem was that my project has two different versions of the class WrapperObject located in different packages! The superclass was using the WrapperObject from one package, but the subclass from another! This little annotation caught what my eyes didn't see. Fixed the import statement in the subclass to properly override the method saveData, re-ran the program and got… an SQL error stating that I have an extra comma somewhere in my Insert statement. But this one is a piece of cake! I was so happy.
Thank you Java @Override – you made my day!From now onI'll be using this example in all my Java classes.
Read the original blog entry...
Published July 28, 2011 Reads 3,704
Copyright © 2011 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Yakov Fain
Yakov Fain is a Managing Director of Farata Systems, consulting, training and product company. He has authored several Java books, dozens of technical articles. SYS-CON Books released his latest co-authored book , Rich Internet Applications with Adobe Flex and Java: Secrets of the Masters in Spring 2007. Sun Microsystems has nominated and awarded Yakov with the title Java Champion. He leads the Princeton Java Users Group. He is an Adobe Certified Flex Instructor. Yakov co-athored the O'Reilly book "Enterprise Application Development with Flex". He twits at twitter.com/yfain.
- Adobe Sends Flex to the Apache Foundation
- Adobe: Another one bites the dust
- SmartBear Software Advances Load Testing for Websites with RIAs
- Immersing into JavaScript Frameworks
- design3 Offers Over $2,500 in Prize Giveaways and 50% Off All Memberships This December
- PowerPoint 2010 Tips: How to Blur the Background of a Photo
- Adobe Augments Real-Time Delivery with Scene7 Acquisition
- Adobe Sends Flex to the Apache Foundation
- Adobe Touch Apps Available in Android Market
- Adobe: Another one bites the dust
- SAP Provides New Solutions for Integrating Business Processes and for Open Development
- SmartBear Software Advances Load Testing for Websites with RIAs
- Immersing into JavaScript Frameworks
- NVIDIA Quad-Core Tegra 3 Chip Sets New Standards of Mobile Computing Performance, Energy Efficiency
- design3 Offers Over $2,500 in Prize Giveaways and 50% Off All Memberships This December
- PowerPoint 2010 Tips: How to Blur the Background of a Photo
- Adobe Augments Real-Time Delivery with Scene7 Acquisition
- Where Are RIA Technologies Headed in 2008?
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- How To Create a Photo Slide Show ...
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Adobe/Macromedia - Microsoft, Look Out!
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets



































