blob: 973524045ee8b36c1ec2261c3cce3bc4b99f0a92 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="SMILA/Documentation/Using The ReST API,SMILA/Documentation/Data Model and Serialization Formats,SMILA/Documentation/HowTo/How to access the REST API with the RestClient,SMILA/Documentation/JettyHttpServer,SMILA/REST API Reference" />
<link rel="shortcut icon" href="http://wiki.eclipse.org/SMILA/Documentation/favicon.ico" />
<link rel="search" type="application/opensearchdescription+xml" href="http://wiki.eclipse.org/opensearch_desc.php" title="Eclipsepedia (English)" />
<link rel="alternate" type="application/rss+xml" title="Eclipsepedia RSS Feed" href="http://wiki.eclipse.org/index.php?title=Special:Recentchanges&amp;feed=rss" />
<link rel="alternate" type="application/atom+xml" title="Eclipsepedia Atom Feed" href="http://wiki.eclipse.org/index.php?title=Special:Recentchanges&amp;feed=atom" />
<title>SMILA/Documentation/Using The ReST API - Eclipsepedia</title>
<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "http://wiki.eclipse.org/skins/eclipsenova/novaWide.css?116"; /*]]>*/</style>
<link rel="stylesheet" type="text/css" media="print" href="http://wiki.eclipse.org/skins/eclipsenova/eclipsenovaPrint.css?116" />
<link rel="stylesheet" type="text/css" media="handheld" href="http://wiki.eclipse.org/skins/eclipsenova/handheld.css?116" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/header.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/tabs.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/visual.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/layout.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/footer.css" media="screen" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="/skins/eclipsenova/IEpngfix.css" media="screen" /><![endif]-->
<!--[if lt IE 5.5000]><style type="text/css">@import "/skins/eclipsenova/IE50Fixes.css?116";</style> <![endif]-->
<!--[if IE 5.5000]><style type="text/css">@import "/skins/eclipsenova/IE55Fixes.css?116";</style><![endif]-->
<!--[if IE 6]><style type="text/css">@import "/skins/eclipsenova/IE60Fixes.css?116";</style><![endif]-->
<!--[if IE 7]><style type="text/css">@import "/skins/eclipsenova/IE70Fixes.css?116";</style><![endif]-->
<!--[if lt IE 7]><script type="text/javascript" src="/skins/common/IEFixes.js?116"></script>
<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
<script type= "text/javascript">/*<![CDATA[*/
var skin = "eclipsenova";
var stylepath = "/skins";
var wgArticlePath = "/$1";
var wgScriptPath = "";
var wgScript = "/index.php";
var wgServer = "http://wiki.eclipse.org";
var wgCanonicalNamespace = "";
var wgCanonicalSpecialPageName = false;
var wgNamespaceNumber = 0;
var wgPageName = "SMILA/Documentation/Using_The_ReST_API";
var wgTitle = "SMILA/Documentation/Using The ReST API";
var wgAction = "view";
var wgRestrictionEdit = [];
var wgRestrictionMove = [];
var wgArticleId = "35475";
var wgIsArticle = true;
var wgUserName = null;
var wgUserGroups = null;
var wgUserLanguage = "en";
var wgContentLanguage = "en";
var wgBreakFrames = false;
var wgCurRevisionId = "292687";
var wgVersion = "1.12.0";
var wgEnableAPI = true;
var wgEnableWriteAPI = false;
/*]]>*/</script>
<script type="text/javascript" src="http://wiki.eclipse.org/skins/common/wikibits.js?116"><!-- wikibits js --></script>
<!-- Performance mods similar to those for bug 166401 -->
<script type="text/javascript" src="http://wiki.eclipse.org/index.php?title=-&amp;action=raw&amp;gen=js&amp;useskin=eclipsenova"><!-- site js --></script>
<!-- Head Scripts -->
<script type="text/javascript" src="http://wiki.eclipse.org/skins/common/ajax.js?116"></script>
<style type="text/css">/*<![CDATA[*/
.source-javascript {line-height: normal; font-size: medium;}
.source-javascript li {line-height: normal;}
/**
* GeSHi Dynamically Generated Stylesheet
* --------------------------------------
* Dynamically generated stylesheet for javascript
* CSS class: source-javascript, CSS id:
* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter)
*/
.source-javascript .de1, .source-javascript .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}
.source-javascript {}
.source-javascript .head {}
.source-javascript .foot {}
.source-javascript .imp {font-weight: bold; color: red;}
.source-javascript .ln-xtra {color: #cc0; background-color: #ffc;}
.source-javascript li {font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;}
.source-javascript li.li2 {font-weight: bold;}
.source-javascript .kw1 {color: #000066; font-weight: bold;}
.source-javascript .kw2 {color: #003366; font-weight: bold;}
.source-javascript .kw3 {color: #000066;}
.source-javascript .co1 {color: #009900; font-style: italic;}
.source-javascript .coMULTI {color: #009900; font-style: italic;}
.source-javascript .es0 {color: #000099; font-weight: bold;}
.source-javascript .br0 {color: #66cc66;}
.source-javascript .st0 {color: #3366CC;}
.source-javascript .nu0 {color: #CC0000;}
.source-javascript .me1 {color: #006600;}
.source-javascript .sc0 {}
.source-javascript .sc1 {}
.source-javascript .sc2 {}
.source-javascript .sc3 {}
.source-javascript .re0 {color: #0066FF;}
/*]]>*/
</style>
<style type="text/css">/*<![CDATA[*/
@import "http://wiki.eclipse.org/index.php?title=MediaWiki:Geshi.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";
/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-text {line-height: normal; font-size: medium;}
.source-text li {line-height: normal;}
/**
* GeSHi Dynamically Generated Stylesheet
* --------------------------------------
* Dynamically generated stylesheet for text
* CSS class: source-text, CSS id:
* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter)
*/
.source-text .de1, .source-text .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}
.source-text {}
.source-text .head {}
.source-text .foot {}
.source-text .imp {font-weight: bold; color: red;}
.source-text .ln-xtra {color: #cc0; background-color: #ffc;}
.source-text li {font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;}
.source-text li.li2 {font-weight: bold;}
/*]]>*/
</style>
<style type="text/css">/*<![CDATA[*/
@import "http://wiki.eclipse.org/index.php?title=MediaWiki:Geshi.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";
/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-java {line-height: normal; font-size: medium;}
.source-java li {line-height: normal;}
/**
* GeSHi Dynamically Generated Stylesheet
* --------------------------------------
* Dynamically generated stylesheet for java
* CSS class: source-java, CSS id:
* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter)
*/
.source-java .de1, .source-java .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}
.source-java {}
.source-java .head {}
.source-java .foot {}
.source-java .imp {font-weight: bold; color: red;}
.source-java .ln-xtra {color: #cc0; background-color: #ffc;}
.source-java li {font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;}
.source-java li.li2 {font-weight: bold;}
.source-java .kw1 {color: #7F0055; font-weight: bold;}
.source-java .kw2 {color: #7F0055; font-weight: bold;}
.source-java .kw3 {color: #000000; font-weight: normal}
.source-java .kw4 {color: #7F0055; font-weight: bold;}
.source-java .co1 {color: #3F7F5F; font-style: italic;}
.source-java .co2 {color: #3F7F5F;}
.source-java .co3 {color: #3F7F5F; font-style: italic; font-weight: bold;}
.source-java .coMULTI {color: #3F5FBF; font-style: italic;}
.source-java .es0 {color: #000000;}
.source-java .br0 {color: #000000;}
.source-java .st0 {color: #2A00ff;}
.source-java .nu0 {color: #000000;}
.source-java .me1 {color: #000000;}
.source-java .me2 {color: #000000;}
/*]]>*/
</style>
<style type="text/css">/*<![CDATA[*/
@import "http://wiki.eclipse.org/index.php?title=MediaWiki:Geshi.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";
/*]]>*/
</style><link rel="stylesheet" type="text/css" href="Using_The_ReST_API.html" /> </head>
<body class="mediawiki ns-0 ltr page-SMILA_Documentation_Using_The_ReST_API">
<div id="globalWrapper">
<div id="column-one">
<!-- Eclipse Additions for the Top Nav start here M. Ward-->
<div id="header">
<div id="header-graphic">
<img src="http://wiki.eclipse.org/skins/eclipsenova/eclipse.png" alt="Eclipse Wiki">
</div>
<!-- Pulled 101409 Mward -->
<div class="portlet" id="p-personal">
<div class="pBody">
<ul>
<li id="pt-login"><a href="http://wiki.eclipse.org/index.php?title=Special:Userlogin&amp;returnto=SMILA/Documentation/Using_The_ReST_API">Log in</a></li>
</ul>
</div>
</div>
<div id="header-icons">
<div id="sites">
<ul id="sitesUL">
<li><a href="http://www.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/eclipseIcon.png" width="28" height="28" alt="Eclipse Foundation" title="Eclipse Foundation" /><div>Eclipse Foundation</div></a></li>
<li><a href="http://marketplace.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/marketplace.png" width="28" height="28" alt="Eclipse Marketplace" title="Eclipse Marketplace" /><div>Eclipse Marketplace</div></a></li>
<li><a href="https://bugs.eclipse.org/bugs"><img src="http://dev.eclipse.org/custom_icons/system-search-bw.png" width="28" height="28" alt="Bugzilla" title="Bugzilla" /><div>Bugzilla</div></a></li>
<li><a href="http://live.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/audio-input-microphone-bw.png" width="28" height="28" alt="Live" title="Live" /><div>Eclipse Live</div></a></li>
<li><a href="http://planeteclipse.org"><img src="http://dev.eclipse.org/large_icons/devices/audio-card.png" width="28" height="28" alt="PlanetEclipse" title="Planet" /><div>Planet Eclipse</div></a></li>
<li><a href="http://portal.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/preferences-system-network-proxy-bw.png" width="28" height="28" alt="Portal" title="Portal" /><div>My Foundation Portal</div></a></li>
</ul>
</div>
</div>
</div>
<!-- NEW HEADER STUFF HERE -->
<div id="header-menu">
<div id="header-nav">
<ul> <li><a class="first_one" href="http://wiki.eclipse.org/" target="_self">Home</a></li> <li><a href="http://www.eclipse.org/downloads/" target="_self">Downloads</a></li>
<li><a href="http://www.eclipse.org/users/" target="_self">Users</a></li>
<li><a href="http://www.eclipse.org/membership/" target="_self">Members</a></li>
<li><a href="http://wiki.eclipse.org/index.php/Development_Resources" target="_self">Committers</a></li>
<li><a href="http://www.eclipse.org/resources/" target="_self">Resources</a></li>
<li><a href="http://www.eclipse.org/projects/" target="_self">Projects</a></li>
<li><a href="http://www.eclipse.org/org/" target="_self">About Us</a></li>
</ul>
</div>
<div id="header-utils">
<!-- moved the search window here -->
<form action="http://wiki.eclipse.org/Special:Search" >
<input class="input" name="search" type="text" accesskey="f" value="" />
<input type='submit' onclick="this.submit();" name="go" id="searchGoButton" class="button" title="Go to a page with this exact name if one exists" value="Go" />&nbsp;
<input type='submit' onclick="this.submit();" name="fulltext" class="button" id="mw-searchButton" title="Search Eclipsepedia for this text" value="Search" />
</form>
</div>
</div>
<!-- Eclipse Additions for the Header stop here -->
<!-- Additions and mods for leftside nav Start here -->
<!--Started nav rip here-->
<!-- these are the nav controls main page, changes etc -->
<div id="novaContent" class="faux">
<div id="leftcol">
<ul id="leftnav">
<!-- these are the page controls, edit history etc -->
<li class="separator"><a class="separator">Navigation &#160;&#160;</li>
<li id="n-mainpage"><a href="http://wiki.eclipse.org/Main_Page">Main Page</a></li>
<li id="n-portal"><a href="http://wiki.eclipse.org/Eclipsepedia:Community_Portal">Community portal</a></li>
<li id="n-currentevents"><a href="http://wiki.eclipse.org/Eclipsepedia:Current_events">Current events</a></li>
<li id="n-recentchanges"><a href="http://wiki.eclipse.org/Special:Recentchanges">Recent changes</a></li>
<li id="n-randompage"><a href="http://wiki.eclipse.org/Special:Random">Random page</a></li>
<li id="n-help"><a href="http://wiki.eclipse.org/Help:Contents">Help</a></li>
<li class="separator"><a class="separator">Toolbox &#160;&#160;</a></li>
<li id="t-whatlinkshere"><a href="http://wiki.eclipse.org/Special:Whatlinkshere/SMILA/Documentation/Using_The_ReST_API">What links here</a></li>
<li id="t-recentchangeslinked"><a href="http://wiki.eclipse.org/Special:Recentchangeslinked/SMILA/Documentation/Using_The_ReST_API">Related changes</a></li>
<!-- This is the toolbox section -->
<li id="t-upload"><a href="http://wiki.eclipse.org/Special:Upload">Upload file</a></li>
<li id="t-specialpages"><a href="http://wiki.eclipse.org/Special:Specialpages">Special pages</a></li>
<li id="t-print"><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/Using_The_ReST_API&amp;printable=yes">Printable version</a></li> <li id="t-permalink"><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/Using_The_ReST_API&amp;oldid=292687">Permanent link</a></li> </ul>
</div>
<!-- Additions and mods for leftside nav End here -->
<div id="column-content">
<div id="content">
<a name="top" id="top"></a>
<div id="tabs">
<ul class="primary">
<li class="active"><a href="Using_The_ReST_API.html"><span class="tab">Page</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=Talk:SMILA/Documentation/Using_The_ReST_API&amp;action=edit"><span class="tab">Discussion</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/Using_The_ReST_API&amp;action=edit"><span class="tab">View source</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/Using_The_ReST_API&amp;action=history"><span class="tab">History</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=Special:Userlogin&amp;returnto=SMILA/Documentation/Using&#32;The&#32;ReST&#32;API"><span class="tab">Edit</span></a></li>
</ul>
</div>
<script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
<h1 class="firstHeading">SMILA/Documentation/Using The ReST API</h1>
<div id="bodyContent">
<h3 id="siteSub">From Eclipsepedia</h3>
<div id="contentSub"><span class="subpages">&lt; <a href="../../SMILA.html" title="SMILA">SMILA</a> | <a href="../Documentation.1.html" title="SMILA/Documentation">Documentation</a></span></div>
<div id="jump-to-nav">Jump to: <a href="Using_The_ReST_API.html#column-one">navigation</a>, <a href="Using_The_ReST_API.html#searchInput">search</a></div> <!-- start content -->
<p>Most functionality of SMILA is already accessible via an HTTP ReST API using JSON to represent data.
This means basically that you can control and monitor a running SMILA server using your web browser (at least with some small plugins).
Also, it is relatively simple to talk to SMILA programmatically or using scripts. On this page we will recommend some tools and
best practices to work with SMILA.
</p><p>Feel free to extend this page if you find interesting tools that you want to recommend to other SMILA users.
</p>
<table id="toc" class="toc" summary="Contents"><tr><td><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1"><a href="Using_The_ReST_API.html#Basics"><span class="tocnumber">1</span> <span class="toctext">Basics</span></a></li>
<li class="toclevel-1"><a href="Using_The_ReST_API.html#Interactive_Tools"><span class="tocnumber">2</span> <span class="toctext">Interactive Tools</span></a>
<ul>
<li class="toclevel-2"><a href="Using_The_ReST_API.html#Web_Browser_Add-Ons"><span class="tocnumber">2.1</span> <span class="toctext">Web Browser Add-Ons</span></a></li>
<li class="toclevel-2"><a href="Using_The_ReST_API.html#Shell_scripting"><span class="tocnumber">2.2</span> <span class="toctext">Shell scripting</span></a>
<ul>
<li class="toclevel-3"><a href="Using_The_ReST_API.html#Posting_attachments_from_shell_scripts"><span class="tocnumber">2.2.1</span> <span class="toctext">Posting attachments from shell scripts</span></a></li>
</ul>
</li>
</ul>
</li>
<li class="toclevel-1"><a href="Using_The_ReST_API.html#Programmatical_Access"><span class="tocnumber">3</span> <span class="toctext">Programmatical Access</span></a>
<ul>
<li class="toclevel-2"><a href="Using_The_ReST_API.html#SMILA_RestClient"><span class="tocnumber">3.1</span> <span class="toctext">SMILA RestClient</span></a></li>
<li class="toclevel-2"><a href="Using_The_ReST_API.html#Apache_HttpClient_4.x"><span class="tocnumber">3.2</span> <span class="toctext">Apache HttpClient 4.x</span></a></li>
<li class="toclevel-2"><a href="Using_The_ReST_API.html#Apache_HttpClient_3.1"><span class="tocnumber">3.3</span> <span class="toctext">Apache HttpClient 3.1</span></a></li>
</ul>
</li>
</ul>
</td></tr></table><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </script>
<a name="Basics"></a><h2> <span class="mw-headline"> Basics </span></h2>
<p>An HTTP ReST API consists of a set of URLs that can be invoked using standard HTTP requests. One URL refers to a "resource" in the system, which may be a service or some element managed by a service. Each resource may support several HTTP methods for different operations, but not each resource will support every method. In SMILA we use the following methods, usually with one of the described semantics:
</p>
<ul><li> <tt>GET</tt>: get the content, definition or description of the resource; get statistic data or state information about the resource
</li><li> <tt>POST</tt>: execute the main functionality of the resource (e.g. execute a pipeline); add or update a sub element of the resource
</li><li> <tt>PUT</tt>: set the content, definition, or description of the resource
</li><li> <tt>DELETE</tt>: clear the contents of the resource; remove an element from the resource.
</li></ul>
<p>Most resources should at least support the <tt>GET</tt> method which is the method used by the web browser when you enter the URL, and the result should contain links to resources associated with this resource. So you can explore the system state with your web browser.
</p><p><tt>GET</tt> and <tt>DELETE</tt> requests never have a request body, parameters must be passed by using <tt>...?param1=value1&amp;param2=value2</tt> in the URL. With <tt>POST</tt> and <tt>PUT</tt> requests the data is passed in the request body as a JSON object, i.e. a JSON string like this:
</p>
<div dir="ltr" style="text-align: left;"><pre class="source-javascript"><span class="br0">&#123;</span>
<span class="st0">&quot;param1&quot;</span>: <span class="st0">&quot;value1&quot;</span>,
<span class="st0">&quot;param2&quot;</span>: <span class="st0">&quot;value2
}</span></pre></div>
<p>In SMILA, this corresponds to the <a href="Data_Model_and_Serialization_Formats.html#Concepts" title="SMILA/Documentation/Data Model and Serialization Formats">metadata part of a record</a>. In <tt>POST</tt> requests it is also possible to add binary attachments, see <a href="JettyHttpServer.html#Attachments" title="SMILA/Documentation/JettyHttpServer">Documentation of the SMILA HTTP server</a> for details. Finally, some resources accept or produce so-called "JSON bulks". This means that it is possible to send or get a bunch of records in a single request. The JSON of the record metadata must then be printed on a single line, and the records are separated by newlines. However, it is not possible to add attachments to such records.
</p><p>See <a href="../REST_API_Reference.html" class="mw-redirect" title="SMILA/REST API Reference">SMILA/REST_API_Reference</a> for a list of available resources and links to documentation.
</p>
<a name="Interactive_Tools"></a><h2> <span class="mw-headline"> Interactive Tools </span></h2>
<a name="Web_Browser_Add-Ons"></a><h3> <span class="mw-headline"> Web Browser Add-Ons </span></h3>
<p>For most web browsers there are free add-ons available that support pretty-printed viewing of JSON documents and the interactive invocation of ReST commands.
</p>
<ul><li> JSON viewer: By default browsers do not know how to handle JSON results and will suggest to download them to a file. There are add-ons that display the JSON right in the browser, nicely formatted and highlighted and make contained URLs clickable, which makes it easy to explore the system state
<ul><li> Firefox: <a href="https://addons.mozilla.org/de/firefox/addon/jsonview/" class="external text" title="https://addons.mozilla.org/de/firefox/addon/jsonview/" rel="nofollow">JSONView</a>
</li><li> Chrome: <a href="https://chrome.google.com/webstore/detail/chklaanhfefbnpoihckbnefhakgolnmc" class="external text" title="https://chrome.google.com/webstore/detail/chklaanhfefbnpoihckbnefhakgolnmc" rel="nofollow">JSONView</a>
</li><li> Opera: <a href="https://addons.opera.com/addons/extensions/details/jsonviewer/" class="external text" title="https://addons.opera.com/addons/extensions/details/jsonviewer/" rel="nofollow">JSONViewer</a>
</li></ul>
</li><li> ReST Client: ReST Client allow to compose other requests than <tt>GET</tt> requests with the browser. They allow to enter the resource URL, select the request method, and add the request body content, and then you can execute the request and view the result. There are lots of these add-ons out there, we can recommend the following:
<ul><li> Firefox: <a href="https://addons.mozilla.org/de/firefox/addon/restclient/" class="external text" title="https://addons.mozilla.org/de/firefox/addon/restclient/" rel="nofollow">REST Client</a>
</li><li> Chrome:
<ul><li> <a href="https://chrome.google.com/webstore/detail/baedhhmoaooldchehjhlpppaieoglhml" class="external text" title="https://chrome.google.com/webstore/detail/baedhhmoaooldchehjhlpppaieoglhml" rel="nofollow">cREST Client</a>: Easy to use and keeps a nice history of the executed requests so that it is easy to repeat sequences of commands for test purposes.
</li><li> <a href="https://chrome.google.com/webstore/detail/hgmloofddffdnphfgcellkdfbfbjeloo" class="external text" title="https://chrome.google.com/webstore/detail/hgmloofddffdnphfgcellkdfbfbjeloo" rel="nofollow">Advanced REST client application</a>: A bit harder to use, but the only one we currently know of that lets you create "multipart" requests containing record attachments: In the following screenshot we have created a request to submit a record (first file field contains name of a JSON file) with an attachment (second file field) to the "indexUpdate" job: <br /> <a href="http://wiki.eclipse.org/Image:SMILA-SendAttachmentWithAdvancedRestClient.png" class="image" title="SMILA-SendAttachmentWithAdvancedRestClient.png"><img alt="" src="http://wiki.eclipse.org/images/thumb/a/a5/SMILA-SendAttachmentWithAdvancedRestClient.png/600px-SMILA-SendAttachmentWithAdvancedRestClient.png" width="600" height="481" border="0" /></a>
</li></ul>
</li><li> Opera: <a href="https://addons.opera.com/de/addons/extensions/details/simple-rest-client/1.3/" class="external text" title="https://addons.opera.com/de/addons/extensions/details/simple-rest-client/1.3/" rel="nofollow">Simple REST Client</a>: Very simple only.
</li></ul>
</li></ul>
<a name="Shell_scripting"></a><h3> <span class="mw-headline"> Shell scripting </span></h3>
<p>Basically, it is possible to work with the ReST API using generic HTTP tools like <a href="http://curl.haxx.se/" class="external text" title="http://curl.haxx.se/" rel="nofollow">cURL</a>. However, for improved usability you might want to check out <a href="https://github.com/micha/resty" class="external text" title="https://github.com/micha/resty" rel="nofollow">resty</a>. This is a simple wrapper (for bash and zsh) for <a href="http://curl.haxx.se/" class="external text" title="http://curl.haxx.se/" rel="nofollow">cURL</a> that allows you to write ReST requests like shell commands:
</p>
<div dir="ltr" style="text-align: left;"><pre class="source-text"># initialize
&gt; resty http://localhost:8080
# get entry page
&gt; GET /smila
# define a job
&gt; POST /smila/jobmanager/jobs '{&quot;name&quot;:&quot;myJob&quot;,&quot;workflow&quot;:&quot;myWorkflow&quot;,&quot;parameters&quot;:{ ... }}'
# etc.</pre></div>
<p>See the <a href="https://github.com/micha/resty" class="external text" title="https://github.com/micha/resty" rel="nofollow">resty web site</a> for more information.
</p>
<a name="Posting_attachments_from_shell_scripts"></a><h4> <span class="mw-headline"> Posting attachments from shell scripts </span></h4>
<p>You can use <a href="http://curl.haxx.se/" class="external text" title="http://curl.haxx.se/" rel="nofollow">cURL</a> to send a record with some metadata and a binary file as an attachment: Use the <tt>-F</tt> option to send a multipart request to the specified URL. The part name "metadata" for the JSON part is arbitrary, the JSON part must be the first part in the request. The field name of the following attachment part (here "content") will be the name of the attachment in the created record. You can add multiple attachments with different names this way.
</p>
<div dir="ltr" style="text-align: left;"><pre class="source-text"># send a metadata record and a binary attachment to a etlImport job
&gt; curl -F &quot;metadata=@record.json&quot; -F &quot;content=@binary-file.pdf&quot; http://localhost:8080/smila/job/etlImport/record</pre></div>
<p>As <a href="https://github.com/micha/resty" class="external text" title="https://github.com/micha/resty" rel="nofollow">resty</a> is based on cURL and passes all options to the cURL call, the same <tt>-F</tt> options should work there, too.
</p>
<a name="Programmatical_Access"></a><h2> <span class="mw-headline"> Programmatical Access </span></h2>
<p>It's quite easy to use the SMILA API from external programs. In Java, basically everything you need is available in packages <tt>java.net</tt>. But it's easier using the SMILA data model classes and JSON utilities and a HTTP library like the Apache HttpClient. Below we provide some simple examples for doing requests with it.
</p><p>There are also free Java libraries available to make working with JSON ReST APIs easier, e.g. <a href="http://beders.github.com/Resty/Resty/Overview.html" class="external text" title="http://beders.github.com/Resty/Resty/Overview.html" rel="nofollow">Resty</a> (yes, same name, but another tool&nbsp;;-). However, we do not have experience with them.
</p>
<a name="SMILA_RestClient"></a><h3> <span class="mw-headline"> SMILA RestClient </span></h3>
<p>Since SMILA 1.1.0, we also provide a small library that encapsulates the JSON conversion and HTTP communication code for you. It's based on the SMILA data model classes and the Apache HttpCient 4.1, so it basically wraps up the code shown below. See <a href="HowTo/How_to_access_the_REST_API_with_the_RestClient.html" title="SMILA/Documentation/HowTo/How to access the REST API with the RestClient">SMILA/Documentation/HowTo/How_to_access_the_REST_API_with_the_RestClient</a> for details.
</p>
<a name="Apache_HttpClient_4.x"></a><h3> <span class="mw-headline"> Apache HttpClient 4.x </span></h3>
<p>Using <a href="http://hc.apache.org/httpcomponents-client-ga/index.html|Apache" class="external text" title="http://hc.apache.org/httpcomponents-client-ga/index.html|Apache" rel="nofollow">HttpClient 4.x</a> (version 4.1 is included in SMILA since 1.1.0) and <a href="http://commons.apache.org/io/" class="external text" title="http://commons.apache.org/io/" rel="nofollow">Apache Commons IO</a>, invoking a pipeline could be done like this:
</p>
<div dir="ltr" style="text-align: left;"><pre class="source-java"><span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">http</span>.<span class="me1">HttpResponse</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">http</span>.<span class="me1">HttpStatus</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">http</span>.<span class="me1">client</span>.<span class="me1">HttpClient</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">http</span>.<span class="me1">client</span>.<span class="me1">methods</span>.<span class="me1">HttpPost</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">http</span>.<span class="me1">entity</span>.<span class="me1">StringEntity</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">http</span>.<span class="me1">impl</span>.<span class="me1">client</span>.<span class="me1">DefaultHttpClient</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">commons</span>.<span class="me1">io</span>.<span class="me1">IOUtils</span>;
&nbsp;
HttpClient client = <span class="kw1">new</span> DefaultHttpClient<span class="br0">&#40;</span><span class="br0">&#41;</span>;
IpcAnyReader jsonReader = <span class="kw1">new</span> IpcAnyReader<span class="br0">&#40;</span><span class="br0">&#41;</span>;
IpcAnyWriter jsonWriter = <span class="kw1">new</span> IpcAnyWriter<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp;
AnyMap request = ...; <span class="co1">// create request</span>
<span class="kw3">String</span> jsonString = jsonWriter.<span class="me1">writeJsonObject</span><span class="br0">&#40;</span>request<span class="br0">&#41;</span>;
HttpPost method = <span class="kw1">new</span> HttpPost<span class="br0">&#40;</span><span class="st0">&quot;http://localhost:8080/smila/pipelines/MyPipeline/process&quot;</span><span class="br0">&#41;</span>;
method.<span class="me1">setEntity</span><span class="br0">&#40;</span><span class="kw1">new</span> StringEntityjsonString, <span class="st0">&quot;application/json&quot;</span>, <span class="st0">&quot;utf-8&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
<span class="kw1">try</span> <span class="br0">&#123;</span>
HttpResponse response = client.<span class="me1">execute</span><span class="br0">&#40;</span>method<span class="br0">&#41;</span>;
<span class="kw1">if</span> <span class="br0">&#40;</span>response.<span class="me1">getStatusLine</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getStatusCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> == HttpStatus.<span class="me1">SC_OK</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
<span class="kw3">InputStream</span> content = response.<span class="me1">getEntity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getContent</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="kw1">try</span> <span class="br0">&#123;</span>
AnyMap result = <span class="br0">&#40;</span>AnyMap<span class="br0">&#41;</span> jsonReader.<span class="me1">readJsonStream</span><span class="br0">&#40;</span>content<span class="br0">&#41;</span>;
... <span class="co1">// use result.</span>
<span class="br0">&#125;</span> <span class="kw1">finally</span> <span class="br0">&#123;</span>
IOUtils.<span class="me1">closeQuietly</span><span class="br0">&#40;</span>content<span class="br0">&#41;</span>;
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>response.<span class="me1">getEntity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>&nbsp;!= <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
EntityUtils.<span class="me1">consume</span><span class="br0">&#40;</span>response.<span class="me1">getEntity</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// be sure to read the response in error cases, too.</span>
... <span class="co1">// handle error.</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">catch</span> <span class="br0">&#40;</span><span class="kw3">Exception</span> ex<span class="br0">&#41;</span> <span class="br0">&#123;</span>
request.<span class="me1">abort</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="br0">&#125;</span></pre></div>
<a name="Apache_HttpClient_3.1"></a><h3> <span class="mw-headline"> Apache HttpClient 3.1 </span></h3>
<p>Using <a href="http://hc.apache.org/httpclient-legacy/index.html|Apache" class="external text" title="http://hc.apache.org/httpclient-legacy/index.html|Apache" rel="nofollow">HttpClient 3.1</a> (included in SMILA) and <a href="http://commons.apache.org/io/" class="external text" title="http://commons.apache.org/io/" rel="nofollow">Apache Commons IO</a>, invoking a pipeline could be done like this:
</p>
<div dir="ltr" style="text-align: left;"><pre class="source-java"><span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">commons</span>.<span class="me1">httpclient</span>.<span class="me1">HttpClient</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">commons</span>.<span class="me1">httpclient</span>.<span class="me1">HttpStatus</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">commons</span>.<span class="me1">httpclient</span>.<span class="me1">methods</span>.<span class="me1">PostMethod</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">commons</span>.<span class="me1">httpclient</span>.<span class="me1">methods</span>.<span class="me1">StringRequestEntity</span>;
<span class="kw1">import</span> org.<span class="me1">eclipse</span>.<span class="me1">smila</span>.<span class="me1">datamodel</span>.<span class="me1">ipc</span>.<span class="me1">IpcAnyReader</span>;
<span class="kw1">import</span> org.<span class="me1">eclipse</span>.<span class="me1">smila</span>.<span class="me1">datamodel</span>.<span class="me1">ipc</span>.<span class="me1">IpcAnyWriter</span>;
<span class="kw1">import</span> org.<span class="me1">eclipse</span>.<span class="me1">smila</span>.<span class="me1">datamodel</span>.<span class="me1">AnyMap</span>;
<span class="kw1">import</span> org.<span class="me1">apache</span>.<span class="me1">commons</span>.<span class="me1">io</span>.<span class="me1">IOUtils</span>;
&nbsp;
HttpClient client = <span class="kw1">new</span> HttpClient<span class="br0">&#40;</span><span class="br0">&#41;</span>;
IpcAnyReader jsonReader = <span class="kw1">new</span> IpcAnyReader<span class="br0">&#40;</span><span class="br0">&#41;</span>;
IpcAnyWriter jsonWriter = <span class="kw1">new</span> IpcAnyWriter<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp;
AnyMap request = ...; <span class="co1">// create request</span>
<span class="kw3">String</span> jsonString = jsonWriter.<span class="me1">writeJsonObject</span><span class="br0">&#40;</span>request<span class="br0">&#41;</span>;
PostMethod method = <span class="kw1">new</span> PostMethod<span class="br0">&#40;</span><span class="st0">&quot;http://localhost:8080/smila/pipelines/MyPipeline/process&quot;</span><span class="br0">&#41;</span>;
method.<span class="me1">setRequestEntity</span><span class="br0">&#40;</span><span class="kw1">new</span> StringRequestEntity<span class="br0">&#40;</span>jsonString, <span class="st0">&quot;application/json&quot;</span>, <span class="st0">&quot;utf-8&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
<span class="kw1">try</span> <span class="br0">&#123;</span>
client.<span class="me1">executeMethod</span><span class="br0">&#40;</span>postMethod<span class="br0">&#41;</span>;
<span class="kw1">if</span> <span class="br0">&#40;</span>method.<span class="me1">getStatusCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> == HttpStatus.<span class="me1">SC_OK</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
<span class="kw3">InputStream</span> content = postMethod.<span class="me1">getResponseBodyAsStream</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="kw1">try</span> <span class="br0">&#123;</span>
AnyMap result = <span class="br0">&#40;</span>AnyMap<span class="br0">&#41;</span> jsonReader.<span class="me1">readJsonStream</span><span class="br0">&#40;</span>content<span class="br0">&#41;</span>;
... <span class="co1">// use result.</span>
<span class="br0">&#125;</span> <span class="kw1">finally</span> <span class="br0">&#123;</span>
IOUtils.<span class="me1">closeQuietly</span><span class="br0">&#40;</span>content<span class="br0">&#41;</span>;
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
... <span class="co1">// handle error.</span>
<span class="br0">&#125;</span>
<span class="br0">&#125;</span> <span class="kw1">finally</span> <span class="br0">&#123;</span>
method.<span class="me1">releaseConnection</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="br0">&#125;</span></pre></div>
<!--
NewPP limit report
Preprocessor node count: 41/1000000
Post-expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
#ifexist count: 0/100
-->
<!-- Saved in parser cache with key wikidb:pcache:idhash:35475-0!1!0!!en!2!edit=0 and timestamp 20130416060934 -->
<div class="printfooter">
Retrieved from "<a href="Using_The_ReST_API.html">http://wiki.eclipse.org/SMILA/Documentation/Using_The_ReST_API</a>"</div>
<div id="catlinks"><p class='catlinks'><a href="http://wiki.eclipse.org/Special:Categories" title="Special:Categories">Category</a>: <span dir='ltr'><a href="http://wiki.eclipse.org/Category:SMILA" title="Category:SMILA">SMILA</a></span></p></div> <!-- end content -->
<div class="visualClear"></div>
</div>
</div>
</div>
<!-- Yoink of toolbox for phoenix moved up -->
</div>
</div>
<div id="clearFooter"/>
<div id="footer" >
<ul id="footernav">
<li class="first"><a href="http://www.eclipse.org/">Home</a></li>
<li><a href="http://www.eclipse.org/legal/privacy.php">Privacy Policy</a></li>
<li><a href="http://www.eclipse.org/legal/termsofuse.php">Terms of Use</a></li>
<li><a href="http://www.eclipse.org/legal/copyright.php">Copyright Agent</a></li>
<li><a href="http://www.eclipse.org/org/foundation/contact.php">Contact</a></li>
<li><a href="http://wiki.eclipse.org/Eclipsepedia:About" title="Eclipsepedia:About">About Eclipsepedia</a></li>
</ul>
<span id="copyright">Copyright &copy; 2013 The Eclipse Foundation. All Rights Reserved</span>
<p id="footercredit">This page was last modified 15:45, 2 March 2012 by <a href="http://wiki.eclipse.org/index.php?title=User:Juergen.schumacher.attensity.com&amp;action=edit" class="new" title="User:Juergen.schumacher.attensity.com">Juergen Schumacher</a>. Based on work by <a href="http://wiki.eclipse.org/index.php?title=User:Christian.dein.attensity.com&amp;action=edit" class="new" title="User:Christian.dein.attensity.com">Christian Dein</a> and <a href="http://wiki.eclipse.org/index.php?title=User:Nadine.auslaender.attensity.com&amp;action=edit" class="new" title="User:Nadine.auslaender.attensity.com"> </a>.</p>
<p id="footerviews">This page has been accessed 1,257 times.</p>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-910670-4");
pageTracker._trackPageview();
</script>
<!-- <div class="visualClear"></div> -->
<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>
</div>
<!-- Served in 0.085 secs. --></body></html>