Although you can use the debugger to inspect data after Flex has received it and before Flex sends it, you may want to find out more details regarding what data is being sent and received. You can achieve this by using the logging framework or a data inspector.
The WebService
, HTTPService
, and RemoteObject
components use the Flex logging
framework, which can greatly assist debugging applications. Messages
are automatically logged to the Flex logging framework, so you won’t
need to enable the components to explicitly begin logging. Messages that
are logged are within the mx.messaging.*
filter. Example 18-4 is an HTTPService
call with a TraceTarget
that will show only log messages
related to the server calls.
Example 18-4. HTTPService call with a TraceTarget that shows log messages related to server calls
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initializeHandler()"> <mx:Script> <![CDATA[ import mx.logging.Log; import mx.logging.targets.TraceTarget; private var _target:TraceTarget; private function initializeHandler():void { _target = new TraceTarget(); _target.includeTime = true; _target.includeLevel = true; _target.includeCategory = true; _target.filters = ["mx.messaging.*"]; Log.addTarget(_target); } private function sendToLog():void { Log.getLogger("com.oreilly.programmingflex.Logging"). info("Log Message"); } ]]> </mx:Script> <mx:Button click="sendToLog()" label="Log Message"/> <mx:Button click="service.send();" label="Send HTTPService"/> <mx:HTTPService id="service" url="http://www.w3c.org"/> </mx:Application>
This example will log messages from the HTTPService
but not from the button click
handler, which can be very useful when you are working with a larger
application and you are interested in viewing only the log information
from the mx.rpc
components. The
server component logs useful information on both the data that is being
sent and received, as well as the information that can be used for
profiling messaging performance. For the WebService
component, this can be especially
useful in gauging Flex’s performance in terms of serializing and
deserializing SOAP messages.
When debugging network programming code, using a data inspector (packet sniffing tools or a proxy) is invaluable. With Flex, these tools can also be very useful. Adobe does not provide such a built-in tool, but many tools exist that work with Flex. If you are already comfortable with a tool, you can continue to use that tool.
Some common network debugging tools include the following:
This cross-platform proxy tool for debugging RPC communication also supports AMF3 (http://www.charlesproxy.com/).
This cross-platform proxy tool for debugging RPC communication supports AMF3 as well (http://kevinlangdon.com/serviceCapture).
This is a feature-complete packet sniffer that is capable of inspecting all traffic for both real-time applications as well as RPC (http://www.wireshark.org).
This is a quick HTTP proxy debugger that is free. It supports RPC debugging, but does not support AMF3 (http://www.fiddlertool.com).