JAX-WS
XML messages that follo SOAP (Simple Object Access Protocol) standard
JAX-RS Representational State Transfer (RESTful) web services
Project Jersey - reference implementation
Suitable when
service completely stateless
caching can be leveraged for performance, for GET
producer/consumer have mutual understanding of the context and content (service has no descriptor)
some provider also provide an API
bandwidth & overhead important
....
data & functions are considered resources
resources accessed using URIs
interface
PUT - create
GET - read
POST - replace / transfer new state
DEL - delete
resource message format
can be in a variety of formats
HTML, XML, text, PDF, JPEG, JSON....
stateful through links
stateful interactions are based on concept of state transfer
techniques
URI rewriting
cookies
hidden form fields
state embedded in response
Root resource class
POJO, annotated with @Path or a request method designator (@GET etc)
annotations are runtime
@Path
a relative URI : /helloworld
can use variable : /helloworld/{username}
used in method: @GET... public String getUser(@PathParam("username") String userName) {
@Path("users/{username: [a-zA-Z][a-zA-Z_0-9]*}") // specify URI format
if not, 404 returns
@GET
@POST
@PUT
@DELETE
@HEAD
@PathParam
parameter, extracted from request URI
name correspond to {same_name} in @Path
see example above
@QueryParam
extracted from URI query parameters
@Consumes
MIME media types that a resource can consume
@Produces
MIME a resource can produce
@Provider
related to anything to the runtime, such as header, status code, etc.
@ApplicationPath
URL mapping for the application, as the base URI for all resource URIs (@Path)
only applicable to a subclass of javax.ws.rs.core.Application
@Context
defined by JAX-RS specification standard types can be injected
best to check implementation what can be injected