SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Creating a Web of Data
            with Restlet
                          Andrew Newman




Monday, 8 December 2008                   1
REST Architecture
       Resource Oriented Analysis and Design (ROAD)
       Stateless Access
       Where Everything is a Resource
       Identified by URI
       With Different Representations
       Linked Together




Monday, 8 December 2008                               2
Restlet Oveview
         GWT, Client and Server APIs
         Standalone, App Servers, Oracle, OSGi, Spring
         HTTP, SMTP, POP3, JDBC, File Connectors
         JSON, XML, HTML, Atom Representations
         Integration with Groovy, JPA, Seam, Struts
         Hibernate



Monday, 8 December 2008                                  3
A little bit of HTTP
               Verb                    Action
                GET           Return the entity
              POST            Server create/modify entity
                PUT           Client create/modify entity
            DELETE        X   Delete an entity
              HEAD            Entity metadata (not data)
         OPTIONS          ?   Methods supported on entity


Monday, 8 December 2008                                     4
Restlet Model
                                                     Uniform


                                                     Restlet



                                   Application     Component        Redirector

                          Connector         Router             Filter         Finder




                          Client          Server                Guard            Route

                                                                        Transformer




Monday, 8 December 2008                                                                  5
Restlet Model
         •      Reference - Mutable java.net.URI

         •      Request - Client Request

         •      Response - Server Response

         •      MediaType - Mime Types e.g. text/html, application/xml

         •      Resource - Anything with a Reference e.g. video, document,
                collection

         •      Variant - Metadata about a representation.

               •      Representation - The current state/value of a Resource.



Monday, 8 December 2008                                                         6
Resource API
           GET            Representation represent(Variant)

          POST            void acceptRepresentation(Representation)

           PUT            void storeRepresentation(Representation)

        DELETE void removeRepresentations()

         HEAD             Calls GET without stream.

      OPTIONS Updates Response’s getAllowedMethods




Monday, 8 December 2008                                               7
Applications and Components
      // Create Application for http://localhost/helloWorld
      Application application = new Application() {
          public synchronized Restlet createRoot() {
              Router router = new Router(getContext());
              // Attach a resource
              router.attach(quot;helloWorldquot;, HelloWorldResource.class);
              return router;
          }
      };
      // Create the component and attach the application
      Component component = new Component();
      component.getServers().add(Protocol.HTTP);
      component.getDefaultHost().attach(application);
      // Start the web server
      component.start();




Monday, 8 December 2008                                                8
Data and Resources
      public HelloWorldResource(Context context, Request request,
          Response response) {
          super(context, request, response);
          // Declare all kind of representations supported by the resource
          getVariants().add(new Variant(MediaType.TEXT_PLAIN));
      }

      // Respond to GET
      public Representation represent(Variant variant) throws ResourceException {
          Representation representation = null;
          // Generate a representation according to the variant media type.
          if (MediaType.TEXT_PLAIN.equals(variant.getMediaType())) {
              representation = new StringRepresentation(quot;hello, worldquot;,
                  MediaType.TEXT_PLAIN);
          }
          return representation;
      }




Monday, 8 December 2008                                                             9
A Bit More HTTP
      GET /index HTTP/1.1
      Host: www.realestate.com
      User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:
      1.7.12)...
      Accept: text/xml,application/xml,application/xhtml
      +xml,text/html;q=0.9,...
      Accept-Language: us,en;q=0.5
      Accept-Encoding: gzip,deflate
      Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7
      Keep-Alive: 300
      Connection: keep-alive




Monday, 8 December 2008                                         10
Drop the Dot
      Yes
      http://realestate.com/house/1 + type
      No
      http://realestate.com/house/1.html
      http://realestate.com/house/1.xml
      http://realestate.com/house/1.json
      http://realestate.com/house/1.png


Monday, 8 December 2008                      11
No iPhone
      Yes
      http://realestate.com/house/1 + user-agent
      No
      http://www.realestate.com/house/1
      http://iphone.realestate.com/house/1
      http://iphone-v2.realestate.com/house/1
      http://n95-8GB-Black.realestate.com/house/1


Monday, 8 December 2008                             12
Client Side API
      // GET a resource from uri as a XML DOM.
      Response response = new Client(Protocol.HTTP).get(uri);
      DomRepresentation document = response.getEntityAsDom();
      // Specify content types.
      ClientInfo clientInfo = request.getClientInfo();
      List<Preference<MediaType>> preferenceList = new
          ArrayList<Preference<MediaType>>();
      preferenceList.add(new Preference<MediaType>(TEXT_XML));
      preferenceList.add(new Preference<MediaType>(APPLICATION_XML));
      preferenceList.add(new Preference<MediaType>(APPLICATION_XHTML_XML));
      preferenceList.add(new Preference<MediaType>(TEXT_HTML, 0.9f));
      clientInfo.setAcceptedMediaTypes(preferenceList);
      // Specify encodings
      clientInfo.setAcceptedEncodings(Arrays.asList(new
          Preference<Encoding>(Encoding.GZIP));
      // Finally, GET.
      client.get(uri);




Monday, 8 December 2008                                                       13
Simple WebDAV

                                Directory Demo

                          See also: http://code.google.com/p/gogoego/




Monday, 8 December 2008                                                 14
Restlet and Spring
      ConfigurableRestletResource
      <bean id=quot;someResourcequot; class=quot;SomeResourcequot; scope=quot;prototypequot;>
        <property name=quot;representationTemplatesquot;>
        <map>
          <entry key-ref=quot;TEXT_HTMLquot; value-ref=quot;htmlRepquot;/>
          <entry key-ref=quot;APPLICATION_JSONquot; value-ref=quot;jsonRepquot;/>
          <entry key-ref=quot;APPLICATION_XMLquot; value-ref=quot;xmlRepquot;/>
        </map>
        </property>
      </bean>




Monday, 8 December 2008                                                 15
Restlet and Spring
      FreemarkerRepresentationFactory
      <bean id=quot;htmlRepquot;
      class=quot;org.jrdf.query.server.FreemarkerRepresentationFactoryquot;>
        <property name=quot;templateNamequot; value=quot;dbLocal-html.ftlquot;/>
        <property name=quot;freemarkerConfigquot; ref=quot;freemarkerConfigquot;/>
      </bean>


      dbLocal-html.ftl
      <html>
      <head>
        <title>Query Page -- Database ${database}</title>
      </head>
      <body>
        <h1>
          Query for database <i>${database}</i>
      ...




Monday, 8 December 2008                                                16
Restlet and Spring
      SpringRouter
      <bean id=quot;routerquot; class=quot;org.restlet.ext.spring.SpringRouterquot;>
        <property name=quot;attachmentsquot;>
          <map>
          <entry key=quot;/databasesquot;>
            <bean class=quot;org.restlet.ext.spring.SpringFinderquot;>
               <lookup-method name=quot;createResourcequot; bean=quot;listDbResourcequot;/>
            </bean>
          </entry>
          <entry key=quot;/databases/{database}quot;>
            <bean class=quot;org.restlet.ext.spring.SpringFinderquot;>
              <lookup-method name=quot;createResourcequot; bean=quot;queryDbResourcequot;/>
            </bean>
          </entry>
          </map>
        </property>
      </bean>




Monday, 8 December 2008                                                       17
Restlet and Spring
      public Representation represent(Variant variant) {
          Representation rep = null;
          try {
              graphName = (String) getRequest().getAttributes().get(quot;databasequot;);
              if (getRequest().getResourceRef().hasQuery()) {
                  queryString = getRequest().getResourceRef().getQueryAsForm().
                       getFirst(quot;queryquot;).getValue();
              }
              if (queryString == null) {
                  rep = queryPageRepresentation(variant);
              } else {
                  rep = queryResultRepresentation(variant);
              }
              getResponse().setStatus(SUCCESS_OK);
          } catch (Exception e) {
              getResponse().setStatus(SERVER_ERROR_INTERNAL, e,
                  e.getMessage().replace(quot;nquot;, quot;quot;));
          }
          return rep;
      }




Monday, 8 December 2008                                                            18
Linking Data
                   MyFood.Com                          YourFood
                             recipe                       recipe
            ID              Desc.      Cat.    ID      Desc.          Cat.
             1              Chips     Snack     1      Toast         Snack
             2            Ice Water   Drink     2       Tea          Drink
                       URIs                                 URIs
         http://myfood.com/recipe/chips       http://yourfood.com/recipe/toast
         http://myfood.com/recipe/water        http://yourfood.com/recipe/tea
           http://myfood.com/cat/snack         http://yourfood.com/cat/snack
           http://myfood.com/cat/drink         http://yourfood.com/cat/drink



Monday, 8 December 2008                                                          19
Linking Data




                                      ?
                   MyFood.Com                          YourFood
                             recipe                       recipe
            ID              Desc.      Cat.    ID      Desc.          Cat.
             1              Chips     Snack     1      Toast         Snack
             2            Ice Water   Drink     2       Tea          Drink
                       URIs                                 URIs
         http://myfood.com/recipe/chips       http://yourfood.com/recipe/toast
         http://myfood.com/recipe/water        http://yourfood.com/recipe/tea
           http://myfood.com/cat/snack         http://yourfood.com/cat/snack
           http://myfood.com/cat/drink         http://yourfood.com/cat/drink



Monday, 8 December 2008                                                          20
Linking Data
  http://myfood.com/cat/snack

                                         http://yourfood.com/cat/snack
                 IsA




                                                 IsA
 http://myfood.com/recipe/chips


                                  http://yourfood.com/recipe/toast




Monday, 8 December 2008                                                  21
Linking Data
  http://myfood.com/cat/snack
                                isTheS
                                      ameA
                                           s
                                                http://yourfood.com/cat/snack
                 IsA




                                                        IsA
 http://myfood.com/recipe/chips


                                         http://yourfood.com/recipe/toast




Monday, 8 December 2008                                                         22
Linking Data
  http://myfood.com/cat/snack
                                   isTheS
                                         ameA
                                              s
                                                   http://yourfood.com/cat/snack
                 IsA




                                                           IsA
 http://myfood.com/recipe/chips
                          IsA




                                   IsA
                                            http://yourfood.com/recipe/toast
         http://purl.org/recipe




Monday, 8 December 2008                                                            23
Querying the Web
      User at myFood.Com wants all the snack recipes:
      1. Find all http://purl.org/recipe and http://myfood.com/cat/snack
             recipe {my:chips, my:water}, snack {my:snack}
      2. my:snack = your:snack
      3. Query YourFood
             recipe {your:toast, your:tea}, snack {your:tea}
      4. Answer: {my:chips, your:toast}




Monday, 8 December 2008                                                    24
How do you Link Data?
      RDF (Linking URIs)
             <my:chips> <rdfs:type> <purl:snack>

      SPARQL (Querying)
             SELECT *
             FROM myfood, yourfood
             WHERE { ?recipe <rdfs:type> <purl:recipe> .
             ?recipe <rdfs:type> <my:cat/snack> }

      OWL (Adding Relationships)
             <my:cat/snack> <owl:sameAs> <your:cat/snack>




Monday, 8 December 2008                                     25
Questions?



Monday, 8 December 2008                26

Contenu connexe

Tendances

What's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field APIWhat's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field APIDrupalize.Me
 
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennJavaDayUA
 
An Introduction to Spring Data
An Introduction to Spring DataAn Introduction to Spring Data
An Introduction to Spring DataOliver Gierke
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
Modularized Persistence - B Zsoldos
Modularized Persistence - B ZsoldosModularized Persistence - B Zsoldos
Modularized Persistence - B Zsoldosmfrancis
 
Jpa queries
Jpa queriesJpa queries
Jpa queriesgedoplan
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaAnatole Tresch
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java ConfigurationAnatole Tresch
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)Yurii Kotov
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache TamayaAnatole Tresch
 
2001: JNDI Its all in the Context
2001:  JNDI Its all in the Context2001:  JNDI Its all in the Context
2001: JNDI Its all in the ContextRussell Castagnaro
 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010Hien Luu
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기Arawn Park
 
Error Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, loggingError Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, loggingSteve Maraspin
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightMichael Pustovit
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scalab0ris_1
 

Tendances (20)

What's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field APIWhat's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field API
 
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
 
An Introduction to Spring Data
An Introduction to Spring DataAn Introduction to Spring Data
An Introduction to Spring Data
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
Modularized Persistence - B Zsoldos
Modularized Persistence - B ZsoldosModularized Persistence - B Zsoldos
Modularized Persistence - B Zsoldos
 
Hibernate 18052012
Hibernate 18052012Hibernate 18052012
Hibernate 18052012
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
hibernate
hibernatehibernate
hibernate
 
Jpa queries
Jpa queriesJpa queries
Jpa queries
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java Configuration
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache Tamaya
 
2001: JNDI Its all in the Context
2001:  JNDI Its all in the Context2001:  JNDI Its all in the Context
2001: JNDI Its all in the Context
 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
 
Error Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, loggingError Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, logging
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
 
Phactory
PhactoryPhactory
Phactory
 

Similaire à Creating a Web of Data with Restlet

Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationAlex Henderson
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)Samnang Chhun
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2Jim Driscoll
 
Slice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed PersistenceSlice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed PersistencePinaki Poddar
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitPeter Wilcsinszky
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)Carles Farré
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rulesSrijan Technologies
 
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nicolas Thon
 
Jersey framework
Jersey frameworkJersey framework
Jersey frameworkknight1128
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0Sun-Jin Jang
 

Similaire à Creating a Web of Data with Restlet (20)

REST dojo Comet
REST dojo CometREST dojo Comet
REST dojo Comet
 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST Presentation
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Slice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed PersistenceSlice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed Persistence
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Struts2
Struts2Struts2
Struts2
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
 
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Oredev 2009 JAX-RS
Oredev 2009 JAX-RSOredev 2009 JAX-RS
Oredev 2009 JAX-RS
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0
 

Dernier

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 

Dernier (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Creating a Web of Data with Restlet

  • 1. Creating a Web of Data with Restlet Andrew Newman Monday, 8 December 2008 1
  • 2. REST Architecture Resource Oriented Analysis and Design (ROAD) Stateless Access Where Everything is a Resource Identified by URI With Different Representations Linked Together Monday, 8 December 2008 2
  • 3. Restlet Oveview GWT, Client and Server APIs Standalone, App Servers, Oracle, OSGi, Spring HTTP, SMTP, POP3, JDBC, File Connectors JSON, XML, HTML, Atom Representations Integration with Groovy, JPA, Seam, Struts Hibernate Monday, 8 December 2008 3
  • 4. A little bit of HTTP Verb Action GET Return the entity POST Server create/modify entity PUT Client create/modify entity DELETE X Delete an entity HEAD Entity metadata (not data) OPTIONS ? Methods supported on entity Monday, 8 December 2008 4
  • 5. Restlet Model Uniform Restlet Application Component Redirector Connector Router Filter Finder Client Server Guard Route Transformer Monday, 8 December 2008 5
  • 6. Restlet Model • Reference - Mutable java.net.URI • Request - Client Request • Response - Server Response • MediaType - Mime Types e.g. text/html, application/xml • Resource - Anything with a Reference e.g. video, document, collection • Variant - Metadata about a representation. • Representation - The current state/value of a Resource. Monday, 8 December 2008 6
  • 7. Resource API GET Representation represent(Variant) POST void acceptRepresentation(Representation) PUT void storeRepresentation(Representation) DELETE void removeRepresentations() HEAD Calls GET without stream. OPTIONS Updates Response’s getAllowedMethods Monday, 8 December 2008 7
  • 8. Applications and Components // Create Application for http://localhost/helloWorld Application application = new Application() { public synchronized Restlet createRoot() { Router router = new Router(getContext()); // Attach a resource router.attach(quot;helloWorldquot;, HelloWorldResource.class); return router; } }; // Create the component and attach the application Component component = new Component(); component.getServers().add(Protocol.HTTP); component.getDefaultHost().attach(application); // Start the web server component.start(); Monday, 8 December 2008 8
  • 9. Data and Resources public HelloWorldResource(Context context, Request request, Response response) { super(context, request, response); // Declare all kind of representations supported by the resource getVariants().add(new Variant(MediaType.TEXT_PLAIN)); } // Respond to GET public Representation represent(Variant variant) throws ResourceException { Representation representation = null; // Generate a representation according to the variant media type. if (MediaType.TEXT_PLAIN.equals(variant.getMediaType())) { representation = new StringRepresentation(quot;hello, worldquot;, MediaType.TEXT_PLAIN); } return representation; } Monday, 8 December 2008 9
  • 10. A Bit More HTTP GET /index HTTP/1.1 Host: www.realestate.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: 1.7.12)... Accept: text/xml,application/xml,application/xhtml +xml,text/html;q=0.9,... Accept-Language: us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Monday, 8 December 2008 10
  • 11. Drop the Dot Yes http://realestate.com/house/1 + type No http://realestate.com/house/1.html http://realestate.com/house/1.xml http://realestate.com/house/1.json http://realestate.com/house/1.png Monday, 8 December 2008 11
  • 12. No iPhone Yes http://realestate.com/house/1 + user-agent No http://www.realestate.com/house/1 http://iphone.realestate.com/house/1 http://iphone-v2.realestate.com/house/1 http://n95-8GB-Black.realestate.com/house/1 Monday, 8 December 2008 12
  • 13. Client Side API // GET a resource from uri as a XML DOM. Response response = new Client(Protocol.HTTP).get(uri); DomRepresentation document = response.getEntityAsDom(); // Specify content types. ClientInfo clientInfo = request.getClientInfo(); List<Preference<MediaType>> preferenceList = new ArrayList<Preference<MediaType>>(); preferenceList.add(new Preference<MediaType>(TEXT_XML)); preferenceList.add(new Preference<MediaType>(APPLICATION_XML)); preferenceList.add(new Preference<MediaType>(APPLICATION_XHTML_XML)); preferenceList.add(new Preference<MediaType>(TEXT_HTML, 0.9f)); clientInfo.setAcceptedMediaTypes(preferenceList); // Specify encodings clientInfo.setAcceptedEncodings(Arrays.asList(new Preference<Encoding>(Encoding.GZIP)); // Finally, GET. client.get(uri); Monday, 8 December 2008 13
  • 14. Simple WebDAV Directory Demo See also: http://code.google.com/p/gogoego/ Monday, 8 December 2008 14
  • 15. Restlet and Spring ConfigurableRestletResource <bean id=quot;someResourcequot; class=quot;SomeResourcequot; scope=quot;prototypequot;> <property name=quot;representationTemplatesquot;> <map> <entry key-ref=quot;TEXT_HTMLquot; value-ref=quot;htmlRepquot;/> <entry key-ref=quot;APPLICATION_JSONquot; value-ref=quot;jsonRepquot;/> <entry key-ref=quot;APPLICATION_XMLquot; value-ref=quot;xmlRepquot;/> </map> </property> </bean> Monday, 8 December 2008 15
  • 16. Restlet and Spring FreemarkerRepresentationFactory <bean id=quot;htmlRepquot; class=quot;org.jrdf.query.server.FreemarkerRepresentationFactoryquot;> <property name=quot;templateNamequot; value=quot;dbLocal-html.ftlquot;/> <property name=quot;freemarkerConfigquot; ref=quot;freemarkerConfigquot;/> </bean> dbLocal-html.ftl <html> <head> <title>Query Page -- Database ${database}</title> </head> <body> <h1> Query for database <i>${database}</i> ... Monday, 8 December 2008 16
  • 17. Restlet and Spring SpringRouter <bean id=quot;routerquot; class=quot;org.restlet.ext.spring.SpringRouterquot;> <property name=quot;attachmentsquot;> <map> <entry key=quot;/databasesquot;> <bean class=quot;org.restlet.ext.spring.SpringFinderquot;> <lookup-method name=quot;createResourcequot; bean=quot;listDbResourcequot;/> </bean> </entry> <entry key=quot;/databases/{database}quot;> <bean class=quot;org.restlet.ext.spring.SpringFinderquot;> <lookup-method name=quot;createResourcequot; bean=quot;queryDbResourcequot;/> </bean> </entry> </map> </property> </bean> Monday, 8 December 2008 17
  • 18. Restlet and Spring public Representation represent(Variant variant) { Representation rep = null; try { graphName = (String) getRequest().getAttributes().get(quot;databasequot;); if (getRequest().getResourceRef().hasQuery()) { queryString = getRequest().getResourceRef().getQueryAsForm(). getFirst(quot;queryquot;).getValue(); } if (queryString == null) { rep = queryPageRepresentation(variant); } else { rep = queryResultRepresentation(variant); } getResponse().setStatus(SUCCESS_OK); } catch (Exception e) { getResponse().setStatus(SERVER_ERROR_INTERNAL, e, e.getMessage().replace(quot;nquot;, quot;quot;)); } return rep; } Monday, 8 December 2008 18
  • 19. Linking Data MyFood.Com YourFood recipe recipe ID Desc. Cat. ID Desc. Cat. 1 Chips Snack 1 Toast Snack 2 Ice Water Drink 2 Tea Drink URIs URIs http://myfood.com/recipe/chips http://yourfood.com/recipe/toast http://myfood.com/recipe/water http://yourfood.com/recipe/tea http://myfood.com/cat/snack http://yourfood.com/cat/snack http://myfood.com/cat/drink http://yourfood.com/cat/drink Monday, 8 December 2008 19
  • 20. Linking Data ? MyFood.Com YourFood recipe recipe ID Desc. Cat. ID Desc. Cat. 1 Chips Snack 1 Toast Snack 2 Ice Water Drink 2 Tea Drink URIs URIs http://myfood.com/recipe/chips http://yourfood.com/recipe/toast http://myfood.com/recipe/water http://yourfood.com/recipe/tea http://myfood.com/cat/snack http://yourfood.com/cat/snack http://myfood.com/cat/drink http://yourfood.com/cat/drink Monday, 8 December 2008 20
  • 21. Linking Data http://myfood.com/cat/snack http://yourfood.com/cat/snack IsA IsA http://myfood.com/recipe/chips http://yourfood.com/recipe/toast Monday, 8 December 2008 21
  • 22. Linking Data http://myfood.com/cat/snack isTheS ameA s http://yourfood.com/cat/snack IsA IsA http://myfood.com/recipe/chips http://yourfood.com/recipe/toast Monday, 8 December 2008 22
  • 23. Linking Data http://myfood.com/cat/snack isTheS ameA s http://yourfood.com/cat/snack IsA IsA http://myfood.com/recipe/chips IsA IsA http://yourfood.com/recipe/toast http://purl.org/recipe Monday, 8 December 2008 23
  • 24. Querying the Web User at myFood.Com wants all the snack recipes: 1. Find all http://purl.org/recipe and http://myfood.com/cat/snack recipe {my:chips, my:water}, snack {my:snack} 2. my:snack = your:snack 3. Query YourFood recipe {your:toast, your:tea}, snack {your:tea} 4. Answer: {my:chips, your:toast} Monday, 8 December 2008 24
  • 25. How do you Link Data? RDF (Linking URIs) <my:chips> <rdfs:type> <purl:snack> SPARQL (Querying) SELECT * FROM myfood, yourfood WHERE { ?recipe <rdfs:type> <purl:recipe> . ?recipe <rdfs:type> <my:cat/snack> } OWL (Adding Relationships) <my:cat/snack> <owl:sameAs> <your:cat/snack> Monday, 8 December 2008 25