Dynamic Reading of Files
With the <<URLAdapter>> it is also possible to use dynamic parameters. The following example shows this using the file protocol. The dynamic parameter can also be used together with the HTTP protocol (GET or POST).
The activity diagram below shows how to manipulate the URL backend parameters, which are set in the component diagram.
Figure: Dynamic Read Request
The deployment macro getHostFromAlias() reads the name of the component instance; in this case localhost. The deployment macro getProtocolFromAlias() reads the tagged value protocol defined on the backend service artifact or backend interface artifact (in the present case the protocol value is file). The deployment macro
getMethodFromAlias() reads the tagged value method defined on the backend service artifact or backend interface artifact (in the present case it is defined on the interface artifact and has the value read).
Figure: Component Diagram for Accessing a File via the URL Adapter
The example above reads a file, which is stored on the localhost (meaning the machine where this configuration instance is deployed to). The path with filename is given from outside (input parameter which is sent by the client) and is then combined with the parameter of the deployment diagram resulting in the complete URL. If the client sends as inputFile string d:/mytext.txt the resulting url would be:
Writing to a file follows the same rules like reading one. An additional parameter is used called content of type Blob, which defines the content of the file, which should be written to the server. In the component diagram, you have also to define POST instead of Read.
The example below creates a file, reads the created file, and provides the client with the content of the file (which has been given as input string).
Figure: Writing a File Using the URL Adapter
Find below a list of relevant tagged values, if the URL adapter is used with the file protocol.
Default values used when an option is not explicitly set are written in bold.
|method||File operation method.||read, write|
|a valid file path, absolute or relative to the Bridge data directory.|