• Flux News
  • Flux Blogs
  • David
  • Eric
  • Arul
  • Brian
  • Flux Website

arul @ flux : June 2008

Previous Next
0

REST Action in Flux 8.0

Posted by arul 19-Jun-2008

REST is an architectural style in which software components are modeled as resources accessed over the web which are identified by unique URIs. These resources are traditionally accessed using HTTP. For example, the typical CRUD operations involve read (HTTP GET), create (HTTP POST), update (HTTP PUT), delete (HTTP DELETE). All these operations can be modeled using REST interface. There are some popular web search APIs which are modeled as REST interfaces. One such example is Yahoo Search API (http://developer.yahoo.com/search/rest.html).

Flux 8.0 will ship with a built-in REST Action. The REST Action will allow you to invoke REST services from flow charts and use the result, or response, from the REST service throughout subsequence actions in the flow chart.

The REST service URL is followed by the actual query parameters, which take the form argument=value. Multiple parameters are separated by an ampersand (&). Here is how the REST Action can be used with in a flow chart in Flux 8.0.

Engine engine = new Engine();

FlowChart job = new FlowChart("REST Action Example");

// Create the Rest Action
RestAction restAction = job.makeRestAction("REST GET Action");

// Specify the URL the rest action is to use.
restAction.setUrl("http://search.yahooapis.com/WebSearchService/V1/webSearch");

// Specify the action type.
restAction.setActionType("get");

// Specify the arguments to pass to the method.
Properties inputParams = new Properties();
inputParams.put("appid", "YahooDemo");
inputParams.put("query", "rest");
inputParams.put("results", "2");

restAction.setInputParams(inputParams);

// Create a Console Action to display the result from the Web service
ConsoleAction consoleAction = job.makeConsoleAction("Display REST Action Result");

// Variable susbtitution is used to access the RESULT flow context variable
consoleAction.setMessage("The result from the REST service is: ${result}\n");

// Make the REST Action flow into the Console Action
restAction.addFlow(consoleAction);

// Schedule the job for immediate execution.
String jobId = engine.put(job);

// Start the engine.
engine.start();

// Give the engine a chance to run the job, up to 5 seconds.
engine.join(jobId, "+5s");

// Clean up the resources.
engine.dispose();

This program invokes the Yahoo Search API and the response is printed to the console.

If you have requirements to integrate a Flux application with a RESTful service, REST Action comes handy in providing this simple integration.

0 Comments 0 References Permalink
Click to view arul's profile

arul

Member since: 27-Feb-2008

Arul is a software developer at Flux. He is very passionate about Java and JEE technologies.

View arul's profile


Number of subscribers for arul @ flux

Recent Comments

No recent comments.

Popular Tags

View all