Build client-side application notes:
1, Specifying the services-config.xml file in a compilation
When you compile your Flex application, you typically specify the services-config.xml configuration file to the compiler. This file defines the channel URLs that the client-side Flex application uses to communicate with the BlazeDS server. Then the channel URLs are compiled into the resultant SWF file.
Both client-side and server-side code use the services-config.xml configuration file. If you change anything in services-config.xml, you usually have to recompile your client-side applications and restart your server-side application for the changes to take effect.
In Flex Builder, the appropriate services-config.xml file is included automatically based on the BlazeDS web application that you specified in the configuration of your Flex Builder project. When you use the mxmlc compiler, use the services option to specify the location of the file.
Note: You can also create channel definitions at run time in ActionScript. In that case, you might be able to omit the reference to the services-config.xml configuration file from the compiler.
2, Specifying the context root in a compilation
The services-config.xml configuration file typically uses the context.root token to specify the context root of a
web application. At compile time, you use the compiler context-root option to specify that information.
During a compilation, Flex Builder automatically sets the value of the context.root token based on the BlazeDS
web application that you specified in the configuration of your project. When you use the mxmlc compiler, use the
context-root option to set it.
How to create a Flash Builder project?
Use this procedure to create a Flex Builder project to edit one of the samples shipped with the Test Drive application.
The procedure for creating and configuring a new project is almost the same as the following procedure.
1 Start Flex Builder.
2 Select File > New > Flex Project.
3 Enter a project name. You are editing an existing application, so use the exact name of the sample folder:
testdrive-chat.
Note: If you are creating an empty project, you can name it anything that you want.
4 If you unzipped flex-src.zip in the samples directory, deselect the Use Default Location option, and specify the directory as C:\blazeds\tomcat\webapps\samples\testdrive-chat, or wherever you unzipped the file on your computer.
Note: By default, Flex Builder creates the project directory based on the project name and operating system. For example, if you are using the plug-in configuration of Flex Builder on Microsoft Windows, the default project directory is C:\Documents and Settings\USER_NAME\workspace\PROJECT_NAME.
5 Select the application type as Web application (runs in Flash Player) to configure the application to run in the browser as a Flash Player pplication.
If you are creating an AIR application, select Desktop Application (Runs In Adobe AIR). However, make sure that you do not have any server tokens in URLs in the configuration files. In the web application that ships with BlazeDS, server tokens are used in the channel endpoint URLs in the WEB-INF/flex/services-config.xml file, as the following example shows:
<endpoint
url="https://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf"
class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
You would change that line to the following:
<endpoint url="http://your_server_name:8400/samples/messagebroker/streamingamf"
class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
6 Select J2EE as the Application server type.
7 Select Use Remote Object Access.
8 Select LiveCycle Data Services.
9 If the option is available, deselect Create Combined Java/Flex Project With WTP.
10 Click Next.
11 Deselect Use Default Location For Local LiveCycle Data Services Server.
12 Set the root folder, root URL, and context root of your web application.
The root folder specifies the top-level directory of the web application (the directory that contains the WEB-INF directory). The root URL specifies the URL of the web application, and the context root specifies the root of the web application.
13 Make sure that your BlazeDS server is running, and click Validate Configuration to ensure that your project is valid.
14 Verify that the Compile The Application Locally In Flex Builder option is selected.
15 Clear the Output Folder field to set the directory of the compiled SWF file to the main project directory.
By default, Flex Builder writes the compiled SWF file to the bin-debug directory under the main project directory. To use a different output directory, specify it in the Output Folder field.
16 Click Next.
17 Set the name of the main application file to Chat.mxml, and click Finish.
Client-side logging
For client-side logging, you directly write messages to the log file, or configure the application to write messages generated by Flex to the log file. Flash Debug Player has two primary methods of writing messages to a log file:
? The global trace() method. The global trace() method prints a String to the log file. Messages can contain checkpoint information to signal that your application reached a specific line of code, or the value of a variable.
? Logging API. The logging API, implemented by the TraceTarget class, provides a layer of functionality on top of the trace() method. For example, you can use the logging API to log debug, error, and warning messages generated by Flex while applications execute.
Flash Debug Player sends logging information to the flashlog.txt file. The operating system determines the location of this file, as the following table shows:
Use settings in the mm.cfg text file to configure Flash Debug Player for logging. If this file does not exist, you can create it when you first configure Flash Debug Player. The location of this file depends on your operating system.
The following table shows where to create the mm.cfg file for several operating systems:
The mm.cfg file contains many settings that you can use to control logging. The following sample mm.cfg file enables error reporting and trace logging:
ErrorReportingEnable=1
TraceOutputFileEnable=1
After you enable reporting and logging, call the trace() method to write a String to the flashlog.txt file, as the
following example shows:
trace("Got to checkpoint 1.");
Insert the following MXML line to enable the logging of all Flex-generated debug messages to flashlog.txt:
<mx:TraceTarget loglevel="2"/>
Server-side logging
You configure server-side logging in the logging section of the services configuration file, services-config.xml. By default, output is sent to System.out.
You set the logging level to one of the following available levels:
? All
? Debug
? Info
? Warn
? Error
? None
You typically set the server-side logging level to Debug to log all debug messages, and also all info, warning, and error messages. The following example shows a logging configuration that uses the Debug logging level:
<logging>
<!-- You may also use flex.messaging.log.ServletLogTarget. -->
<target class="flex.messaging.log.ConsoleTarget" level="Debug">
<properties>
<prefix>[Flex]</prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>false</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint</pattern>
<!--<pattern>Service.*</pattern>-->
<!--<pattern>Message.*</pattern>-->
</filters>
</target>
</logging>
You use two parameters in a channel definition to enable message processing metrics:
<record-message-times>
<record-message-sizes>
Set these parameters to true or false ; the default value is false . You can set the parameters to different values to capture only one type of metric. For example, the following channel definition specifies to capture message timing
information, but not message sizing information:
<channel-definition id="my-streaming-amf"
class="mx.messaging.channels.StreamingAMFChannel">
<endpoint
url="http://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf"
class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
<properties>
<record-message-times>true</record-message-times>
<record-message-sizes>false</record-message-sizes>
</properties>
</channel-definition>