How to set the URL for ServerActions (RoundtripHandler / DownloadHandler)

Questions & Answers

Summary

This article shows the different ways to set the URL for server actions like roundtripping or download / upload.

Description

Terminology

In yFiles Flex the different parts of an URL are handled differently. Thus, we have to define the teminology first. An URL is composed from context root, service name and service extension:

http://localhost:40936/Web%20App/theWebService.ashx

context-root service name .service extension

Even if the application adresses more than one service, the context root and the service extension usually don't differ. Thus, it makes sense to define a default. If not set, these values are http://localhost:8080/ as context root and an empty String as service extension.

Setting a default context root and service extension via Config

The context root and service extension properties can be set using Config, setting the corresponding elements in the file config.xml:

<context-root>http://localhost:8080/yfiles-flex/</context-root>
<service-extension></service-extension>

The above code sets the context root to http://localhost:8080/yfiles-flex/ and the service extension to an empty String.

If you set these properties using config.xml make sure that the server is not called before the config is read (i.e. after Event.COMPLETE is fired).

Using the DemoConfigTool and an embedded config.xml (available since yFiles FLEX 1.4)

The demo.DemoConfigTool is available and used in the flex demos. It tries to find the correct context root and server extension by trying to connect to a test servlet. If a working configuration could be found it is set as default and stored in the local storage of the Flash Player.
The following configurations are tested:

  • The configuration set in the config.xml which was embedded into the DemoConfigTool at compile time.
  • The context root "http://localhost:8080/yfiles-flex/" with the service extension set in the config.xml
  • The relative context root "../../" with the service extension set in the config.xml. This configuration is only tested if the application runs in the sandboxType Security.REMOTE.
  • The configuration previously stored in the local storage (if existing).
If neither of these approaches succeeds a dialog is displayed allowing the user to enter the correct configuration.

Setting a default context root and service extension using HttpServiceFactory

To set the defaults for context root and service extension without using a config file one can use the defaultContextRoot and defaultServiceExtension property of HttpServiceFactory: HttpServiceFactory.defaultContextRoot = "http://localhost:8080/yfiles-flex/"; HttpServiceFactory.defaultServiceExtension = "";

Don't use default settings

It is possible to pass full URLs instead of passing only the service name as parameter to the RoundtripHandler. To do so, set the resolveURLs and the appendExtension property of HttpServiceFactory to false: HttpServiceFactory.resolveURLs = false; HttpServiceFactory.appendExtension = false;

How to set the URLs / service names to the handlers

  • RoundtripHandler: The service name has to be passed in the constructor: var handler:RoundtripHandler = new RoundtripHandler(graphCanvas, "serviceName"); The URL will be created from that name and the default settings for the context root and the extension. In order to pass a full URL, one has to disable that feature first HttpServiceFactory.resolveURLs = false; HttpServiceFactory.appendExtension = false; var handler:RoundtripHandler = new RoundtripHandler(graphCanvas, "http://root/serviceName.extension");
  • DownloadHandler, UploadHandler, ImageExportHandler: Unlike RoundtripHandler, these handlers take a full URL as parameter: var download:DownloadHandler = new DownloadHandler("http://root/serviceName.extension", readWriteHandler); download.download(graphCanvas.graph, "thegraph.graphml"); If one wants to use the default settings with these handlers, too, HttpServiceFactory offers the convenience method getService(serviceName:String):HTTPService for creating a full URL from a service name: download = new DownloadHandler(HttpServiceFactory.getService("serviceName").url, readWriteHandler);

Categories this article belongs to:
yFiles FLEX > Communicating with the Server > Remote Communication in yFiles FLEX
Applies to:
yFiles FLEX: 1.4, 1.5, 1.6, 1.7, 1.8
Keywords:
URL - roundtrip - RoundtripHandler - Config - config.xml - HttpServiceFactory