Developer Resources:

Customer Quotes:

Article Contents


This article will guide you through creating a basic Flex Remoting application and connecting it with a Java class hosted in WebORB. To get started you need to install WebORB for Java. The product comes with an installer which can be launched using the following command:

java -jar weborb4java.jar

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):


The console provides a variety of useful features:


  • Code generator (select a class in the Service browser) - generates ActionScript code for invoking a selected class
  • Service browser (select Management, then Services) - provides access to all the deployed class files.
  • 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.

Java Service 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( "" );
    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).

Create Flex Builder Project

Create a Flex Builder project as described in this article.

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 abo

<mx:RemoteObject id="compinfo"
                 fault="faultHandler(event)" >
     <mx:method name="getComputerInfo"             result="getComputerInfoHandler(event)"/>

using ActionScript:

var compinfo:RemoteObject = new RemoteObject( "GenericDestination" );
compinfo.addEventListener( FaultEvent.FAULT, faultHandler );

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
{ 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++ )" />

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 Client

When you run the application in Flex Builder, it opens a browser and loads the application from:


If you compiled the application with Flex SDK, you can load it from the following URL:


The application connects to the backend service upon the startup or when a user clicks the "Send Request" button: