0
REZA LESMANA                               Universitas GunadarmaSaturday, February 5, 2011
REST                             Using Restlet FrameworkSaturday, February 5, 2011
REST                    Representational State TransferSaturday, February 5, 2011
WHAT IS REST?               GAYA ARSITEKTUR SOFTWARE UNTUK ARSITEKTUR                        APLIKASI BERBASIS JARINGAN   ...
WHY USE REST?                             UNIFORM INTERFACE    SEMUA KOMPONEN APLIKASI DALAM WEB SERVICES       BERINTERAK...
UNIFORM INTERFACE                                one of the feature of RESTSaturday, February 5, 2011
UNIFORM INTERFACE                             Resource Identification [1]                                   RESOURCE       ...
UNIFORM INTERFACE                             Resource Identification [2]                   Uniform Resource Identifier     ...
UNIFORM INTERFACE                              Resource Identification [3]                                        URI Templ...
RESTLET FRAMEWORK                                 application building blockSaturday, February 5, 2011
RESTLET FRAMEWORK                                   servlet configuration (web.xml)                              <!-- Appli...
UNIFORM INTERFACE                              Resource Identification [4]                                 aplikasi penyimp...
RESTLET FRAMEWORK                              MainApplication       public class MainApplication extends Application {   ...
UNIFORM INTERFACE      Manipulation Through Representation [1]                                REPRESENTATION              ...
RESTLET FRAMEWORK                                 application building blockSaturday, February 5, 2011
UNIFORM INTERFACE      Manipulation Through Representation [2]                              HTTP METHOD as Popular Practic...
UNIFORM INTERFACE      Manipulation Through Representation [3]                                        Another Protocol?   ...
UNIFORM INTERFACE      Manipulation Through Representation [4]                       Standardized Document Structure as Re...
UNIFORM INTERFACE      Manipulation Through Representation [5]                                      Not Only HTTP         ...
RESTLET FRAMEWORK                              MainApplication       public class MainApplication extends Application {   ...
RESTLET FRAMEWORK      Manipulation Through Representation [1]                       public class MessageResource extends ...
RESTLET FRAMEWORK      Manipulation Through Representation [2]                  @Get("xml")           	      public Repres...
RESTLET FRAMEWORK      Manipulation Through Representation [3]                       	     @Put                       	   ...
RESTLET FRAMEWORK      Manipulation Through Representation [4]            	     @Delete            	     public Representa...
UNIFORM INTERFACE                             Self-Descriptive Messages [1]                                    TWO FACTORS...
UNIFORM INTERFACE                             Self-Descriptive Messages [2]                                  The Protocol ...
UNIFORM INTERFACE                             Self-Descriptive Messages [3]                                       The Medi...
Contoh MediaType XML            <messages>              <message>                     <messageid>120</messageid>          ...
Contoh MediaType Atom <entry>    <id>urn:uuid:95506d98-aae9-4d34-a8f4-1ff30bece80c</id>    <title type=ʹ′ʹ′textʹ′ʹ′>produc...
RESTLET FRAMEWORK                             Self-Descriptive Message [1]           @Get("xml")           	 public Repres...
RESTLET FRAMEWORK                             Self-Descriptive Message [2]                                 <messages>     ...
Saturday, February 5, 2011
UNIFORM INTERFACE      Hypermedia as The Engine of Application             State (HATEOAS) [1]                            ...
UNIFORM INTERFACE                             Hypermedia Constraint [1]    • Inti          dari Representational State Tra...
UNIFORM INTERFACE                             Hypermedia Constraint [2]                    explains why named as “represen...
UNIFORM INTERFACE                             Hypermedia Constraint [3]                                 execution of busin...
UNIFORM INTERFACE                             Hypermedia Constraint [3]                                        Best Practi...
UNIFORM INTERFACE                             Hypermedia Constraint [4]                                                   ...
UNIFORM INTERFACE                             Hypermedia Constraint [5]                               hypermedia support i...
RESTLET FRAMEWORK                             Hypermedia Constraints [1]    • Native    support untuk mempermudah manajeme...
CONTOH APLIKASI LAIN                                  SOCIAL COMMERCE [1]    • Indeks Aplikasi              Memuat :      ...
CONTOH APLIKASI LAIN                                    SOCIAL COMMERCE [2]    • Masuk                  ke salah satu Toko...
CONTOH APLIKASI LAIN                                  SOCIAL COMMERCE [3]    • Lihat            deskripsi lengkap produk (...
CONTOH APLIKASI LAIN                             SOCIAL COMMERCE [4]Saturday, February 5, 2011
CONTOH APLIKASI LAIN                             SOCIAL COMMERCE [5]Saturday, February 5, 2011
CONTOH APLIKASI LAIN                             SOCIAL COMMERCE [6]Saturday, February 5, 2011
CONTOH APLIKASI LAIN                             SOCIAL COMMERCE [7]Saturday, February 5, 2011
THANK YOU !                             QUESTION?Saturday, February 5, 2011
Upcoming SlideShare
Loading in...5
×

Rest dengan restlet

789

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
789
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Rest dengan restlet"

  1. 1. REZA LESMANA Universitas GunadarmaSaturday, February 5, 2011
  2. 2. REST Using Restlet FrameworkSaturday, February 5, 2011
  3. 3. REST Representational State TransferSaturday, February 5, 2011
  4. 4. WHAT IS REST? GAYA ARSITEKTUR SOFTWARE UNTUK ARSITEKTUR APLIKASI BERBASIS JARINGAN BASICALLY WEB SERVICES ARCHITECTURESaturday, February 5, 2011
  5. 5. WHY USE REST? UNIFORM INTERFACE SEMUA KOMPONEN APLIKASI DALAM WEB SERVICES BERINTERAKSI DENGAN CARA YANG SAMASaturday, February 5, 2011
  6. 6. UNIFORM INTERFACE one of the feature of RESTSaturday, February 5, 2011
  7. 7. UNIFORM INTERFACE Resource Identification [1] RESOURCE informasi yang dibutuhkan oleh user untuk menjalankan proses bisnis dari suatu aplikasiSaturday, February 5, 2011
  8. 8. UNIFORM INTERFACE Resource Identification [2] Uniform Resource Identifier (URI) Contoh : HTTP URLSaturday, February 5, 2011
  9. 9. UNIFORM INTERFACE Resource Identification [3] URI Template http://contohaja.com/message/{index}Saturday, February 5, 2011
  10. 10. RESTLET FRAMEWORK application building blockSaturday, February 5, 2011
  11. 11. RESTLET FRAMEWORK servlet configuration (web.xml) <!-- Application class name --> <context-param> <param-name>org.restlet.application</param-name> <param-value> com.helloworld.main.MainApplication </param-value> </context-param> <!-- Restlet adapter --> <servlet> <servlet-name>RestletServlet</servlet-name> <servlet-class> org.restlet.ext.servlet.ServerServlet </servlet-class> </servlet> <!-- Catch all requests --> <servlet-mapping> <servlet-name>RestletServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>Saturday, February 5, 2011
  12. 12. UNIFORM INTERFACE Resource Identification [4] aplikasi penyimpanan pesan dalam stack • Daftar Pesan ---> • “/” ---> MessagesResource • Top of Stack ---> • “/message/ ---> MessageResource • Pesan Tunggal ---> • “/message/{index} ---> MessageResourceSaturday, February 5, 2011
  13. 13. RESTLET FRAMEWORK MainApplication public class MainApplication extends Application { public MainApplication(Context parentContext) { super(parentContext); } @Override public synchronized Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/", MessagesResource.class); router.attach("/message/", MessageResource.class); router.attach("/message/{messageIndex}", MessageResource.class); return router; } }Saturday, February 5, 2011
  14. 14. UNIFORM INTERFACE Manipulation Through Representation [1] REPRESENTATION representasi dari resourceSaturday, February 5, 2011
  15. 15. RESTLET FRAMEWORK application building blockSaturday, February 5, 2011
  16. 16. UNIFORM INTERFACE Manipulation Through Representation [2] HTTP METHOD as Popular Practices • HTTP POST ---> • membuat Resource baru (Create) • HTTP GET ---> • mendapatkan Resource (Read) • HTTP PUT ---> • mengubah Resource (Update) • HTTP DELETE ---> • menghapus Resource (Delete)Saturday, February 5, 2011
  17. 17. UNIFORM INTERFACE Manipulation Through Representation [3] Another Protocol? • Gunakan standar protokol komunikasi sesuai dengan spesifikasinya • Perhatikan Safety dan Idempotency dari method • Safety : tidak menghasilkan “efek samping” pada resource • Idempotency : dilakukan berulang-ulang hasilnya samaSaturday, February 5, 2011
  18. 18. UNIFORM INTERFACE Manipulation Through Representation [4] Standardized Document Structure as Representation • XHTML • MPEG • XML • MP3 • Atom Pub • AVI • OData • Text/Audio/Video StreamingSaturday, February 5, 2011
  19. 19. UNIFORM INTERFACE Manipulation Through Representation [5] Not Only HTTP TEXT/AUDIO/VIDEO STREAMING Contoh : VoIP Using SIP or XMPPSaturday, February 5, 2011
  20. 20. RESTLET FRAMEWORK MainApplication public class MainApplication extends Application { public MainApplication(Context parentContext) { super(parentContext); } @Override public synchronized Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/", MessagesResource.class); router.attach("/message/", MessageResource.class); router.attach("/message/{messageIndex}", MessageResource.class); return router; } }Saturday, February 5, 2011
  21. 21. RESTLET FRAMEWORK Manipulation Through Representation [1] public class MessageResource extends ServerResource { @Post public Representation addMessage(Representation entity) { StringRepresentation representation = null; String result = ""; try { result = HelloBusiness.create(entity.getText()); } catch (IOException e) { setStatus(Status.SERVER_ERROR_INTERNAL ); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }Saturday, February 5, 2011
  22. 22. RESTLET FRAMEWORK Manipulation Through Representation [2] @Get("xml") public Representation get(){ String index = (String)getRequest().getAttributes().get("messageIndex"); StringRepresentation representation = null; String result = ""; try{ if(index != "" && index != null){ result = HelloBusiness.get(Integer.parseInt(index)); }else{ result = HelloBusiness.get(); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }catch(Exception e){ setStatus(Status.CLIENT_ERROR_NOT_FOUND); representation = new StringRepresentation ("no item found", MediaType.TEXT_PLAIN); return representation; } }Saturday, February 5, 2011
  23. 23. RESTLET FRAMEWORK Manipulation Through Representation [3] @Put public Representation put(Representation entity){ StringRepresentation representation = null; String result = ""; try { result = HelloBusiness.update(entity.getText()); } catch (IOException e) { setStatus(Status.SERVER_ERROR_INTERNAL ); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }Saturday, February 5, 2011
  24. 24. RESTLET FRAMEWORK Manipulation Through Representation [4] @Delete public Representation delete(){ StringRepresentation representation = null; String result = ""; try { result = HelloBusiness.delete(); }catch(NoMoreItemException ne){ setStatus(Status.CLIENT_ERROR_FORBIDDEN); representation = new StringRepresentation ("Tidak boleh, udah kosong", MediaType.TEXT_PLAIN); return representation; } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }Saturday, February 5, 2011
  25. 25. UNIFORM INTERFACE Self-Descriptive Messages [1] TWO FACTORS The Protocol Message The Media Type (Type of Representation)Saturday, February 5, 2011
  26. 26. UNIFORM INTERFACE Self-Descriptive Messages [2] The Protocol Message • HTTP Header --> Content Negotiation • Contoh : Accept : application/xml • Status Respon : • Contoh : HTTP 1.1 / 200 OK ,HTTP 1.1 / 403 FORBIDDENSaturday, February 5, 2011
  27. 27. UNIFORM INTERFACE Self-Descriptive Messages [3] The Media Type • Struktur Dokumen Bisa Mudah Diolah • Contoh : • XML (application/xml) • Atom Pub (application/atom+xml)Saturday, February 5, 2011
  28. 28. Contoh MediaType XML <messages> <message> <messageid>120</messageid> <author>Reza</author> <created>2011/02/04 08:20:12</created> <value>Hello, World!</value> <link>/message/120</link> <message> ........ ........ <messages>Saturday, February 5, 2011
  29. 29. Contoh MediaType Atom <entry> <id>urn:uuid:95506d98-aae9-4d34-a8f4-1ff30bece80c</id> <title type=ʹ′ʹ′textʹ′ʹ′>product created</title> <updated>2009-07-05T10:25:00Z</updated> <link rel=ʹ′ʹ′selfʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/notifications/95506d98-aae9-4d34- a8f4-1ff30bece80cʹ′ʹ′/> <link rel=ʹ′ʹ′relatedʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/527ʹ′ʹ′/> <category scheme=ʹ′ʹ′http://starbucks.com/products/categories/typeʹ′ʹ′ term=ʹ′ʹ′productʹ′ʹ′/> <category scheme=ʹ′ʹ′http://starbucks.com/products/categories/statusʹ′ʹ′ term=ʹ′ʹ′newʹ′ʹ′/> <content type=ʹ′ʹ′application/vnd.starbucks+xmlʹ′ʹ′> <product xmlns=ʹ′ʹ′http://schemas.starbucks.com/productʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/527ʹ′ʹ′> <name>Fairtrade Roma Coffee Beans</name> <size>1kg</size> <price>10</price> <currency>$</currency> </product> </content> </entry>Saturday, February 5, 2011
  30. 30. RESTLET FRAMEWORK Self-Descriptive Message [1] @Get("xml") public Representation get(){ String index = (String)getRequest().getAttributes().get("messageIndex"); StringRepresentation representation = null; String result = ""; try{ if(index != "" && index != null){ result = HelloBusiness.get(Integer.parseInt(index)); }else{ result = HelloBusiness.get(); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }catch(NotFoundException e){ setStatus(Status.CLIENT_ERROR_NOT_FOUND); representation = new StringRepresentation ("no item found", MediaType.TEXT_PLAIN); return representation; } }Saturday, February 5, 2011
  31. 31. RESTLET FRAMEWORK Self-Descriptive Message [2] <messages> <request>GET : ALL</request> <message> <request>GET</request> <value>Hello, World!</value> <link>/message/0</link> </message> <message> <request>GET</request> <value>Halo, Dunia!</value> <link>/message/1</link> </message> <message> <request>GET</request> <value>Apa Kabar?</value> <link>/message/2</link> </message> </messages>Saturday, February 5, 2011
  32. 32. Saturday, February 5, 2011
  33. 33. UNIFORM INTERFACE Hypermedia as The Engine of Application State (HATEOAS) [1] or Hypermedia constraintsSaturday, February 5, 2011
  34. 34. UNIFORM INTERFACE Hypermedia Constraint [1] • Inti dari Representational State Transfer • Menyatukan informasi proses bisnis dalam representasi resourceSaturday, February 5, 2011
  35. 35. UNIFORM INTERFACE Hypermedia Constraint [2] explains why named as “representational state transfer”Saturday, February 5, 2011
  36. 36. UNIFORM INTERFACE Hypermedia Constraint [3] execution of business process “Consumers in a hypermedia system cause state transitions by visiting and manipulating resource state. Interestingly, the application state changes that result from a consumer driving a hypermedia system resemble the execution of a business process. This suggests that our services can advertise workflows using hypermedia.” - Jim Webber - REST In PracticeSaturday, February 5, 2011
  37. 37. UNIFORM INTERFACE Hypermedia Constraint [3] Best Practices • Menambahkan informasi possible next states langsung di dalam Representation • Caranya (untuk saat ini) : • possible next states ----> hyperlinksSaturday, February 5, 2011
  38. 38. UNIFORM INTERFACE Hypermedia Constraint [4] examples <entry> <order xmlns=ʹ′ʹ′http://schemas.starbucks.comʹ′ʹ′> <location>takeAway</location> <item> <name>latte</name> <quantity>1</quantity> <milk>whole</milk> <size>small</size> </item> <cost>2.0</cost> <status>payment-expected</status> <link rel=ʹ′ʹ′http://relations.restbucks.com/paymentʹ′ʹ′ href=ʹ′ʹ′https://restbucks.com/payment/1234ʹ′ʹ′/> <link rel=ʹ′ʹ′http://relations.restbucks.com/special-offerʹ′ʹ′ href=ʹ′ʹ′http://restbucks.com/offers/cookie/1234ʹ′ʹ′/> </entry>Saturday, February 5, 2011
  39. 39. UNIFORM INTERFACE Hypermedia Constraint [5] hypermedia support in MediaType • Lebih baik jangan gunakan MediaType XML untuk menambahkan hyperlinks di dalamnya. • Tidak ada dukungan langsung (native link tag) untuk hyperlinks • Gunakan Hypermedia Types (-Mike Amundsen) • Contoh : Atom • http://amundsen.com/hypermedia/Saturday, February 5, 2011
  40. 40. RESTLET FRAMEWORK Hypermedia Constraints [1] • Native support untuk mempermudah manajemen hypermedia constraints terdapat pada Restlet versi 2.1 (dalam pengembangan) • Solusi : Tambahkan secara manual ! :D • Solusi : Pakai versi 2.1 dengan resiko sendiriSaturday, February 5, 2011
  41. 41. CONTOH APLIKASI LAIN SOCIAL COMMERCE [1] • Indeks Aplikasi Memuat : • Daftar Toko Online (dengan link masing-masing) • Link ke User Profile • Link ke Pengaturan Toko Online milik userSaturday, February 5, 2011
  42. 42. CONTOH APLIKASI LAIN SOCIAL COMMERCE [2] • Masuk ke salah satu Toko Online (melalui link). Memuat : • Profil singkat penjual (dengan link ke profil lengkap) • Daftar Deskripsi Singkat Produk (dengan link masing- masing untuk deskripsi lengkap) • Link ke IndeksSaturday, February 5, 2011
  43. 43. CONTOH APLIKASI LAIN SOCIAL COMMERCE [3] • Lihat deskripsi lengkap produk (melalui link). Memuat : • Informasi produk • Link untuk memesan • Link kembali ke Toko OnlineSaturday, February 5, 2011
  44. 44. CONTOH APLIKASI LAIN SOCIAL COMMERCE [4]Saturday, February 5, 2011
  45. 45. CONTOH APLIKASI LAIN SOCIAL COMMERCE [5]Saturday, February 5, 2011
  46. 46. CONTOH APLIKASI LAIN SOCIAL COMMERCE [6]Saturday, February 5, 2011
  47. 47. CONTOH APLIKASI LAIN SOCIAL COMMERCE [7]Saturday, February 5, 2011
  48. 48. THANK YOU ! QUESTION?Saturday, February 5, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×