Providing File Web Services
Besides the possibility of providing X4 processes as ReSTful services via HTTP (S), the X4 Webservices interface also allows to provide static file resources from the repository as service via HTTP GET.
Prerequisites:
- A file within the repository, which is to be provided as file service via HTTP. The file is referenced via its
x4db:/ URL
, thereby. - A URL part, under which the file shall be accessible via HTTP, e.g.
http://localhost:8080/X4/httpstarter/ReST/MyFile
. Normally, you have already defined this URL part (as constant, variable or remainder) within the webservice configuration, see Graphically Editing the Web Service Configuration.
Providing File Resources via HTTP
Create a new
File
service entry under the desired URL resource (defined e.g. by means of a constant or variable URL part) via the context menu Add File Service.Specify the
x4db:/
path to the desired file, whose content shall be provided unalteredly as file resource via HTTP, within the repository in Path.Within the X4 Webservice Configuration Editor, you can assign a file from the repository by drag & drop.- Adjust the security realms (Guest Allowed, Token Return etc.), if required.
- Save and apply the web service configuration with Reload on Server.
The changes will be active instantly and the file web service will be provided.
Using File Web Services with Variables
The path specification to the repository file within the attribute path
can be built dynamically by defining the file service in a variable block, for example for changing file names or IDs within a variable URL part. The assignment is done based on the variable name, e.g. <myVar>
.
Example: Definition of a FILE service as constant (excerpt from the restconfig.xml)
<Variable name="myVar">
<Service type="File" path="x4db:/1/Project/Folder/<myVar>"/>
</Variable>
Explanations:
- The element
<Variable/>
defines within its attributename
the name of a variable, e.g.myVar
. - In attribute
path
this variable is referenced as placeholder at any place within thex4db:/
URL; multiple mentions of the placeholder are also possible. - The placeholder always begins with an opening angle bracket
<
(<
in XML storage format), followed by the variable name and a closing angle bracket>
.
Example: Variable placeholder at any position (excerpt from restconfig.xml)
<Constant value="varied_1">
<Variable name="VAR">
<Service type="File" path="x4db:/1/RestExamples/file/varied_1/<VAR>"/>
</Variable>
</Constant>
<Constant value="varied_2">
<Variable name="VAR">
<Service type="File" path="x4db:/1/RestExamples/file/varied_1/<VAR>.png"/>
</Variable>
</Constant>
Example: Combined variables (excerpt from XML storage format)
<Constant value="varied_3">
<Variable name="TYPE">
<Variable name="PART">
<Service type="File"
path="x4db:/1/RestExamples/file/deep/<TYPE>/<PART>.<TYPE>"/>
</Variable>
</Variable>
</Constant>
<Constant value="varied_4">
<Variable name="VAR">
<Constant value="image">
<Service type="File"
path="x4db:/1/RestExamples/file/varied_1/<VAR>.png"/>
</Constant>
</Variable>
</Constant>
Using File Web Services with Remainder
If you want to define a file web service with any URL parts, you can use the Remainder construct. As a more tolerant variant of a variable, it allows to intercept URL parts of any depth. Similar to variables, you define a remainder with a name and reference it within the attribute path
.
Example: Definition of a FILE service with remainder (excerpt from XML storage format)
<Remainder name="myRemainderVar">
<Service type="File"
path="x4db:/1/Project/Folder/<myRemainderVar>"/>
</Remainder>
Explanations:
- The element
<Remainder/>
defines within the attributename
the name of a remainder variable, e.g.myRemainderVar
. - In attribute
path
this variable is referenced as placeholder at any place within thex4db:/
URL; multiple mentions of the placeholder are also possible. - The placeholder always begins with an opening angle bracket
<
(or<
in XML storage format), followed by the variable name and a closing angle bracket>
.
Example: Further examples for remainders (excerpt from XML storage format)
<Constant value="deep_1">
<Remainder name="VAR">
<Service type="File"
path="x4db:/1/RestExamples/file/deep/<VAR>"/>
</Remainder>
</Constant>
<Constant value="deep_2">
<Remainder name="VAR">
<Service type="File"
path="x4db:/1/RestExamples/file/deep/<VAR>.png"/>
</Remainder>
</Constant>
Caching of Provided File Resources
Each file resource provided by means of a file web service via HTTP GET has a validity of 10 hours. Thus, the client (e.g. a Web browser) re-invokes the resource only after the expiration of this period.
To load the current resource for development or test purposes, set back the cache within the client manually or deactivate it.