You can use the Flux REST API to interact with a Flux Cluster using an HTTP interface. Complete documentation for the REST API (including input and output payload details for each API) is available in the directory /doc/restapidoc located under your Flux installation directory and also on the Flux Support Portal. For example, the following examples illustrate using CURL to interact with a Flux instance through this REST API.  Any CURL script first needs to perform a signIn to fetch a session cookie, and then save that cookie to a file. All subsequent CURL commands need to submit that cookie file in their request. Finally, a signOut should occur to invalidate the session. Note the syntax may vary depending upon your CURL implementation.

NOTE: For those operating systems that do not provide CURL as a utility program (e.g., Windows), download and install the appropriate version of CURL from here: http://curl.haxx.se/download.html 

Your server name, port, and username:password will need to be changed to match your environment.

SignIn and save session information (a cookie) to a cookies file
curl -c cookies.txt -u admin:admin http://FluxServer:7186/cluster/session/signIn.json

Query the repository of flowcharts
curl -b cookies.txt -u admin:admin http://FluxServer:7186/cluster/repositoryFlowCharts.json
{"count":"1","matched":"1","repositoryElement":{"creationTimestamp":"2013-11-06T21:31:26.179-06:00","creationTimestampFormatted":"06 Nov 2013 @ 21:31:26","id":"2","lastModifiedTimestamp":"2013-11-26T13:17:25.736-06:00","lastModifiedTimestampFormatted":"26 Nov 2013 @ 13:17:25","namespace":"/Workflow","owner":"admin"}}

Insert a workflow named /Workflow into the Flux repository from the current directory

curl -b cookies.txt -F "file=@Workflow.ffc" -u admin:admin http://FluxServer:7186/cluster/repositoryFlowCharts/upload


Returns the message <success/>

Fetch a workflow named /Workflow
curl -b cookies.txt -u admin:admin http://FluxServer:7186/cluster/repositoryFlowCharts/download?namespace=/Workflow
Returns the workflow XML

SignOut of a session
curl -b cookies.txt -d " " http://FluxServer:7186/cluster/session/signOut
Returns: {"message":"Success"}
curl -b cookies.txt -u admin:admin -d " " http://FluxServer:7186/cluster/session/signOut
Returns: {"message":"Success"}

The following example demonstrates calling Flux's RESTful web services using Java. This code makes no assumptions about the returned data – it simply returns the json. But it does demonstrate the use of cookies to move from API call to API call. This jersey jar file must be in your classpath.  jersey-bundle-1.18.jar

Sample Java Code to call Flux REST Services Expand source


A successful run looks like:

Cookie from Server ... JSESSIONID=1v91o3o16klluh4lfkpop8akr;Version=1;Path=/
Output from Server .... {"message":"Success"}
Output from Server .... {"count":"2","matched":"2","repositoryElement":[{"creationTimestamp":"2013-10-25T17:01:48.278Z","creationTimestampFormatted":"25 Oct 2013 @ 17:01:48","id":"27","lastModifiedTimestamp":"2013-10-25T17:03:15.982Z","lastModifiedTimestampFormatted":"25 Oct 2013 @ 17:03:15","namespace":"/FLUX-SAMPLES/MFT-Example","owner":"admin"},{"creationTimestamp":"2013-12-12T16:02:15.031Z","creationTimestampFormatted":"12 Dec 2013 @ 16:02:15","id":"42","lastModifiedTimestamp":"2013-12-12T16:03:09.891Z","lastModifiedTimestampFormatted":"12 Dec 2013 @ 16:03:09","namespace":"/FLUX-SAMPLES/Ping","owner":"admin"}]}
Output from Server .... {"message":"Success"}

A failure to login looks like:

Cookie from Server ... JSESSIONID=1qiy9exofylmw8gj6apirvb9b;Version=1;Path=/
Output from Server .... {"error":"Login failed.","evaluationLicense":"false","ldapSecurity":"false","licenseExpirationFormatted":"","menuItems":null,"pageSize":"0","perpetualLicense":"false","privileges":null,"propertiesInWebapp":"false","redirect":"signIn","secured":"false","supportAndMaintenanceExpirationFormatted":"","timeZone":"Etc/UTC"}
java.lang.RuntimeException: Failed : HTTP error code : 400
at RestJavaClient.main(RestJavaClient.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)




Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.