1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
<!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.atom : 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> > <A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A> > <A href="index.html" title="Index">Index</A> > <A href="sca-java-extensions-guide.html" title="SCA Java Extensions Guide">SCA Java Extensions Guide</A> > <A href="" title="SCA Java binding.atom">SCA Java binding.atom</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%">
<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A> > <A href="index.html" title="Index">Index</A> > <A href="sca-java-extensions-guide.html" title="SCA Java Extensions Guide">SCA Java Extensions Guide</A> > <A href="" title="SCA Java binding.atom">SCA Java binding.atom</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>
</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.atom</DIV>
<DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
<!-- -->
<A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=5964961">
<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=5964961">Edit Page</A>
<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>
<A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=5964961">
<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=5964961">Add Page</A>
<A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=5964961">
<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=5964961">Add News</A>
<!-- -->
</DIV>
</DIV>
<DIV class="pagecontent">
<DIV class="wiki-content">
<H3><A name="SCAJavabinding.atom-%3Cbinding.atom%3EIntroduction"></A><binding.atom> Introduction</H3>
<P>The Tuscany Java SCA runtime supports Atom using the <binding.atom> extension. Tuscany can communicate with services that provide or consume items described in the Atom Syndication Format and Atom Publishing Protocol. The Atom protcol is an additional conceptual layer that operates on top of the Hyper Text Transfer Protocol, so it is useful to understand that underlying protocol as well. Reference materials on these specifications is available here.</P>
<UL>
<LI><A href="http://tools.ietf.org/html/rfc2616" class="external-link" rel="nofollow">Hyper Text Transfer Protocol</A>.</LI>
<LI><A href="http://tools.ietf.org/html/rfc4287" class="external-link" rel="nofollow">Atom Syndication Format</A>.</LI>
<LI><A href="http://tools.ietf.org/html/rfc5023" class="external-link" rel="nofollow">Atom Publishing Protocol</A>.</LI>
</UL>
<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> Some of the function described here is included in the Tuscany 1.3.2 and 1.4 releases. The complete timeline of available and future plans is given in the <A href="http://tuscany.apache.org/sca-java-roadmap.html" class="external-link" rel="nofollow">Tuscany Web 2.0 Roadmap</A>.</P>
<H3><A name="SCAJavabinding.atom-UsingtheTuscanyAtombinding"></A>Using the Tuscany Atom binding</H3>
<P>The primary use of the Atom binding is to provide support for collections that can be shared in a distributed fashion. Examples of shared collections includes shopping carts, telephone directories, insurance forms, and blog sites. These collections of items can be added, retrieved, updated, and deleted using the 4 basic actions of the HTTP protocol:</P>
<UL>
<LI>POST (create or add)</LI>
<LI>GET (retreive or query)</LI>
<LI>PUT (update)</LI>
<LI>DELETE (destroy or remove</LI>
</UL>
<P>The simplest way to use the Atom binding is to declare a collection as a service and provide an HTTP address where one can access the service. This service is declared in an SCA composite file which describes the SCA domain.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<service name=<SPAN class="code-quote">"customer"</SPAN> promote=<SPAN class="code-quote">"CustomerCollection"</SPAN>>
<tuscany:binding.atom uri = <SPAN class="code-quote">"http:<SPAN class="code-comment">//localhost:8084/customer"</SPAN>/>
</SPAN> </service>
</PRE>
</DIV></DIV>
<P>The service can be implemented in Java or any of the the Tuscany implementation types. For example, here is a way to create an implmentation for the above CustomerCollection service in the Java type.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<component name=<SPAN class="code-quote">"CustomerCollection"</SPAN>>
<implementation.java class=<SPAN class="code-quote">"org.apache.tuscany.sca.binding.atom.CustomerCollectionImpl"</SPAN>/>
</component>
</PRE>
</DIV></DIV>
<P>A collection that uses the Atom binding usually implements the Collection interface given in the package org.apache.tuscany.sca.binding.atom.collection. This interface declares the basic access methods mentioned above (post, get, put, and delete), and the data types on the methods are expressed as Atom type objects Feed and Entry. In other words, one can view the collection as an Atom Feed, and manipulate items in the Feed as Atom Entries. This shows the basic methods of the Atom Collection intergface in Tuscany:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> Collection {
Entry post(Entry entry);
Entry get(<SPAN class="code-object">String</SPAN> id) <SPAN class="code-keyword">throws</SPAN> NotFoundException;
void put(<SPAN class="code-object">String</SPAN> id, Entry entry) <SPAN class="code-keyword">throws</SPAN> NotFoundException;
void delete(<SPAN class="code-object">String</SPAN> id) <SPAN class="code-keyword">throws</SPAN> NotFoundException;
Feed getFeed();
Feed query(<SPAN class="code-object">String</SPAN> queryString);
}
</PRE>
</DIV></DIV>
<P>It is up to the developer or implementer of the shopping cart, telephone directory, or blog site to provide the code that implements the Collection interface. The developer or implementor also provides the code that translates from the business objects (shopping cart items, directory entries, insurance forms, blog articles) to the Atom model objects Feed and Entry.</P>
<P>One of the features of using this binding is that your business objects (shopping cart items, directory entries, insurance forms, and blog articles) can now be easily published and shared by the many Atom supporting tools such as feed readers, web browsers, and syndication aggregation. In other words, people can access your collection most anywhere on any device.</P>
<H3><A name="SCAJavabinding.atom-Example"></A>Example</H3>
<P>Continuing with the CustomerCollection example shown above, let's see how one of the common access methods. In this case, let's look at the post method and how one would add a new item to the collection. When you declared your Atom binding in your SCA composite, you also provided a uri for your collection. Using a web browser or other device, a user performs an HTTP put request to this uri, with the body of the put containing the data. Tuscany SCA performs the task of invoking the correct service and finding the Java implementation for your collection and calling the correct method. </P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> Entry post(Entry entry) {
<SPAN class="code-comment">// 1. Validate entry fields
</SPAN> <SPAN class="code-keyword">if</SPAN> (entry.getTitle() != <SPAN class="code-keyword">null</SPAN> ) {
entryID = <SPAN class="code-quote">"tag:"</SPAN> + site <SPAN class="code-quote">","</SPAN> + todaysDate + <SPAN class="code-quote">":"</SPAN> + title;
entry.setID( entryID );
}
<SPAN class="code-comment">// 2. Provide any additional data.
</SPAN> entry.setUpdated( <SPAN class="code-keyword">new</SPAN> Date() );
<SPAN class="code-comment">// 3. Store data in local collection or data base.
</SPAN> entries.put(id, entry);
<SPAN class="code-comment">// 4. Return entry to poster.
</SPAN> <SPAN class="code-keyword">return</SPAN> entry;
}
</PRE>
</DIV></DIV>
<P>Much of the code consists of converting from a Feed or Entry to a business data model and storing to a collection.</P>
<P>Tuscany uses the Apache Abdera project to provide a model for Atom data. Please see <A href="http://incubator.apache.org/abdera/" class="external-link" rel="nofollow">Apache Abdera</A> for the Java method to access Atom Feeds and Entries, and how to easily convert these Java objects to and from XML.</P>
<H3><A name="SCAJavabinding.atom-OtherFeaturesoftheTuscanyAtomBinding"></A>Other Features of the Tuscany Atom Binding</H3>
<P>More advanced features of the Tuscany Atom binding are described below.</P>
<H4><A name="SCAJavabinding.atom-DataCachingusingETags%2CLastModified%2CandotherHeaderCommands"></A>Data Caching using ETags, Last-Modified, and other Header Commands</H4>
<P>Atom feeds and entries can often be very large pieces of data. Since Tuscany uses the Atom data binding as one of its supported bindings, there is the potential that many requests for data may have large pieces of data associated with a request.</P>
<P>Hyper Text Transfer Protocol (HTTP), the basis of the web, has support to help limit or cache the amount of data shared between a client and server by adding tags to a resource reques. These header tags are the ETag and the Last-Modified tags. When used with a predicate tag such as If-Match, If-Not-Match, If-Modified-Since, If-Unmodified-Since, etc., the client and the server can avoid shipping large pieces of data when updated data is not needed. </P>
<P>The following entry scenarios show how Tuscany supports this form of caching throught ETags, Last-Modified, and other Header Commands.</P>
<UL>
<LI>Posting new entry data to a feed<BR>
(Show entry data post request, item does not exist on server, server response code 200, return entry data body)</LI>
<LI>Updating existing entry data in a feed<BR>
(Show data update put, If-Match precondition, item is newer and matching, matching return code 412)</LI>
<LI>Requesting existing entry data<BR>
(Show get via ETag, If-None-Match precondition, modified entry data item, matching entry body returned) </LI>
<LI>Requesting stale entry data<BR>
(Show get via ETAG, If-None-Match precondition, unmodified entry data item, not modified return code 304)</LI>
<LI>Requesting up-to-date entry data<BR>
(Show request via last-modified date, entry data is unmodified, Not modified return code 304)</LI>
<LI>Requesting out-of-date entry data<BR>
(Show request via last-modified date, entry data is modified, updated data is returned)</LI>
</UL>
<P>Tuscany provides a test case ProviderEntryEntityTagsTest.java in module binding.atom.abdera that validates these Entry caching scenarios via JTest. Additionally, the following Feed scenarios are provided in the test case ProviderFeedEntityTagsTest.java.</P>
<UL>
<LI>Test feed basics<BR>
(Request Atom feed. Check that feed is non-null, has Id, title, and updated values. Check for Etag and Last-Modified headers)</LI>
<LI>Test Unmodified If-Match predicate<BR>
(Request feed based on existing ETag. Use If-Match predicate in request header. Expect status 200 and feed body.)</LI>
<LI>Test Unmodified If-None-Match predicate<BR>
(Request feed based on existing ETag. Use If-None-Match predicate in request header. Expect status 304, item not modified, no feed body.)</LI>
<LI>Test Unmodified If-Unmodified-Since predicate<BR>
(Request feed based on very current Last-Modified. Use If-Unmodified-Since predicate in request header. Expect status 304, item not modified, no feed body.)</LI>
<LI>Test Unmodified If-Modified-Since predicate<BR>
(Request feed based on very old Last-Modified. Use If-Modified-Since predicate in request header. Expect status 200, feed in body.)</LI>
<LI>Test Modified If-None-Match predicate<BR>
(Request feed based on existing ETag. Use If-None-Match predicate in request header. Expect status 200, feed in body.)</LI>
<LI>Test Modified If-Match predicate<BR>
(Request feed based on existing ETag. Use If-Match predicate in request header. Expect status 412, precondition failed, no feed in body.)</LI>
<LI>Test Modified If-UnModified-Since predicate<BR>
(Request feed based on very recent Last-Mod date. Use If-Unmodified-Since predicate in request header. Expect status 304, no feed in body.)</LI>
<LI>Test Modified If-Modified-Since predicate<BR>
(Request feed based on very old Last-Mod date. Use If-Modified-Since predicate in request header. Expect status 200, feed in body.)</LI>
</UL>
<P>Support of Web 2.0 data caching via ETags and Last-Modified fields allow the Tuscany user to save bandwidth and re-requests of data. Especially in the area of content feeds which can have very large data objects, the ability to cache improves server performance and reduces network bottlenecks. A full end-to-end demonstration of this network savings is being created via Jira TUSCANY-2537 which will show caching in the feed aggregator sample.</P>
<H4><A name="SCAJavabinding.atom-SupportforNegotiatedContentTypes"></A>Support for Negotiated Content Types</H4>
<P>Requests for data now respond with negotiated content types. In other words, the requester can now state which content types are preferred, and the responder can provide different content types. The data preference is expressed in the request header "Accept" parameter.</P>
<P>These data binding types are supported:</P>
<UL>
<LI>Atom XML format (Request header Accept=application/atom+xml)</LI>
<LI>Atom in JSON format (Request header Accept=application/atom+json)</LI>
</UL>
<P>The following content types are requestable in different data bindings</P>
<UL>
<LI>Atom entry data (MIME type application/atom+xxx;type=entry where xxx=xml or json)</LI>
<LI>Atom feed data (MIME type application/atom+xxx;type=feed where xxx=xml or json)</LI>
</UL>
<P>For example, the requester asks for an Atom entry with no Accept header or Accept header value is application/atom+xml. The returned response body contains:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Atom Entry response body as XML</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2005/Atom"</SPAN>>
</SPAN> <title type=<SPAN class="code-quote">"text"</SPAN>>customer Fred Farkle</title>
<updated>2008-08-08T18:40:30.484Z</updated>
<author>
<name>Apache Tuscany</name>
</author>
<content type=<SPAN class="code-quote">"text"</SPAN>>Fred Farkle</content>
<id>urn:uuid:customer-91d349b3-4b8b-4cfa-b9e9-d999f9937085</id>
<link href=<SPAN class="code-quote">"urn:uuid:customer-91d349b3-4b8b-4cfa-b9e9-d999f9937085"</SPAN> rel=<SPAN class="code-quote">"edit"</SPAN> />
<link href=<SPAN class="code-quote">"urn:uuid:customer-91d349b3-4b8b-4cfa-b9e9-d999f9937085"</SPAN> rel=<SPAN class="code-quote">"alternate"</SPAN> />
</entry>
</PRE>
</DIV></DIV>
<P>In contrast, the requester asks for an Atom entry with Accept header value is application/atom+json. The returned response body contains:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Atom Entry response body as JSON</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
{
<SPAN class="code-quote">"id"</SPAN>:<SPAN class="code-quote">"urn:uuid:customer-91d349b3-4b8b-4cfa-b9e9-d999f9937085"</SPAN>,
<SPAN class="code-quote">"title"</SPAN>:<SPAN class="code-quote">"customer Fred Farkle"</SPAN>,
<SPAN class="code-quote">"content"</SPAN>:<SPAN class="code-quote">"Fred Farkle"</SPAN>,
<SPAN class="code-quote">"updated"</SPAN>:<SPAN class="code-quote">"2008-08-08T18:40:30.484Z"</SPAN>,
<SPAN class="code-quote">"authors"</SPAN>:[{
<SPAN class="code-quote">"name"</SPAN>:<SPAN class="code-quote">"Apache Tuscany"</SPAN>
}
],
<SPAN class="code-quote">"links"</SPAN>:[{
<SPAN class="code-quote">"href"</SPAN>:<SPAN class="code-quote">"urn:uuid:customer-91d349b3-4b8b-4cfa-b9e9-d999f9937085"</SPAN>,
<SPAN class="code-quote">"rel"</SPAN>:<SPAN class="code-quote">"edit"</SPAN>
},{
<SPAN class="code-quote">"href"</SPAN>:<SPAN class="code-quote">"urn:uuid:customer-91d349b3-4b8b-4cfa-b9e9-d999f9937085"</SPAN>,
<SPAN class="code-quote">"rel"</SPAN>:<SPAN class="code-quote">"alternate"</SPAN>
}
]
}
</PRE>
</DIV></DIV>
<P>The ability to view entires and feeds in multiple data formats allows the Tuscany user extreme flexibility in parsing and processing data returned by a service or collection.</P>
<H4><A name="SCAJavabinding.atom-ServiceandWorkspaceDocumentSupport%28application%2Fatomsvcxml%29"></A>Service and Workspace Document Support (application/atomsvc+xml)</H4>
<P>Prior to this implementation, there was a dummy service document provided when you visited an Atom feed service address with an "atomsvc" extension. For example, running the the Atom service binding unit tests, one could visit <A href="http://localhost:8080/customer/atomsvc" class="external-link" rel="nofollow">http://localhost:8080/customer/atomsvc</A> and receive the following service document:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany Atom Binding Dummy Service document</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
<?xml version='1.0' encoding='UTF-8'?>
<service xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2007/app"</SPAN> xmlns:atom=<SPAN class="code-quote">"http://www.w3.org/2005/Atom"</SPAN>>
</SPAN> <workspace>
<atom:title type=<SPAN class="code-quote">"text"</SPAN>>resource</atom:title>
<collection href=<SPAN class="code-quote">"http:<SPAN class="code-comment">//luck.ibm.com:8084/customer"</SPAN>>
</SPAN> <atom:title type=<SPAN class="code-quote">"text"</SPAN>>collection</atom:title>
<accept>application/atom+xml;type=entry</accept>
<categories />
</collection>
</workspace>
</service>
</PRE>
</DIV></DIV>
<P>This dummy implementation did not provide a true collection name, URL to the collection, accept MIME types or categories.</P>
<P>Following the inclusion of TUSCANY-2597 and the new implentation, the Tuscany Atom binding will correctly populate an atomsvc document with information from the feed and give correct information for discovery. Now , running the the Atom service binding unit tests, one could visit <A href="http://localhost:8080/customer/atomsvc" class="external-link" rel="nofollow">http://localhost:8080/customer/atomsvc</A> and receive the following service document:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany Atom Binding Service document</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
<?xml version='1.0' encoding='UTF-8'?>
<service xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2007/app"</SPAN> xmlns:atom=<SPAN class="code-quote">"http://www.w3.org/2005/Atom"</SPAN>>
</SPAN> <workspace xml:base=<SPAN class="code-quote">"http:<SPAN class="code-comment">//localhost:8084/"</SPAN>>
</SPAN> <atom:title type=<SPAN class="code-quote">"text"</SPAN>>workspace</atom:title>
<collection href=<SPAN class="code-quote">"http:<SPAN class="code-comment">//localhost:8084/customer"</SPAN>>
</SPAN> <atom:title type=<SPAN class="code-quote">"text"</SPAN>>customers</atom:title>
<accept>application/atom+xml; type=feed</accept>
<accept>application/json; type=feed</accept>
<accept>application/atom+xml; type=entry</accept>
<accept>application/json; type=entry</accept>
<categories />
</collection>
</workspace>
</service>
</PRE>
</DIV></DIV>
<P>The service document is now properly populated with URLs, titles, accept MIME types and categories. These are elements that are needed for collection discovery and visitatin.</P>
<H4><A name="SCAJavabinding.atom-SupportforfullJavaScriptAtomclient."></A>Support for full JavaScript Atom client.</H4>
<P><A name="SCAJavabinding.atom-JavaScriptAtomClient"></A><BR>
After creating and publishing your SCA service, it can be tedious converting to and from Atom Feeds and Entries on the client side. Tuscany provides a full JavaScript object model for Atom Feeds, Entries, and other data objects. This benefits customers and client developers by providing an easy model to use in HTML, JSP, scripts, GUIs, and other client side technology.</P>
<P>For example, prior to this feature, developers would have to develop code in XML to manipulate nodes in the XML document that represented the current page:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany client side XML Document Manipulation (old style)</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">var</SPAN> entries = feed.getElementsByTagName(<SPAN class="code-quote">"entry"</SPAN>);
<SPAN class="code-keyword">var</SPAN> list = "";
<SPAN class="code-keyword">for</SPAN> (<SPAN class="code-keyword">var</SPAN> i=0; i<entries.length; i++) {
<SPAN class="code-keyword">var</SPAN> item = entries[i].getElementsByTagName(<SPAN class="code-quote">"content"</SPAN>)[0].firstChild.nodeValue;
list += item + ' <br>';
}
</PRE>
</DIV></DIV>
<P>Using the new JavaScript client object model, the code is greatly simplified and easier to understand:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany client side JavaScript Atom Object Model (new style)</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">var</SPAN> entries = feed.getEntries();
<SPAN class="code-keyword">var</SPAN> list = "";
<SPAN class="code-keyword">for</SPAN> (<SPAN class="code-keyword">var</SPAN> i=0; i<entries.length; i++) {
<SPAN class="code-keyword">var</SPAN> item = entries[i].getContent();
list += item + ' <br>';
}
</PRE>
</DIV></DIV>
<P>Additionally, the Tuscany Atom JavaScript client provides full deserialization and serialization to and from the JavaScript Atom model and its XML format. In other words let's say you create an HTML page that scrapes a data base and wants to submit the data as an entry to a collection of blog articles. You can create the Entry data using the JavaScript Entry model:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">var</SPAN> entry = <SPAN class="code-keyword">new</SPAN> Entry();
entry.setNamespace( <SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2005/Atom"</SPAN> );
</SPAN> entry.setTitle( <SPAN class="code-quote">"Atom-Powered Robots Run Amok"</SPAN> );
entry.setId( <SPAN class="code-quote">"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"</SPAN> );
entry.setUpdated( <SPAN class="code-quote">"2003-12-13T18:30:02Z"</SPAN> );
entry.setContent( <SPAN class="code-quote">"Some text."</SPAN> );
entry.addAuthor( <SPAN class="code-keyword">new</SPAN> Person( <SPAN class="code-quote">"John Doe"</SPAN> ) );
entry.addAuthor( <SPAN class="code-keyword">new</SPAN> Person( <SPAN class="code-quote">"Mark Pilgrim"</SPAN>, <SPAN class="code-quote">"f8dy@example.com"</SPAN> ));
entry.addContributor( <SPAN class="code-keyword">new</SPAN> Person( <SPAN class="code-quote">"Sam Ruby"</SPAN> ));
entry.addContributor( <SPAN class="code-keyword">new</SPAN> Person( <SPAN class="code-quote">"Joe Gregorio"</SPAN> ));
entry.addLink( <SPAN class="code-keyword">new</SPAN> Link( <SPAN class="code-quote">"http:<SPAN class="code-comment">//example.org/edit/first-post.atom"</SPAN>, <SPAN class="code-quote">"edit"</SPAN> ));</SPAN>
</PRE>
</DIV></DIV>
<P>Now to convert this code to XML and submit it to a site is easy using the Tuscany Atom JavaScript client:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">var</SPAN> text = entry.toXML();
</PRE>
</DIV></DIV>
<P>The text string now contains the fully serialized XML format of the Entry object</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-quote">"<?xml version="</SPAN>1.0"?>
<entry xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2005/Atom"</SPAN>>
</SPAN> <title>Atom-Powered Robots Run Amok</title>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<author><name>John Doe</name></author>
<content>Some text.</content>
<link rel=<SPAN class="code-quote">"edit"</SPAN> href=<SPAN class="code-quote">"http:<SPAN class="code-comment">//example.org/edit/first-post.atom"</SPAN>/>
</SPAN> </entry>"
</PRE>
</DIV></DIV>
<P>Similarly the Tuscany Atom JavaScript client contains methods for deserializing from XML reperesentations to a JavaScript Atom model:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">var</SPAN> feed = <SPAN class="code-keyword">new</SPAN> Feed();
feed.readFromXML( xmlString );
</PRE>
</DIV></DIV>
<P>A full example showing how to use this client model is given in implementation-widgets-runtime. The store.html page shows the older style of document XML manipulation. The storeJS.html page shows the newer style of JavaScript object manipulation.</P>
<H4><A name="SCAJavabinding.atom-SupportforPostingandPuttingMediaItems"></A>Support for Posting and Putting Media Items</H4>
<P>The Atom Publishing Protocol provides for a separate space for storage of media resources. The purpose of a separate space for these resources is to keep feeds and entries from growing too large with the contents of typically large items. Media resources can be any binary object that is supported by a MIME type, but typically media resources include video, image, and audio type files.</P>
<P>Media resources are maintained by the collection implementor, and are given a dual identity. There is a location in the media respository, typically where one places the media files, and there is a location in the feed or entry space. This second reference is known as a media link entry.</P>
<P>The Tuscany package at org.apache.tuscany.sca.binding.atom.collection (in tuscany-binding-atom-abdera package) has the following interface for MediaCollection:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Tuscany MediaCollection interface</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
/**
* Creates a <SPAN class="code-keyword">new</SPAN> media entry
*
* @param title
* @param slug
* @param contentType
* @param media
*/
Entry postMedia(<SPAN class="code-object">String</SPAN> title, <SPAN class="code-object">String</SPAN> slug, <SPAN class="code-object">String</SPAN> contentType, InputStream media);
/**
* Update a media entry.
*
* @param id
* @param contentType
* @param media
* @<SPAN class="code-keyword">return</SPAN>
*/
void putMedia(<SPAN class="code-object">String</SPAN> id, <SPAN class="code-object">String</SPAN> contentType, InputStream media) <SPAN class="code-keyword">throws</SPAN> NotFoundException;
</PRE>
</DIV></DIV>
<P>These two methods are used to create (post) new media files, and update (put) new media information and edits. The media resources may be retrieved (get) or removed (delete) via the normal HTTP get and delete operations and the links returned by the post and get methods.</P>
<P>For instance, when creating a media resource, one typically posts the following information via an HTTP post request:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Requesting New Media Creation (postMedia method invoke)</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
POST /edit/ HTTP/1.1
Host: media.example.org
Content-Type: image/png
Slug: The Beach
Authorization: Basic ZGFmZnk6c2VjZXJldA==
Content-Length: nnn
...binary data...
</PRE>
</DIV></DIV>
<P>In turn, the Tuscany invocation framework invokes the postMedia shown above on the media collection implementation. The media collection implementation may then take the binary data from the media InputStream and store it to a media repository. The media collection implemenation should construct a proper Entry item via XML construction or some Atom model framework such as Apache Abdera. The Entry should contain the required elements (title, id, updated, summary, content, edit link, edit-media link) in order to provide the proper Atom Pub Protocol return headers and Entry data as given here:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Affirming New Media Creation (postMedia method return)</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
HTTP/1.1 201 Created
Content-Length: nnn
Content-Type: application/atom+xml;type=entry;charset=<SPAN class="code-quote">"utf-8"</SPAN>
Location: http:<SPAN class="code-comment">//example.org/media/edit/the_beach.atom
</SPAN><?xml version=<SPAN class="code-quote">"1.0"</SPAN>?>
<entry xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2005/Atom"</SPAN>>
</SPAN> <title>The Beach</title>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2005-10-07T17:17:08Z</updated>
<author><name>Daffy</name></author>
<summary type=<SPAN class="code-quote">"text"</SPAN> />
<content type=<SPAN class="code-quote">"image/png"</SPAN>
src=<SPAN class="code-quote">"http:<SPAN class="code-comment">//media.example.org/the_beach.png"</SPAN>/>
</SPAN> <link rel=<SPAN class="code-quote">"edit-media"</SPAN>
href=<SPAN class="code-quote">"http:<SPAN class="code-comment">//media.example.org/edit/the_beach.png"</SPAN> />
</SPAN> <link rel=<SPAN class="code-quote">"edit"</SPAN>
href=<SPAN class="code-quote">"http:<SPAN class="code-comment">//example.org/media/edit/the_beach.atom"</SPAN> />
</SPAN></entry>
</PRE>
</DIV></DIV>
<P>Note that the edit link provides the Atom Feed link to the media entry, and the edit-media link provides the media repository link to the media entry. Use these links to get and delete media.</P>
<P>A special convention has been implemented to allow the media collection implementation to return properties in the response header. The summary element of the Entry returned may contain a set of key=value properties separated via commas. For example, in order to provide return Content-Type and Content-Length values in the response header, one can created this text in the postMedia Entry summary element: <TT>Content-Type=image/jpg,Content-Length=21642</TT>.</P>
<P>The putMedia method acts in much the same way, but the URI to the item should contain an ID to the media being updated. For instance, if the usual post and get feed URI is <TT><A href="http://localhost:8084/receipt" class="external-link" rel="nofollow">http://localhost:8084/receipt</A></TT>, then to update the media given above one would put to the URI <TT><A href="http://localhost:8084/receipt/urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a" class="external-link" rel="nofollow">http://localhost:8084/receipt/urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</A></TT>. Here is an example of a put request:</P>
<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Requesting Media Update (putMedia method invoke)</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
PUT /edit/urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a HTTP/1.1
Host: media.example.org
Content-Type: image/png
Authorization: Basic ZGFmZnk6c2VjZXJldA==
Content-Length: nnn
...binary data...
</PRE>
</DIV></DIV>
<P>After the above put request, the Atom binding will invoke the media collection implementation putMedia method. The media collection should update the media if the ID exists (and a 200 OK status code will return), or the media collection should throw a NotFoundException if the ID does not exist (and a 404 not found status code will return).</P>
<P>The above scenarios are documents in the MediaCollectionTestCase unit test case in the binding-atom-abdera module in the Tuscany code base.</P>
<H3><A name="SCAJavabinding.atom-SecurityPolicysupportinHTTPandWeb2.0Bindings"></A>Security Policy support in HTTP and Web 2.0 Bindings</H3>
<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>work in progress</TD></TR></TABLE></DIV>
<H3><A name="SCAJavabinding.atom-Scenarios"></A>Scenarios</H3>
<UL>
<LI>A Web 2.0 application requires that a user get authenticated before it can access the application.</LI>
<LI>A Web 2.0 application requires that all communication between client/server be done using SSL.</LI>
<LI>A given service, exposed using a web 2.0 binding requires user authentication.</LI>
<LI>A given operation, exposed using a web 2.0 binding requires user authentication.</LI>
</UL>
<H3><A name="SCAJavabinding.atom-PolicyInterceptor"></A>Policy Interceptor</H3>
<P>The design approach that is being considered is to inject policy security interceptors, that would properly validate and enforce the security intents.<BR>
The authentication will be done using JAAS modules for authentication, and initially we would support authenticating to a list of username/password supplied by the application or using an LDAP.</P>
<P><SPAN class="image-wrap" style="display: block; text-align: center"><IMG src="sca-java-bindinghttp-security-policy-section.data/policy_interceptors_high_level_design.jpg" style="border: 0px solid black"></SPAN></P>
</DIV>
</DIV>
</DIV>
</TD>
</TR>
</TABLE>
<!-- footer -->
<TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
<TR>
<TD align="left" valign="middle" class="footer">
<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>
<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.atom';
digg_topic = 'programming';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
-->
</TD>
<TD align="right" valign="middle" class="footer">
<A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A> -
Copyright © 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
|