Git Product home page Git Product logo

jaxrs2study's Introduction

JAX-RS 2.0 Study

To get started with:

  • JSR 339
  • Apache CXF
  • Jersey
  • Apache Wink: latest version is 1.4.0, it's not maintained any more and not recommended

![Mind map](/images/jax-rs 2 mindmap.png)

It will cover:

  • Annotations

    • inject
  • Application

    • getClasses vs getSingletons: former one is to create instances per requests, the latter one is to use single instance for all requests
  • Security: SecurityContext (inject with filed property, or can get it via ContainerRequestContext which user principal is populated with filter or server container configuring with security info)

    • HTTP Basic + Token
    • Role-based access control with annotation
    • OAuth
    • SAML
  • Data binding

    • JacksonJsonProvider
    • JAXB + JacksonJaxbJsonProvider
  • Filter and Interceptor

    • AuthenticationFilter
    • Name binding
    • Priorities

Interceptors share a common API for the server and the client side. Whereas filters are primarily intended to manipulate request and response parameters like HTTP headers, URIs and/or HTTP methods, interceptors are intended to manipulate entities, via manipulating entity input/output streams.

Filters and interceptors can be name-bound. Name binding is a concept that allows to say to a JAX-RS runtime that a specific filter or interceptor will be executed only for a specific resource method. When a filter or an interceptor is limited only to a specific resource method we say that it is name-bound. Filters and interceptors that do not have such a limitation are called global. Filter or interceptor can be assigned to a resource method using the @NameBinding annotation. The annotation is used as meta annotation for other user implemented annotations that are applied to a providers and resource methods. See the following example:

  • Configuration

    • Application: getClasses vs. getSingletons
  • Expires, Cache-Control, Revalidation with Last-Modified & ETag for scaling

    • Expires: timestamp will be present on response header, set it with the ResponseBuilder.expires API
    • Cache-Control: private, public, no-cache, no-store, no-transform, max-age, s-max-age, set it with the ResponseBuilder.cacheControl API
    • Revalidation
      • Last-Modified along with response/If-Modified-Since coming from request, set it with the ResponseBuilder.lastModified API
      • ETag along with response/If-None-Match coming from request: generate EntityTag and validate with the Request.evaluatePreconditions API, no matching then proceed to send new etag back to client with the ResponseBuilder.tag API
    • Concurrency

    If these values do not match the values within the If-Match and If-Unmodified-Since headers sent with the request, evaluatePreconditions() sends back an instance of a ResponseBuilder initialized with the error code 412, “Precondition Failed.” A Response object is built and sent back to the client. If the preconditions are met, the service performs the update and sends back a success code of 204, “No Content.”

  • Asynchronous

    • client invoker: Futures or callbacks?
    • server async response

In general, use futures if you need to join a set of requests you’ve invoked asynchronously. By join, I mean you need to know when each of the requests has finished and you need to perform another task after all the asynchronous requests are complete. For example, maybe you are gathering information from a bunch of different web services to build a larger aggregated document (a mashup). Use callbacks when each invocation is its own distinct unit and you do not have to do any coordination or mashing up.

In 2009, the Servlet 3.0 specification introduced asynchronous HTTP. With the Servlet 3.0 API, you can suspend the current server-side request and have a separate thread, other than the calling thread, handle sending back a response to the client. For a server push app, you could then have a small handful of threads manage sending responses back to polling clients and avoid all the overhead of the “one thread per connection” model.

Server-side async response processing is only meant for a specific small subset of applications. Asynchronous doesn’t necessarily mean automatic scalability. For the typical web app, using server asynchronous response processing will only complicate your code and make it harder to maintain. It may even hurt performance.

  • Client API and Unit Test

    • WebClient with local transport which protocol is lile: local://myapp/resource/...
  • Performance

    • Improvement tips
    • Comparison
  • WADL (Web Application Description Language)

The Web Application Description Language (WADL) is a machine-readable XML description of HTTP-based web services. WADL models the resources provided by a service and the relationships between them. WADL is intended to simplify the reuse of web services that are based on the existing HTTP architecture of the Web. WADL is the REST equivalent of SOAP's Web Services Description Language (WSDL), which can also be used to describe REST web services.

  • Deployment
    • Embedded Jetty: confgiure web app and https
    • Liberty: configure web app, classpath and https
    • WAS: configure web app, classpath and https?

Samples

Apache CXF

It shows: annotations, data binding with JaksonJsonProvider, authentication filter with data binding, unit test with local transport and WebClient, and embedded Jetty with https enabled.

Question: How to make tokens expire? with Guava cache or use another scheduled thread to evict expired tokens?

Apache Wink

Not to recommend using it.

WADL service with Jersey

It's implemented by referring the blog: http://weli.iteye.com/blog/2305096

References

jaxrs2study's People

Watchers

Jianfeng Cai avatar James Cloos avatar

Forkers

jeffreyxqf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.