summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/documentation-2x/sca-java-bindingrest.html
diff options
context:
space:
mode:
Diffstat (limited to 'site/trunk/site-publish/documentation-2x/sca-java-bindingrest.html')
-rw-r--r--site/trunk/site-publish/documentation-2x/sca-java-bindingrest.html515
1 files changed, 515 insertions, 0 deletions
diff --git a/site/trunk/site-publish/documentation-2x/sca-java-bindingrest.html b/site/trunk/site-publish/documentation-2x/sca-java-bindingrest.html
new file mode 100644
index 0000000000..5c7fa11f94
--- /dev/null
+++ b/site/trunk/site-publish/documentation-2x/sca-java-bindingrest.html
@@ -0,0 +1,515 @@
+
+
+
+
+
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<HTML>
+ <HEAD>
+ <META name="description" content="Apache Tuscany">
+ <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture, sca, service component architecture, das, sdo, csa, ruby, opensource">
+
+ <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css">
+ <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x/$images/favicon.ico">
+ <TITLE>SCA Java binding.rest : Apache Tuscany</TITLE>
+ <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
+
+ <STYLE>
+ .spacetree * ul {
+ padding-left:0px;
+ margin-left: 0px;
+ }
+ .spacetree * li {
+ margin-left: 5px;
+ padding-left:5px;
+ }
+ </STYLE>
+
+ <BODY onload="init()">
+ <!-- topNav -->
+ <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
+ <TR class="topBar">
+ <TD align="left" valign="middle" class="topBarDiv" align="left" nowrap="">
+ <A href="https://cwiki.apache.org/geronimo"> Home</A> &gt;&nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="sca-java-extensions-guide.html" title="SCA Java Extensions Guide">SCA Java Extensions Guide</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java binding.rest">SCA Java binding.rest</A>
+ </TD>
+ <TD align="right" valign="middle" nowrap="">
+ <FORM name="search" action="http://www.google.com/search" method="get">
+ <INPUT type="hidden" name="ie" value="UTF-8">
+ <INPUT type="hidden" name="oe" value="UTF-8">
+ <INPUT type="hidden" name="domains" value="">
+ <INPUT type="hidden" name="sitesearch" value="">
+ <INPUT type="text" name="q" maxlength="255" value="">
+ <INPUT type="submit" name="btnG" value="Google Search">
+ </FORM>
+ </TD>
+ </TR>
+ </TABLE>
+
+
+ <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
+ <TR class="topBar">
+ <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
+ &nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="sca-java-extensions-guide.html" title="SCA Java Extensions Guide">SCA Java Extensions Guide</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java binding.rest">SCA Java binding.rest</A>
+ </TD>
+
+ <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
+ <A href="http://tuscany.apache.org/">Tuscany Home</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>&nbsp;&nbsp;
+ </TD>
+ </TR>
+ </TABLE>
+
+ <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
+ <TR>
+ <TD valign="top" align="left" width="22%" bgcolor="#F9F9F9" class="noprint">
+ <DIV class="tabletitle">Table of Contents</DIV>
+ <DIV class="spacetree">
+
+
+ </DIV>
+ </TD>
+ <TD align="left" valign="top" width="78%">
+ <!-- pageContent -->
+ <DIV id="PageContent">
+ <DIV class="pageheader" style="padding: 6px 0px 0px 0px;">
+ <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
+ <!--img src="http://geronimo.apache.org/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
+ <DIV style="margin: 0px 10px 0px 10px" class="smalltext">Apache Tuscany Docs 2.x</DIV>
+ <DIV style="margin: 0px 10px 8px 10px" class="pagetitle">SCA Java binding.rest</DIV>
+
+ <DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
+<!-- -->
+ <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=20644360">
+ <IMG src="http://geronimo.apache.org/images/icons/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=20644360">Edit Page</A>
+ &nbsp;
+ <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">
+ <IMG src="http://geronimo.apache.org/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Browse Space"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">Browse Space</A>
+ &nbsp;
+ <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644360">
+ <IMG src="http://geronimo.apache.org/images/icons/add_page_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add Page"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644360">Add Page</A>
+ &nbsp;
+ <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644360">
+ <IMG src="http://geronimo.apache.org/images/icons/add_blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add News"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644360">Add News</A>
+<!-- -->
+ </DIV>
+ </DIV>
+
+ <DIV class="pagecontent">
+ <DIV class="wiki-content">
+ <H3><A name="SCAJavabinding.rest-%3Cbinding.rest%3EIntroduction"></A>&lt;binding.rest&gt; Introduction</H3>
+
+<P>The Tuscany Java SCA runtime supports Representational State Transfer (REST) services invocations via the &lt;binding.rest&gt; extension. Tuscany REST binding leverage JAX-RS Standards based annotations to map business operations to HTTP operations such as POST, GET, PUT and DELETE and utilizes Tuscany Databindings to provide support for different wire formats such as JSON, XML, Binary, etc shielding the application developer from contaminating his business logic with code to handle payload production/transformation details.</P>
+
+<H3><A name="SCAJavabinding.rest-UsingtheTuscanyRESTbinding"></A>Using the Tuscany REST binding</H3>
+
+<P>The primary use of the REST binding is to provide business services over HTTP in a distributed fashion. The simplest way to use the REST binding is to declare a business service that can be shared over the web and provide an HTTP address where one can access the service. This service is declared in an SCA composite file.</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+ &lt;component name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;implementation.java class=<SPAN class="code-quote">&quot;services.store.FruitsCatalogImpl&quot;</SPAN>/&gt;
+ &lt;service name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;tuscany:binding.<SPAN class="code-keyword">rest</SPAN> uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8085/Catalog&quot;</SPAN>&gt;
+</SPAN> &lt;tuscany:wireFormat.json /&gt;
+ &lt;tuscany:operationSelector.jaxrs /&gt;
+ &lt;/tuscany:binding.<SPAN class="code-keyword">rest</SPAN>&gt;
+ &lt;/service&gt;
+ &lt;/component&gt;
+</PRE>
+</DIV></DIV>
+
+
+<P>Another way of implementing a REST service is to use a collection interface that matches the actions of the HTTP protocol. In this case, the methods must be named post, get, put, and delete. Tuscany ensures that the proper method is invoked via the request and response protocol of HTTP:</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+<SPAN class="code-keyword">public</SPAN> class TestGetImpl {
+
+ <SPAN class="code-keyword">public</SPAN> InputStream get(<SPAN class="code-object">String</SPAN> id) {
+ <SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">new</SPAN> ByteArrayInputStream((<SPAN class="code-quote">&quot;&lt;html&gt;&lt;body&gt;&lt;p&gt;This is the service GET method, item=&quot;</SPAN> + id + <SPAN class="code-quote">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</SPAN>).getBytes());
+
+ }
+}
+</PRE>
+</DIV></DIV>
+
+<P>So using the common verbs of HTTP and Java object serialization, one can implement services and run them anywhere the HTTP protocol is implemented. The service developer or implementer simply creates methods for post, get, put, and delete, and a business collection such as a shopping cart, telephone directory, insurance form, or blog sites can be created. See the Tuscany module binding-rest-runtime for complete examples.</P>
+
+
+<H3><A name="SCAJavabinding.rest-MappingbusinessinterfacestoHTTPOperationsusingJAXRSStandardAnnotations"></A>Mapping business interfaces to HTTP Operations using JAX-RS Standard Annotations</H3>
+
+<P>JAX-RS offers standards based annotations that allow properly configuration of the REST service endpoint and mappings of specific HTTP operations (e.g. get, put, post, delete) to java operations. The following subset of JAX-RS annotations are currently supported :</P>
+
+<H4><A name="SCAJavabinding.rest-URIMappings"></A>URI Mappings</H4>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+@Path
+@Path(<SPAN class="code-quote">&quot;{id}&quot;</SPAN>)
+@PathParam(<SPAN class="code-quote">&quot;id&quot;</SPAN>)
+</PRE>
+</DIV></DIV>
+
+<H4><A name="SCAJavabinding.rest-OperationMappings"></A>Operation Mappings</H4>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+@GET
+@PUT
+@POST
+@DELETE
+</PRE>
+</DIV></DIV>
+
+<H4><A name="SCAJavabinding.rest-EnablingJAXRSannotationprocessing"></A>Enabling JAX-RS annotation processing</H4>
+
+<P>In order to enable JAX-RS annotation processing, a component need to be configured to use JAX-RS Operation Selector.</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+ &lt;component name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;implementation.java class=<SPAN class="code-quote">&quot;services.store.FruitsCatalogImpl&quot;</SPAN>/&gt;
+ &lt;property name=<SPAN class="code-quote">&quot;currencyCode&quot;</SPAN>&gt;USD&lt;/property&gt;
+ &lt;service name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;tuscany:binding.<SPAN class="code-keyword">rest</SPAN> uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8085/Catalog&quot;</SPAN>&gt;
+</SPAN> &lt;tuscany:wireFormat.json /&gt;
+ &lt;tuscany:operationSelector.jaxrs /&gt;
+ &lt;/tuscany:binding.<SPAN class="code-keyword">rest</SPAN>&gt;
+ &lt;/service&gt;
+ &lt;reference name=<SPAN class="code-quote">&quot;currencyConverter&quot;</SPAN> target=<SPAN class="code-quote">&quot;CurrencyConverter&quot;</SPAN>/&gt;
+ &lt;/component&gt;
+</PRE>
+</DIV></DIV>
+
+<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>Integration with a existent JAX-RS engine might help on processing the full set of JAX-RS annotations. I have started looking into leveraging Wink resourceProcessor or related code to help on this layer.</TD></TR></TABLE></DIV>
+
+<H3><A name="SCAJavabinding.rest-MappingRPCstylecallsoverHTTPGET"></A>Mapping RPC style calls over HTTP GET</H3>
+
+<P>In some cases, there isn't a simple mapping of a business operation as resources, but there is still a desire to take advantage of HTTP caching and other benefits that HTTP GET type of operations provide. In order to accomplish this, binding.rest has built in functionality that allows you to map RPC style calls to HTTP GET operations.</P>
+
+
+
+<H4><A name="SCAJavabinding.rest-ClientInvocation"></A>Client Invocation</H4>
+
+<P>The URL schema follows a simple pattern :</P>
+
+<UL class="alternate" type="square">
+ <LI>&lt;base service URI&gt; ?<B>method=</B>&lt;operation name&gt;&amp;<B>parm1=</B>&lt;value&gt;&amp;<B>parm2=</B>&lt;value&gt;</LI>
+</UL>
+
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+http:<SPAN class="code-comment">//localhost:8085/EchoService?method=echo&amp;msg=Hello RPC</SPAN>
+</PRE>
+</DIV></DIV>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+http:<SPAN class="code-comment">//localhost:8085/EchoService?method=echoArrayString&amp;msgArray=Hello RPC1&amp;msgArray=Hello RPC2&quot;</SPAN>
+</PRE>
+</DIV></DIV>
+
+<H4><A name="SCAJavabinding.rest-MappingQueryStringstoBusinessOperationparameters"></A>Mapping QueryStrings to Business Operation parameters</H4>
+
+<P>Standard JAX-RS annotation @QueryParam is used to map parameters sent over HTTP GET invocations using query string to business operation parameter</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+@Remotable
+<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> Echo {
+
+ <SPAN class="code-object">String</SPAN> echo(@QueryParam(<SPAN class="code-quote">&quot;msg&quot;</SPAN>) <SPAN class="code-object">String</SPAN> msg);
+
+ <SPAN class="code-object">int</SPAN> echoInt(<SPAN class="code-object">int</SPAN> param);
+
+ <SPAN class="code-object">boolean</SPAN> echoBoolean(<SPAN class="code-object">boolean</SPAN> param);
+
+ <SPAN class="code-object">String</SPAN> [] echoArrayString(@QueryParam(<SPAN class="code-quote">&quot;msgArray&quot;</SPAN>) <SPAN class="code-object">String</SPAN>[] stringArray);
+
+ <SPAN class="code-object">int</SPAN> [] echoArrayInt(<SPAN class="code-object">int</SPAN>[] intArray);
+
+}
+</PRE>
+</DIV></DIV>
+
+<H4><A name="SCAJavabinding.rest-EnablingRPCtoHTTPGETmapping"></A>Enabling RPC to HTTP GET mapping</H4>
+
+<P>In order to enable automatically mapping, a component need to be configured to use RPC Operation Selector.</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+ &lt;component name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;implementation.java class=<SPAN class="code-quote">&quot;services.store.FruitsCatalogImpl&quot;</SPAN>/&gt;
+ &lt;property name=<SPAN class="code-quote">&quot;currencyCode&quot;</SPAN>&gt;USD&lt;/property&gt;
+ &lt;service name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;tuscany:binding.<SPAN class="code-keyword">rest</SPAN> uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8085/Catalog&quot;</SPAN>&gt;
+</SPAN> &lt;tuscany:wireFormat.json /&gt;
+ &lt;tuscany:response&gt;
+ &lt;tuscany:operationSelector.rpc /&gt;
+ &lt;/tuscany:response&gt;
+ &lt;/tuscany:binding.<SPAN class="code-keyword">rest</SPAN>&gt;
+ &lt;/service&gt;
+ &lt;reference name=<SPAN class="code-quote">&quot;currencyConverter&quot;</SPAN> target=<SPAN class="code-quote">&quot;CurrencyConverter&quot;</SPAN>/&gt;
+ &lt;/component&gt;
+</PRE>
+</DIV></DIV>
+
+<H3><A name="SCAJavabinding.rest-WireFormats"></A>Wire Formats</H3>
+
+<P>This binding will support two styles of wire formats and will be used to control what type of payload will be generated by the service:</P>
+
+<UL class="alternate" type="square">
+ <LI>hardWired : where you hard code the wire format expectations in the composite when configuring the binding. In the example below, service will be using JSON payload.</LI>
+</UL>
+
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+&lt;binding...&gt;
+ &lt;wireFormat.json&gt;
+&lt;/binding...&gt;
+</PRE>
+</DIV></DIV>
+
+<UL class="alternate" type="square">
+ <LI>dynamic : based on Content-Type header for request and Accept header for response. In the case below, the request content will be parsed based on the Content-Type request header and the response payload will be based on the request Accept header.</LI>
+</UL>
+
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+&lt;binding...&gt;
+ &lt;wireFormat.dynamic&gt;
+&lt;/binding...&gt;
+</PRE>
+</DIV></DIV>
+
+<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>In progress</TD></TR></TABLE></DIV>
+
+<H3><A name="SCAJavabinding.rest-CachecontrolusingETags%2CLastModifiedandotherHTTPHeaders"></A>Cache control using ETags, Last-Modified and other HTTP Headers</H3>
+
+<P>The HTTP specification provides a set of methods for HTTP clients and servers to interact. These methods form the foundation of the World Wide Web. Tuscany implements many of these methods a binding interface to a collection. The main methods are:</P>
+
+<UL>
+ <LI>GET - retrieves an item from a collection</LI>
+ <LI>POST - creates or adds an item to a collection</LI>
+ <LI>PUT - updates or replaces an item in a collection</LI>
+ <LI>DELETE - removes an item in a a collection</LI>
+</UL>
+
+
+<P>The HTTP specification (HTTP 1.1 Chapter 13 - Caching) also provides a mechanism by which these methods may be executed conditionally. To perform conditional methods, an HTTP client puts 3 items in the HTTP request header:</P>
+
+<UL>
+ <LI>ETag - entity tag, a unique identifier to an item in a collection. Normally created and returned by the server when creating (POST) a new item.</LI>
+ <LI>LastModified - an updated field. Normally a string containing a date and time of the last modification of the item.</LI>
+ <LI>Predicate - a logical test (e.g. IfModified, IfUnmodified) to use with the ETag and LastModified to determine whether to act.</LI>
+</UL>
+
+
+<P>The complete list of predicates is given in the HTTP specification.</P>
+
+<P>The most common use of conditional methods is to prevent two requests to the server instead of one conditional request. For example, a common scenario is to check if an item has been modified, if not changed update it with a new version, if changed do not update it. With a conditional PUT method (using the IfUnmodifed predicate and a LastModified date), this can be done in one action. Another common use is to prevent multiple GETs of an item to ensure we have a valid copy. Rather than doing a second request of a large item, one can do a conditional GET request (using an IfModified predicate and a LastModified date), and avoid the second request if our object is still valid. The server responds with either a normal response body, or status code 304 (Not Modified), or status code 412 (precondition failed).</P>
+
+<P>Default cache control is done by using generated ETags based on response content checksum. To avoid data to be overwriten during concurrent updates, include an HTTP If-Match header that contains the original content ETag value. If you want to force an update regardless of whether someone else has updated it since you retrieved it, then use If-Match: * and don't include the ETag.</P>
+
+<H4><A name="SCAJavabinding.rest-Declarativecachecontrol"></A>Declarative cache control</H4>
+<P>In order to allow for better flexibility, and re-usability of the components exposed as REST services, there is an option to declare cache controls when configuring the REST Binding as show the example below :</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+ &lt;component name=<SPAN class="code-quote">&quot;CustomerService&quot;</SPAN>&gt;
+ &lt;implementation.java class=<SPAN class="code-quote">&quot;services.customer.CustomerServiceImpl&quot;</SPAN>/&gt;
+ &lt;service name=<SPAN class="code-quote">&quot;CustomerService&quot;</SPAN>&gt;
+ &lt;tuscany:binding.<SPAN class="code-keyword">rest</SPAN> uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8085/Customer&quot;</SPAN>&gt;
+</SPAN> &lt;tuscany:wireFormat.xml /&gt;
+ &lt;tuscany:operationSelector.jaxrs /&gt;
+ &lt;tuscany:http-headers&gt;
+ &lt;tuscany:header name=<SPAN class="code-quote">&quot;Cache-Control&quot;</SPAN> value=<SPAN class="code-quote">&quot;no-cache&quot;</SPAN>/&gt;
+ &lt;tuscany:header name=<SPAN class="code-quote">&quot;Expires&quot;</SPAN> value=<SPAN class="code-quote">&quot;-1&quot;</SPAN>/&gt;
+ &lt;tuscany:header name=<SPAN class="code-quote">&quot;X-Tuscany&quot;</SPAN> value=<SPAN class="code-quote">&quot;tuscany&quot;</SPAN>/&gt;
+ &lt;/tuscany:http-headers&gt;
+ &lt;/tuscany:binding.<SPAN class="code-keyword">rest</SPAN>&gt;
+ &lt;/service&gt;
+ &lt;/component&gt;
+</PRE>
+</DIV></DIV>
+
+<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>This could be enhanced to enable more complex injection of fields to cache control headers.</TD></TR></TABLE></DIV>
+
+
+
+<H3><A name="SCAJavabinding.rest-StorescenariosgoesRESTCatalogServicesusingbinding.rest"></A>Store scenarios goes REST - Catalog Services using binding.rest</H3>
+
+<P>Below is our Store Catalog exposed as REST services utilizing the new binding.rest.</P>
+
+<P>Let's start by looking on how the component gets defined and configured in the composite file, particularly the following details :</P>
+
+<UL class="alternate" type="square">
+ <LI>binding.rest uri defines the Catalog service endpoint</LI>
+ <LI>wireFormat.json configure the service to use JSON as the payload</LI>
+ <LI>operationSelector.jaxrs configure the binding to use JAX-RS annotations to map the HTTP operations to business operations</LI>
+</UL>
+
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+&lt;composite xmlns=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//docs.oasis-open.org/ns/opencsa/sca/200912&quot;</SPAN>
+</SPAN> xmlns:tuscany=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//tuscany.apache.org/xmlns/sca/1.1&quot;</SPAN>
+</SPAN> targetNamespace=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//store&quot;</SPAN>
+</SPAN> name=<SPAN class="code-quote">&quot;store&quot;</SPAN>&gt;
+
+ &lt;component name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;implementation.java class=<SPAN class="code-quote">&quot;services.store.FruitsCatalogImpl&quot;</SPAN>/&gt;
+ &lt;property name=<SPAN class="code-quote">&quot;currencyCode&quot;</SPAN>&gt;USD&lt;/property&gt;
+ &lt;service name=<SPAN class="code-quote">&quot;Catalog&quot;</SPAN>&gt;
+ &lt;tuscany:binding.<SPAN class="code-keyword">rest</SPAN> uri=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8085/Catalog&quot;</SPAN>&gt;
+</SPAN> &lt;tuscany:wireFormat.json /&gt;
+ &lt;tuscany:operationSelector.jaxrs /&gt;
+ &lt;/tuscany:binding.<SPAN class="code-keyword">rest</SPAN>&gt;
+ &lt;/service&gt;
+ &lt;reference name=<SPAN class="code-quote">&quot;currencyConverter&quot;</SPAN> target=<SPAN class="code-quote">&quot;CurrencyConverter&quot;</SPAN>/&gt;
+ &lt;/component&gt;
+
+ &lt;component name=<SPAN class="code-quote">&quot;CurrencyConverter&quot;</SPAN>&gt;
+ &lt;implementation.java class=<SPAN class="code-quote">&quot;services.store.CurrencyConverterImpl&quot;</SPAN>/&gt;
+ &lt;/component&gt;
+
+&lt;/composite&gt;
+</PRE>
+</DIV></DIV>
+
+
+<P>Below is the Catalog Interface utilizing JAX-RS standard annotations to map HTTP operations to business operations.</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+<SPAN class="code-keyword">package</SPAN> services.store;
+
+<SPAN class="code-keyword">import</SPAN> javax.ws.rs.DELETE;
+<SPAN class="code-keyword">import</SPAN> javax.ws.rs.GET;
+<SPAN class="code-keyword">import</SPAN> javax.ws.rs.POST;
+<SPAN class="code-keyword">import</SPAN> javax.ws.rs.PUT;
+<SPAN class="code-keyword">import</SPAN> javax.ws.rs.Path;
+<SPAN class="code-keyword">import</SPAN> javax.ws.rs.PathParam;
+
+<SPAN class="code-keyword">import</SPAN> org.oasisopen.sca.annotation.Remotable;
+
+
+@Remotable
+<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> Catalog {
+
+ @GET
+ Item[] getAll();
+
+ @GET
+ @Path(<SPAN class="code-quote">&quot;{id}&quot;</SPAN>)
+ Item getItemById(@PathParam(<SPAN class="code-quote">&quot;id&quot;</SPAN>) <SPAN class="code-object">String</SPAN> itemId);
+
+ @POST
+ void addItem(Item item);
+
+ @PUT
+ void updateItem(Item item);
+
+ @DELETE
+ @Path(<SPAN class="code-quote">&quot;{id}&quot;</SPAN>)
+ void deleteItem(@PathParam(<SPAN class="code-quote">&quot;id&quot;</SPAN>) <SPAN class="code-object">String</SPAN> itemId);
+}
+</PRE>
+</DIV></DIV>
+
+<P>Below is the Fuit catalog implementation</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+@Scope(<SPAN class="code-quote">&quot;COMPOSITE&quot;</SPAN>)
+<SPAN class="code-keyword">public</SPAN> class FruitsCatalogImpl <SPAN class="code-keyword">implements</SPAN> Catalog {
+
+ @Property
+ <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> currencyCode = <SPAN class="code-quote">&quot;USD&quot;</SPAN>;
+
+ @Reference
+ <SPAN class="code-keyword">public</SPAN> CurrencyConverter currencyConverter;
+
+ <SPAN class="code-keyword">private</SPAN> Map&lt;<SPAN class="code-object">String</SPAN>, Item&gt; catalog = <SPAN class="code-keyword">new</SPAN> HashMap&lt;<SPAN class="code-object">String</SPAN>, Item&gt;();
+
+ @Init
+ <SPAN class="code-keyword">public</SPAN> void init() {
+ <SPAN class="code-object">String</SPAN> currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+ catalog.put(<SPAN class="code-quote">&quot;Apple&quot;</SPAN>, <SPAN class="code-keyword">new</SPAN> Item(<SPAN class="code-quote">&quot;Apple&quot;</SPAN>, currencySymbol + currencyConverter.getConversion(<SPAN class="code-quote">&quot;USD&quot;</SPAN>, currencyCode, 2.99)));
+ catalog.put(<SPAN class="code-quote">&quot;Orange&quot;</SPAN>, <SPAN class="code-keyword">new</SPAN> Item(<SPAN class="code-quote">&quot;Orange&quot;</SPAN>, currencySymbol + currencyConverter.getConversion(<SPAN class="code-quote">&quot;USD&quot;</SPAN>, currencyCode, 3.55)));
+ catalog.put(<SPAN class="code-quote">&quot;Pear&quot;</SPAN>, <SPAN class="code-keyword">new</SPAN> Item(<SPAN class="code-quote">&quot;Pear&quot;</SPAN>, currencySymbol + currencyConverter.getConversion(<SPAN class="code-quote">&quot;USD&quot;</SPAN>, currencyCode, 1.55)));
+ }
+
+ <SPAN class="code-keyword">public</SPAN> Item[] getAll() {
+ Item[] catalogArray = <SPAN class="code-keyword">new</SPAN> Item[catalog.size()];
+ catalog.values().toArray(catalogArray);
+ <SPAN class="code-keyword">return</SPAN> catalogArray;
+ }
+
+ <SPAN class="code-keyword">public</SPAN> Item getItemById(<SPAN class="code-object">String</SPAN> itemId) {
+ <SPAN class="code-keyword">return</SPAN> catalog.get(itemId);
+ }
+
+ <SPAN class="code-keyword">public</SPAN> void addItem(Item item) {
+ catalog.put(item.getName(),item);
+ }
+
+ <SPAN class="code-keyword">public</SPAN> void updateItem(Item item) {
+ <SPAN class="code-keyword">if</SPAN>(catalog.get(item.getName()) != <SPAN class="code-keyword">null</SPAN>) {
+ catalog.put(item.getName(), item);
+ }
+ }
+
+ <SPAN class="code-keyword">public</SPAN> void deleteItem(<SPAN class="code-object">String</SPAN> itemId) {
+ <SPAN class="code-keyword">if</SPAN>(catalog.get(itemId) != <SPAN class="code-keyword">null</SPAN>) {
+ catalog.remove(itemId);
+ }
+ }
+}
+</PRE>
+</DIV></DIV>
+
+ </DIV>
+
+ </DIV>
+ </DIV>
+ </TD>
+ </TR>
+ </TABLE>
+
+ <!-- footer -->
+ <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
+ <TR>
+ <TD align="left" valign="middle" class="footer">
+ &nbsp;&nbsp;
+ <IMG src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious">
+ <A href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'delicious','toolbar=no,width=550,height=550'); return false;">Bookmark this on Delicious</A>
+ &nbsp;&nbsp;
+ <IMG src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" height="16" alt="Digg!">
+ <A href="" onclick="window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&topic=programming');">Digg this</A>
+ <!-- Slicker, but no text
+ <script type="text/javascript">
+ digg_skin = 'icon';
+ digg_window = 'new';
+ digg_title = 'Apache Geronimo v2.2 Documentation : SCA Java binding.rest';
+ digg_topic = 'programming';
+ </script>
+ <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
+ -->
+ &nbsp;&nbsp;
+ </TD>
+ <TD align="right" valign="middle" class="footer">
+ <A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A>&nbsp;&nbsp;-&nbsp;&nbsp;
+ Copyright &copy; 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A>&nbsp;&nbsp;
+ </TD>
+ </TR>
+ </TABLE>
+
+ </BODY>
+</HTML> \ No newline at end of file