====== Glassfish Debugging, Caching, HATEOAS, RESTEasy ====== ===== Glassfish application debugging ===== See how to debug an app on Glassfish: [[https://docs.oracle.com/cd/E19798-01/821-1752/beafc/index.html|Glassfish Application Debug]] [[https://www.jetbrains.com/idea/help/creating-run-debug-configuration-for-application-server.html|IntelliJ Tutorial]] ===== RESTEasy ===== Another JAX-RS implementation except Jersey JBoss: http://www.jboss.org/resteasy Uses the same API and package //javax.ws.rs.*// Simple dependencies with JSON for Maven: org.jboss.resteasy resteasy-jaxrs 2.2.1.GA org.jboss.resteasy resteasy-jackson-provider 2.2.1.GA JBOSS_NEXUS http://repository.jboss.org/nexus/content/groups/public ===== REST architecture constraints ===== * Client-Server * Stateless * Cacheable * Layered system * Code on demand (optional) * Uniform interface Talk on the topic given by doc. Ing. Tomáš Vitvar, Ph.D (FIT): {{:courses:a4m36aos:cviceni:lecture8.pdf|HATEOAS-Vitvar}} ==== Caching ==== === HTTP Headers Cache-Control, Last-Modified, ETag, If-Modified-Since, If-None-Match === == Cache-Control == Defines caching setting for client, proxy * **private** proxy can't cache, client can * **public** both client and proxy can cache * **no-cache** should not be cached * **no-store** cache should not be persistent * **no-transform** no data transformation (compression) * **max-age** cache validity * **s-maxage** cache validity for proxy == Last-Modified == Response header, defines when the resource was last modified. == If-Modified-Since == Request header, defines that the resource returns ok (200), if modified since the given date, 304 otherwise. == ETag == Response header, defines the tag (hash) of the returned resource. == If-None-Match == Request header, defines, that the resource should be returned if the tag was modified, otherwise returns 304 === Example === {{:courses:a4m36aos:cviceni:caching.zip|caching.zip}} === Concurrency Control === Lze možné tyto caching headers použít i pro Concurrency Control? == If-Unmodified-Since == Request header (for Last-Modified response header) - if holds, 200 / 204, otherwise 412 Precondition Failed == If-Match == Request header (for ETag response header) - if holds, 200 / 204, otherwise 412 Precondition Failed ==== HATEOAS ==== **Hypertext as the Engine for Application State** * How is the state of the stateful application stored? * How can we achieve the same behavior in stateless application? HATEOAS - using links and headers we can store the state of the application. === Stateless ordering system design === Download the RESTEasy project: {{:courses:a4m36aos:cviceni:hateoas.zip|HATEOAS}} Resources: * **POST /orders** Creates a new order and returns URI of the order in the Location header * **GET /orders/id** Returns an order with given ID * **POST /orders/id {"name":"car"}** Creates a new item in the order * **GET /orders/id/itemId** Returns an item of the order with given ID * **PUT /orders/id/itemId {"name":"car"}** Modifies the item in the order * **DELETE /orders/id/itemId** Deletes item of the order with given ID.