View comments | RSS feed

Handling service results

When the service function results return from the application server, event handlers use the returned data or handle the returned error information. For example, a result handler could display the results in the Flash application, and an error handler could set trace functions to report the error descriptions. This section describes how to handle result data. The section "Handling errors" describes how to handle error information.

Result-handling hierarchy

Flash Remoting MX supports the following hierarchy of event handling:

  1. If you specify a responder object in the NetConnection object getService method, Flash Remoting MX does the following:
    1. If the responder has a function with a name of the form functionName_Result, where functionName is the name of the service function that you called, Flash Remoting MX returns the result for the function to that method.
    2. If the responder has a function named onResult, Flash Remoting MX returns the result for the function to that function.
  2. If you specify a responder object in the service function call, Flash Remoting MX returns the result to that object's onResult method.

    Note:   Do not specify a responder object in the gatewayConnection.getService method and in the service function call. If you specify the responder in both places, Flash Remoting MX passes the responder you specify in the service function method to the service function as an argument. This behavior causes errors in your application.

  3. When you test an application in Flash MX during development, if there is no appropriate responder object method, Flash displays the results in a message window.

Result-handling strategies

The different types of result handlers provide you with a variety of result-handling strategies you can use to match your application's needs. The following sections describe some of the techniques you can use:

Using the getService method to specify a responder

If you use the gatewayConnection.getService method to specify the responder object, you can use the following techniques:

Example: using a hierarchy of handlers

The following example shows how you can use the main movie as the responder and have a common onResult result handler for some service functions, and function-specific functionName_Result handlers for other functions. In this example, there are two function-specific result handlers, getTemperature_Result and getForecast_Result, which display the returned temperature and forecast in specific text boxes. The default onResult response handler displays the result in a general-purpose message box.

// Initialization code, run once for each movie instance.
if (inited == null)
{
  inited = true;
  NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway")
  gatewayConnection = NetServices.createGatewayConnection();
  // Specify the main movie (this) as the default responder object.
  weatherService = gatewayConnection.getService("flashExamples.weatherStation",
    this); 
}

// Function-specific result handlers
function getTemperature_Result(temperature)
  { temperatureIndicator.text = temperature; }
function getForecast_Result(forecast)
{ forecastIndicator.text = forecast; }
// Default response handler
function onResult(result) 
  { generalMessageBox.text = result; }

// Call the service functions
weatherService.getTemperature("New York");
weatherService.getForecast("Chicago");
weatherService.getServiceStatus("San Francisco");
weatherService.getUsageStats();

Using the service function call to specify a responder

If you specify the responder when you call the service function methods, you can use the following techniques:

Example: specifying unique result objects in service function calls

The following example rewrites the example in the "Example: using a hierarchy of handlers" to have the service function calls specify result handlers. There are three response-handler objects: tempResult for the temperature, forecastResult for the forecast, and generalResult for other service functions. Each result handler has one function, onResult, to handle the result returned by the service.

// Initialization code, run once for each movie instance.
if (inited == null)
{
  inited = true;
  NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway")
  gatewayConnection = NetServices.createGatewayConnection();
  // Do not specify a default responder object when creating the service object.
  weatherService = gatewayConnection.getService("flashExamples.weatherStation"); 
}

// Temperature result handler object
function tempResult()
{
  this.onResult = function (temperature)
  { temperatureIndicator.text = temperature; }
}

//Forecast result handler object
function forecastResult()
{
  this.onResult = function (forecast)
  { forecastIndicator.text = forecast; }
}

// General result handler object
function generalResult ()
{
  this.onResult = function (result) 
  { generalMessageBox.text = result; }
}

// Call the service functions and specify the result handler as the first argument.
weatherService.getTemperature(new tempResult(), "New York");
weatherService.getForecast(new forecastResult(), "Chicago");
weatherService.getServiceStatus(new generalResult(), "San Francisco");
weatherService.getUsageStats(new generalResult());

Comments


No screen name said on Jan 5, 2004 at 11:42 AM :
Hesta koza del dhemonhio no ezta lo zufisientemente ekzplikada !
Adrian Cadena said on Apr 16, 2004 at 12:39 PM :
Dear Macromedia Sirs,

Can you publish a real document where i can find how to manage this king of exception?

"SERVER.PROCESSING"
.....description: "Service threw an exception during method invocation: null"
.....details: "java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at flashgateway.adapter.java.JavaAdapter.invokeFunction(JavaAdapter.java:49)
at flashgateway.filter.AdapterFilter.invoke(AdapterFilter.java:200)
at flashgateway.filter.SecurityFilter.invoke(SecurityFilter.java:84)
at flashgateway.filter.LicenseFilter.invoke(LicenseFilter.java:58)
at flashgateway.filter.ErrorFilter.invoke(ErrorFilter.java:44)
at flashgateway.filter.LogFilter.invoke(LogFilter.java:43)
at flashgateway.filter.BatchProcessFilter.invoke(BatchProcessFilter.java:63)
at flashgateway.filter.DebugFilter.invoke(DebugFilter.java:38)
at flashgateway.filter.SerializationFilter.invoke(SerializationFilter.java:59)
at flashgateway.Gateway.invoke(Gateway.java:184)
at flashgateway.controller.GatewayServlet.service(GatewayServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:226)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: java.lang.NullPointerException
at ec.com.ils.file.delegate.solicitud.SeguridadImplBD.verificarUsuario(SeguridadImplBD.java:119)
at ec.com.ils.file.flash.solicitud.Seguridad.verificarUsuario(Seguridad.java:88)
... 23 more
"
.....level: "error"
.....type: "java.lang.reflect.InvocationTargetException"
No screen name said on Jun 17, 2004 at 6:42 PM :
I'll second that. I'm having the same issue -- and it's related to my installation because same code works on another machine. Call CF cfc file (which works correctly when called from cfm file) and get error

Service threw an exception during method invocation: null"
.....details: "java.lang.NullPointerException

"Service threw an exception during method invocation: null"
.....details: "java.lang.NullPointerException
at coldfusion.runtime.TemplateClassLoader.findApplicationCfm(Unknown Source)
at coldfusion.filter.ApplicationFilter.invoke(Unknown Source)
at coldfusion.filter.FlashTemplateFilter.invoke(Unknown Source)
at coldfusion.filter.FlashFilter.invoke(Unknown Source)
at coldfusion.filter.LicenseFilter.invoke(Unknown Source)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(Unknown Source)
at coldfusion.filter.GlobalsFilter.invoke(Unknown Source)
at coldfusion.filter.DatasourceFilter.invoke(Unknown Source)
at coldfusion.flash.FlashProxy.invokeTemplate(Unknown Source)
at flashgateway.adapter.coldfusion.ColdFusionAdapter.invokeFunction(ColdFusionAdapter.java:107)
at flashgateway.filter.AdapterFilter.invoke(AdapterFilter.java:266)
at flashgateway.filter.SecurityFilter.invoke(SecurityFilter.java:84)
at flashgateway.filter.LicenseFilter.invoke(LicenseFilter.java:58)
at flashgateway.filter.ErrorFilter.invoke(ErrorFilter.java:44)
at flashgateway.filter.LogFilter.invoke(LogFilter.java:43)
at flashgateway.filter.BatchProcessFilter.invoke(BatchProcessFilter.java:63)
at flashgateway.filter.DebugFilter.invoke(DebugFilter.java:38)
at flashgateway.filter.SerializationFilter.invoke(SerializationFilter.java:59)
at flashgateway.Gateway.invoke(Gateway.java:194)
at flashgateway.controller.GatewayServlet.service(GatewayServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:226)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:348)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:294)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
"
.....level: "error"
.....type: "java.lang.NullPointerException"
Mark Kerecz said on Jul 5, 2004 at 1:46 PM :
In regards to results being sent back from a service call to a cfc function.. ...
is it possible to have a variable/value sent along with a a query so that i can target a specific object within my flash environment. i have an array of objects in which each object makes a call to a service to receive a recordset. i made a loop to cycle through the objects and fetch the recordsets but have not considered that the function for handling _Results won't have a direct path to the object requiring the fetched recordset. . .. . i've searched for this info and have been unsuccessful so far in finding an answer. .. .

thanks!
mark

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/UseActionScript7.htm