2008. 9. 2. 16:16

[BlazeDS] Building your server-side application

Reference : http://livedocs.adobe.com/blazeds/1/blazeds_devguide/build_apps_5.html#173498

You write the server-side part of a BlazeDS application in Java, and then use the javac compiler to compile it.

Creating a simple Java class to return data to the client

A common reason to create a server-side Java class is to represent data returned to the client. For example, the client-side RemoteObject component lets you access the methods of server-side Java objects to return data to the client.

The Test Drive sample application contains the Accessing Data Using Remoting sample where the client-side code uses the RemoteObject component to access product data on the server. The Product.java class represents that data. After starting the BlazeDS server and the samples database, view this example by opening the following URL in a browser: http://localhost:8400/samples/testdrive-remoteobject/index.html.

The source code for Product.java is in the install_root\samples\WEB-INF\src\flex\samples\product directory. For example, if you are using a BlazeDS Turnkey installation on Microsoft Windows, the directory is C:\blazeds\tomcat\webapps\samples\WEB-INF\src\flex\samples\product.

Modify, compile, and deploy Product.java in the samples web application

  1. Start the samples database.
  2. Start BlazeDS.
  3. View the running example by opening the following URL in a browser:

    http://localhost:8400/samples/testdrive-remoteobject/index.html

  4. Click the Get Data button to download data from the server. Notice that the description column contains product descriptions.
  5. In an editor, open the file C:\blazeds\tomcat\webapps\samples\WEB-INF\src\flex\samples\product\Product.java. Modify this path as necessary for your installation.
  6. Modify the following getDescription() method definition so that it always returns the String "My description" rather than the value from the database:
    public String getDescription() {
        return description;
    }
    
    

    The modified method definition appears as the following:

    public String getDescription() {
        return "My description.";
    }
    
    
  7. Change the directory to samples.
  8. Compile Product.java by using the following javac command line:
    javac -d WEB-INF/classes/ WEB-INF/src/flex/samples/product/Product.java 
    
    

    This command creates the file Product.class, and deploys it to the WEB-INF\classes\flex\samples\product directory.

  9. View the running example by opening the following URL in a browser:

    http://localhost:8400/samples/testdrive-remoteobject/index.html

  10. Click the Get Data button.

    Notice that the description column now contains the String "My description" for each product.

Creating a Java class that extends a BlazeDS class

As part of developing your server-side code, you can create a custom assembler class, factory class, or other type of Java class that extends the BlazeDS Java class library. For example, a data adapter is responsible for updating the persistent data store on the server in a manner appropriate to the specific data store type.

You perform many of the same steps to compile a Java class that extends the BlazeDS Java class library as you do for compiling a simple class. The major difference is to ensure that you include the appropriate BlazeDS JAR files in the classpath of your compilation so that the compiler can locate the appropriate files.