p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional BlazeDS: Creating Rich Internet Applications with Flex and Java
This is the forum to discuss the Wrox book Professional BlazeDS: Creating Rich Internet Applications with Flex and Java by Shashank Tiwari; ISBN: 978-0-470-46489-2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional BlazeDS: Creating Rich Internet Applications with Flex and Java section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2009, 01:09 AM
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 4: Java-based Data Service

Hello Mr. Tiwari,

I come from a Flex background and I'm new to the whole Java/BlazeDS thing. Currently I'm having trouble with implementing your example on chapter 4. Specifically, I'm stuck on what to do with HSQL DB in order to get the example to work. Can you provide set of step-by-step instruction on how to it should be setup?

Thanks,

Adrian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 12th, 2009, 12:56 AM
Registered User
Points: 46, Level: 1
Points: 46, Level: 1 Points: 46, Level: 1 Points: 46, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default chapter 04 example problems

Here is what I have found so far:

1) As he did in chapter 02, the author forgets in chapter 04 to update services-config.xml to change "my-amf" to be the following.

Code:
   <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://localhost:8080/ProBlazeDSCh04/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
2) The author forgot to place the following import statements in class EnergyConsumptionDataService :

Code:
package problazeds.ch04;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class EnergyConsumptionDataService
3) The author places all of the java files in the wrong directory. To make the example work, remove all the java files from directory "\ProBlazeDSCh04\WebContent\WEB-INF\src" and place them instead into directory ProBlazeDSCh04\src

4) Be sure to copy the following into remoting-confix.xml (the author's download has this entry correctly in it):
,
Code:
<destination id="energyConsumptionData">
        <properties>
            <source>problazeds.ch04.EnergyConsumptionDataService</source>
        </properties>
    </destination>
5) Go to http://hsqldb.org, click on "latest stable version", and download "hsqldb_1_8_1_1.zip". Unzip it into an empty directory. Copy file hsqldb.jar from the exploded zipfile into the "lib" directory of your flex web project.

6) Since the author provides no instructions on how to configure hsqldb, we have to use the defaults. Each time you run the web app, 4 files will appear on the root of your "C;" drive. Those 4 files are shown below. You have to manually delete these four files each time you rerun the web application or else an error message appears that says a a table is already defined:

Code:
Directory of C:\

11/11/2009  11:22 PM                16 db_texttable.lck
11/11/2009  11:22 PM               331 db_texttable.log
11/11/2009  11:21 PM               493 db_texttable.properties
11/11/2009  11:21 PM                 0 us_energy_data.csv

7) If you do all this, the flex app will appear okay in the browser when you right click on ProBlazeDSCh04.mxml and select "Run as Flex Application".

8) Unfortunately however, when you then click the "Get Data" button on the flex application, nothing happens. No data appears. But at least no error messages appear.

9) Since the author does not provide any screen shot of the finished application, it's not possible to know what is supposed to happen when the "Get Data' button is clicked. Maybe the lack of an error message is what the author means when he writes on page 107 quote, "The illustration of the service, client, and the configuration covers all aspects of the example".

10) This is all I was able to accomplish on the example so far.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 12th, 2009, 02:58 AM
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default Remoting fault error

Thanks for your help RobertGloverJr.

I wholeheartedly share your frustrations with the incompleteness in examples for this book.

The steps that you've outlined have definitely been very helpful. But when I run the example program and attempt a remoting call, I get a remoting fault error:

Code:
[RPC Fault faultString="java.lang.RuntimeException : java.sql.SQLException: No suitable driver found for jdbc:hsqldb:file:/db_texttable" faultCode="Server.Processing" faultDetail="null"]
	at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\galaga\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:290]
	at mx.rpc::Responder/fault()[C:\autobuild\galaga\frameworks\projects\rpc\src\mx\rpc\Responder.as:58]
	at mx.rpc::AsyncRequest/fault()[C:\autobuild\galaga\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
	at NetConnectionMessageResponder/statusHandler()[C:\autobuild\galaga\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:571]
	at mx.messaging::MessageResponder/status()[C:\autobuild\galaga\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:222]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 12th, 2009, 08:36 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Remoting fault error

adriang,
Did you add hsqldb jar to your classpath? This can be done in multiple ways, the simplest of which is to copy it in the WEB-INF/lib folder.

Thanks, Shashank
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old November 12th, 2009, 09:04 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: chapter 04 example problems

RobertGloverJr,
While I am happy to provide detailed instructions and include more examples, please be aware that the book assumes some knowledge of Java web application development and never intends to cover every single essential topic related to the subject.

Now a few comments inline ----

1) if you need to change the AMF Channel configuration from its default --

Code:
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
to

Code:
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://localhost:8080/ProBlazeDSCh04/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
it means there is some issue with your current configuration. "server.name", "server.port" and "context.root" should automatically reconcile to "localhost" (when the server is running locally), "8080" if your server HTTP listener is configured to listen on port "8080" and "ProBlazeDSCh04" if that is the root directory of your Java web application, which it should be if the project was set up correctly.

2) I will verify the statement import. If its not imported or not within the same package and sub-package it simply wouldn't compile. Its possible I made a mistake but let me check that once.

3) Your statement is not correct at all. I have setup WTP with Eclipse. Please download WTP from http://www.eclipse.org/webtools/. Using Flex and WTP defaults, I chose to go with WebContent as the root of my application. Please revisit page 59 and 60.

5) and 6) I will write-up a blog post soon explaining the use of HSQL DB. The post will be available at www.shanky.org. It may not happen until the coming weekend though. I hope that works.

8) I will verify and see why its not working and if there are any errors, I will make sure to upload an updated build to the code download.

9) Again will try to write-up a detailed explanation of the example configuration, code and expected results.

Once again, I am sorry that the experience has been frustrating.

Thanks, Shashank
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old November 12th, 2009, 01:16 PM
Registered User
Points: 46, Level: 1
Points: 46, Level: 1 Points: 46, Level: 1 Points: 46, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default chap04 sample, experience required and hsqldb info

Quote:
Originally Posted by Shashank Tiwari View Post
RobertGloverJr,
While I am happy to provide detailed instructions and include more examples, please be aware that the book assumes some knowledge of Java web application development and never intends to cover every single essential topic related to the subject.


Thanks, Shashank
Shashank, I realize how difficult it must be to write a book like this, and I am satisified your book is worth the money I paid. But still, there is room for improvement, especially as regards these samples. I personally am a Sun Certified Java Programmer and have been writing java programs professionally for ten years. I use Eclipse and Tomcat professionally on the job every day. Yet, I am still having all these problems getting your sample programs to work.

At the moment the only problem I have left with the chapter 04 sample is that I need someone to provide details of the doubtless very simple 2 or three small things that have to be done to get the hsqldb to be configured properly. I don't need to become an expert in hsqldb and for that reason it's not terribly helpful to hear that over the weekend you will write a very detailed post about hsqldb. Couldn't you just give us the "answer" here in a paragraph or two so that we can all get chapter 04's example to work with hsqldb? There must be some sort of simple configuration necessary now that everybody knows to drop the hsqldb jar file into the "lib" directory of the web app.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old November 12th, 2009, 03:20 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default chap04 sample, experience required and hsqldb info

RobertGloverJr,

Once again thanks for understanding and I am happy you like the book. At the same time, I am happy you are sending your feedback, which would in turn help me make the book only better.

Please allow me till tomorrow to look into the issue and get back to you with a solution. I am very swamped with work at the moment and do appreciate your patience. I want to make sure I don't provide you a half baked solution that only creates further confusion, so would like to look at the configuration carefully and explain all the required bits.

Thanks, Shashank
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old November 14th, 2009, 12:06 PM
Registered User
Points: 46, Level: 1
Points: 46, Level: 1 Points: 46, Level: 1 Points: 46, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default solution to getting chapter 04 example to work

By making two changes I was able to get the chapter 04 example to work.

The first change is to manually copy file "us_energy_data.csv" into the root directory of the "C" drive. The reason this is necessary is because if you don't copy this file manually, an empty file with this name will be created by HSQLDBConnectionHelper.java. Because that file is empty, no data displays in the flex client!

Below shows a portion of file "us_energy_data.csv". As you can see it contains the column names and the corresponding data that hsqldb will use to load table "energy_consumption"

Code:
year,fossil_fuels,nuclear_electric_power,renewable_energy,total
1949,29002099,0,2973984,31981503
1950,31631956,0,2977718,34615768
1951,34008105,0,2958464,36974030:
1952,33799903,0,2940181,36747825
...snip...
(If they are there already) go the the "C" drive and manually delete the 3 files that begin with "db_". Below shows the names of the 3 files to delete:

C:\>dir db_*
Volume in drive C has no label.
Volume Serial Number is 2418-DBE2

Code:
Directory of C:\
11/14/2009  10:25 AM                16 db_texttable.lck
11/14/2009  10:26 AM               493 db_texttable.log
11/14/2009  10:25 AM               493 db_texttable.pro
               3 File(s)          1,002 bytes
               0 Dir(s)   1,348,075,520 bytes free
If you now run "ProBlazeDSCh04" as a Flex Application and press the "get data" button, it will show the data in both a table and in a graph. However when you click "get data" a second time, you will get the error shown below:

Code:
[RPC Fault faultString="java.lang.RuntimeException : java.sql.SQLException: Table already exists: ENERGY_CONSUMPTION in statement [CREATE TEXT TABLE energy_consumption]" faultCode="Server.Processing" faultDetail="null"]
	at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:220]
	at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:53]
	at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
	at NetConnectionMessageResponder/statusHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:569]
	at mx.messaging::MessageResponder/status()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:222]
That's all the time I have today to work on this.

Last edited by RobertGloverJr : November 15th, 2009 at 12:29 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old November 15th, 2009, 11:54 AM
Registered User
Points: 46, Level: 1
Points: 46, Level: 1 Points: 46, Level: 1 Points: 46, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default new improved version of HSQLDBConnectionHelper.java

Below is the code for a much better version of HSQLDBConnectionHelper.java that works across reloads of the web app, Tomcat recycles , etc. etc.

Start with the author's original code for HSQLDBConnectionHelper.java and then update the code below that has the comments "// start of R.Glover's code to add" and "// end of R.Glover's code to add" around it. The code enhancement uses a regular expression to determine if a "Table already exists" condition occurred. If so, it ignores it instead of throwing an exception.

Code:
   public static Connection getConnection() throws SQLException {
        if (singletonInstance == null) {
            singletonInstance = new HSQLDBConnectionHelper();
        }
        try {
            Connection conn = DriverManager.getConnection(singletonInstance.url);
            final StringBuilder createTable = new StringBuilder();  
            createTable.append("CREATE TEXT TABLE energy_consumption (");  
            createTable.append("year INT PRIMARY KEY, fossil_fuels DOUBLE,");
            createTable.append("nuclear_electric_power DOUBLE, renewable_energy DOUBLE, total DOUBLE)");  
              
            final StringBuilder linkTable = new StringBuilder();  
            linkTable.append("SET TABLE energy_consumption SOURCE ");  
            linkTable.append("\"us_energy_data.csv");  
            linkTable.append(";ignore_first=true;all_quoted=true\"");
            // start of R.Glover's code to add
            try {
            	conn.setAutoCommit(true);  
            	conn.createStatement().execute(createTable.toString());  
            	conn.createStatement().execute(linkTable.toString());
            }
            catch (SQLException e) {
            	java.util.regex.Pattern pattern =
            		java.util.regex.Pattern.compile(".*(Table already exists).*",
            		java.util.regex.Pattern.CASE_INSENSITIVE);
            	java.util.regex.Matcher matcher = pattern.matcher(e.getMessage());
                if (matcher.matches()) {
                	System.out.println("ignoring futile attempt to define same table twice");
                } else {
                	throw e;
                }
            }
         // end of R.Glover's code to add
            return conn;
        } catch (SQLException e) {
            throw e;
        }
    }

Last edited by RobertGloverJr : November 15th, 2009 at 12:35 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old November 15th, 2009, 12:26 PM
Registered User
Points: 46, Level: 1
Points: 46, Level: 1 Points: 46, Level: 1 Points: 46, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default improved version of EnergyConsumptionDataService.java

Below is an improvement to EnergyConsumptionDataService.java that causes the client graph and grid to show different results each time the "get data" button is clicked. Change the code below that has the comments "// start R.Glover addition" and "// end R.Glover addition" around it.

Code:
package problazeds.ch04;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class EnergyConsumptionDataService
{
    public List getEnergyConsumptionData() throws RuntimeException {

        List list = new ArrayList();
        Connection c = null;

        try {
            c = HSQLDBConnectionHelper.getConnection();
            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery("SELECT * FROM energy_consumption ORDER BY year");
            while (rs.next()) {
            	// start R.Glover addition
            	 java.util.Random randomGenerator = new java.util.Random(System.currentTimeMillis());
            	 int randomInt1 = randomGenerator.nextInt(9999999);
            	 int randomInt2 = randomGenerator.nextInt(9999999);
            	 int randomInt3 = randomGenerator.nextInt(9999999);
                list.add(new EnergyConsumption(rs.getInt("year"),
                        rs.getDouble("fossil_fuels") + randomInt1,
                        rs.getDouble("nuclear_electric_power") + randomInt2,
                        rs.getDouble("renewable_energy") + randomInt3, 
                        rs.getDouble("total") + randomInt1 + randomInt2 + randomInt3));
            	// end R.Glover addition
            }
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            HSQLDBConnectionHelper.close(c);
        }
        return list;

    }

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Announce] LGPL Java, XSL and Ajax based Framework erkan_cengiz XSLT 0 March 27th, 2008 11:27 AM
audio video based chat using java manish_regmi J2EE 0 August 22nd, 2006 05:58 AM
conditional xslt processing based on java array twilson997 XSLT 7 June 28th, 2006 08:32 AM
Java based open-source online shop shantawn Apache Tomcat 0 July 15th, 2005 02:53 AM
JAVA SOAP and service registeration pcfeifei J2EE 0 May 19th, 2004 11:00 PM



All times are GMT -4. The time now is 12:10 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc