|

|
INTRODUCTION |
|
|
 |
WebORB for Java
provides an implementation of the Remoting and Data
Management functionality for Flex/Flash clients as
well as support for AJAX client/server invocations.. Using WebORB developers can
integrate Flex, Flash and AJAX client applications with Java objects
and relational databases.
WebORB does not require Adobe LiveCycle Data Services as the WebORB implementation is
independent of any third-party products. In addition
to integration with Flex,
the product offers a variety of important features:
- Access to the
Java objects exposed to Flex clients can be
restricted using WebORB security;
- WebORB
automatically handles translation between Java
and ActionScript types for argument and return
type serialization;
- Construction of
method argument objects can be overridden using
argument type factories;
- Return type
serialization algorithm can be changed using custom serializers;
|
|

|
INSTALL WEBORB |
|
|
 |
WebORB for Java distribution is
available as a zip or tar archive. Extract the
files from the archive into a directory. This article assumes the product is installed into
the /weborb folder.
|

|
LAUNCH WEBORB |
|
|
 |
WebORB for Java supports two
execution modes: hosted and standalone. The hosted
mode allows running the product in any Java servlet
container or Java EE server. The standalone mode
lets you start the product directly from the command
line prompt without any additional configuration
steps (the standalone mode requires Java SE).
To simplify the task of getting
started with WebORB, this guide assumes WebORB runs
standalone, however working with the product in the hosted mode is identical (it requires
product deployment into the container).
To start WebORB open a command
prompt window and change the current directory to the
WebORB installation directory. Run the following command:
java -jar
weborb.jar
WebORB starts on the default port
for the standalone execution (8080). To change port
number use the following command (where [PORT] is
the port number to start the product on):
java -jar
weborb.jar http://localhost:[PORT]
Once the product starts, you can
access the management console at the following URL (change the port number if you specified
a different value):
http://localhost:8080/
The console provides a variety of
useful features:
-
Service browser (select
Management, then Services) - provides access to
all the deployed class files.
-
Code generator (select a
class in the Service browser) - generates
ActionScript code for invoking a selected class
-
Test drive (select a method
for a class) - provides a visual interface for
accepting method argument and invoking the method
directly from the console
-
Logging configuration
(Management > Server Configuration > Logging) -
configures server-side logging categories and
current logging policy (std. output or file)
-
Class mappings (Management
> Server Configuration > Class Mappings) -
establishes client/server class mappings to guide
WebORB's type adaptation system
-
Examples (see the Examples
tab) - offers a variety of Flex and Flash remoting
as well as Data Management examples. Each example
contains links to the client- and server-side
source code.
|

|
CREATING A FLEX APPLICATION |
|
|
| |
The result of this step is a Flex builder project
configured to compile a Flex application working with
WebORB for Java. Select a tab for the version of Flex
Builder you use to get instructions specific to that
version. |
| |
 
|
| |
Run Flex Builder
2.0 and select File -> New -> Flex Project.
The
dialog window shown below will appear. Make the
selections as shown below and click "Next >".

The next step is very important as it establishes the
configuration paths. Clear the checkbox and enter the path for the directory containing the WebORB installation into the "Root folder" text field.
This walkthrough assumes the product is installed in the /weborb directory, as a result when
running WebORB standalone, the "Root folder" must contain "c:\weborb\webapp" as shown in the
image below.
The "Root URL" text field must contain a URL
to the WebORB servlet. The URL in the standalone mode is http://localhost:8080/weborb/ (the
trailing slash is important): Enter the values and click
"Next >" to continue.

The next step is to assign a name to the Flex project.
Enter "SampleFlexToJavaProject" and
click "Finish" to finalize the creation of the project.

Flex Builder creates a blank default Flex application. The steps below
will guide you through adding MXML/ActionScript code and connecting it with a Java object.
Run Flex Builder
3 and select File -> New -> Flex Project.
The
dialog window shown below will appear. Enter "SampleFlexToJavaProject"
as the project name. Make sure to select "J2EE" as
the Application server type. Make other selections as shown below and click "Next >".

The next step is very important as it establishes the
configuration paths. Clear the checkbox and enter the path for the folder
containing the WebORB installation into the "Root folder" text field.
This walkthrough assumes the product is installed in the /weborb directory, as a result when
running WebORB standalone, the "Root folder" must contain "c:\weborb\webapp" as shown in the
image below.
The "Root URL" text field must contain a URL
to the WebORB servlet. The URL in the standalone mode is http://localhost:8080/weborb/ (the
trailing slash is important):

Click "Finish" to continue. Flex Builder creates a
default (blank) Flex application. Flex Builder may report the following error: "Server SDK:
Directory does not contain a Flex SDK":

To correct the error open the project properties window (right click the project node and select
Properties). Select "Flex Compiler" and change the "Flex SDK version" to either "Use default
SDK" or "Use a specific SDK" as shown in the image below:

Click Apply, then OK to close the window.
The steps below will guide you through adding MXML/ActionScript
code and connecting it with a Java object.
Flex SDK is available free of charge
from the Adobe website. The SDK contains a command-line
compiler for the Flex applications. Follow the steps
below to compile and deploy the client-side code for the
example reviewed in this guide:
-
Open a command prompt window and change
to the current directory to \weborb\webapp\examples\quickstart\flex\client-code
-
Run the mxmlc compiler with the
following parameters:
|
-services=\weborb\webapp\WEB-INF\flex\services-config.xml
-output=\weborb\webapp\SampleFlexToJavaProject\SampleFlexToJavaProject.swf
SampleFlexToJavaProject.mxml |
The first parameter (-services)
instructs the compiler to use the configuration file
with the definition of a remoting destination used in
the Flex application.
The second parameter (-output) instructs
the compiler to output the compiled application to the
specified directory. Finally, the third
parameter is the filename containing the source code
of the compiled Flex application. The
command line and the compiler output should look as in
the image below:

Make sure the compiled application file exists at the
following path: \weborb\webapp\SampleFlexToJavaProject\SampleFlexToJavaProject.swf
|
|

|
CONFIGURATION - FLEX
BUILDER (skip
this if you're using Flex SDK) |
|
|
| |
WebORB product distribution contains a finished Flex application demonstrating Flex to WebORB
remoting invocation and connectivity. Copy and paste the contents of the
SampleFlexToJavaProject.mxml file located at the path below into the mxml file created in
Flex Builder:
[WEBORB PATH]\examples\quickstart\flex\client-code
The code in the application connects to a Java object and retrieves some basic
information about the computer where the object is running.
|
|

|
JAVA CODE |
|
|
 |
The Java class shown below
will be deployed as a remoting service accessible via WebORB. The method
creates and returns a Java object with some basic
information about the server-side environment:
|
package
weborb.examples.quickstart;
public class ComputerInfoService
{
public ComputerInfo getComputerInfo( String requestId )
{
ComputerInfo computerInfo = new ComputerInfo();
computerInfo.javaVersion = System.getProperty( "java.vm.version" );
computerInfo.javaVendor = System.getProperty( "java.vm.vendor" );
computerInfo.os = System.getProperty( "os.name" );
computerInfo.osVersion = System.getProperty( "os.version" );
computerInfo.requestId = requestId;
return computerInfo;
}
}
public class
ComputerInfo
{
String javaVersion;
String javaVendor;
String os;
String osVersion;
String requestId;
}
|
Source code and and compiled classes:
The next step is to compile the .Java code and deploy it into WebORB.
You can download the source code or use the compiled classes from a jar linked above.
If you would like to skip the compilation step and
proceed to the next step, use the jar file for the actual deployment. Otherwise compile the
classes shown above. |
|

|
DEPLOYING JAVA CLASSES |
|
|
 |
The compiled code can be deployed by copying the JAR file into WEB-INF/lib
(in the standalone mode the directory is located under [WEBORB PATH]/webapp.
Alternatively, the individual class files can be deployed into the
/WEB-INF/classes directory of the web application (WEB-INF/classes is located under [WEBORB
PATH]/webapp
in the standalone mode. The location of the directory in the hosted mode varies between J2EE
servers). When you copy the class files into WEB-INF/classes, it is important to keep the
directory structure the same as the Java class package structure.
Once the classes are deployed, you can see them in the service browser available in the WebORB
Management Console (see the Management tab, Services sub-tab).
|

|
FLEX CLIENT CODE |
|
|
 |
The client-side application's logic for
this example is very straightforward. The code
uses the RemoteObject API to invoke remote
Java method. When the remote method invocation returns a result, the client renders it on
the screen. The code below demonstrates the
usage of the RemoteObject tag and the
mx.rpc.remoting.RemoteObject API for the Java class
above:
using MXML:
<mx:RemoteObject id="compinfo"
destination="GenericDestination"
source="weborb.examples.quickstart.ComputerInfoService"
showBusyCursor="true"
fault="faultHandler(event)" >
<mx:method name="getComputerInfo"
result="getComputerInfoHandler(event)"/>
</mx:RemoteObject> |
using ActionScript:
var compinfo:RemoteObject = new RemoteObject( "GenericDestination"
);
compinfo.source="weborb.examples.quickstart.ComputerInfoService";
compinfo.addEventListener( FaultEvent.FAULT, faultHandler );
compinfo.getComputerInfo.addEventListener(Result.EVENT,getComputerInfoHandler); |
There are two response handlers: one
is responsible to handle errors (faultHandler) and
the other will be processing remote method
invocation return data (getComputerInfoHandler).
Both functions are shown below:
private
function faultHandler( event:FaultEvent ):void
{
Alert.show( event.fault.faultString, "Error"
);
}
private function getComputerInfoHandler( event:ResultEvent ):void
{
javaVersion.text = event.result.javaVersion;
javaVendor.text = event.result.javaVendor;
os.text = event.result.os;
osVersion.text = event.result.osVersion;
requestId.text = event.result.requestId;
}
|
And finally the user interface part
to display the response could have the following
MXML markup:
<mx:Panel width="476"
height="281"
layout="absolute"
title="Getting Started Example"
cornerRadius="0"
backgroundColor="#ffffff">
<mx:Label x="292"
y="-23" text="Flex Remoting
with WebORB"/>
<mx:Label x="46"
y="59" text="Java Version"
/>
<mx:Label x="46"
y="85" text="Java Vendor"
/>
<mx:Label x="46"
y="111" text="OS" />
<mx:Label x="46"
y="137" text="OS Version"
/>
<mx:Label x="46"
y="163" text="Request ID"
/>
<mx:TextInput x="154"
y="60" id="javaVersion"/>
<mx:TextInput x="154"
y="86" id="javaVendor"/>
<mx:TextInput x="154"
y="112" id="os"/>
<mx:TextInput x="154"
y="138" id="osVersion"/>
<mx:TextInput x="154"
y="164" id="requestId"/>
<mx:Button x="47"
y="209" label="Send Request"
click="compinfo.getComputerInfo( reqId++ )"/>
</mx:Panel> |
Full client code listing is
available
here.
Compile and run the project. You
should have a working Flex application using Flex
Remoting with Java.
|

|
RUNNING FLEX
APPLICATION |
|
|
 |
When you run the application in Flex
Builder, it opens a browser and loads the application
from:
http://localhost:8080/weborb/SampleFlexToJavaProject/SampleFlexToJavaProject.html
If you compiled the application with Flex SDK, you can
load it from the following URL:
http://localhost:8080/weborb/SampleFlexToJavaProject/SampleFlexToJavaProject.swf
The application connects to the backend
service upon the startup or when a user clicks the "Send
Request" button:

|
|
|