Java Reference
In-Depth Information
Listing 8.9. JSON Bid DTO encoding
{
"@bidId":"10",
"bidDate":"2012-05-15T21:52:58.771-04:00",
"bidPrice":"10.0",
"itemId":"45",
"bidderId":"77"
}
If you attempt to run this code, the JAX-RS implementation will most likely complain
that it doesn't know how to instantiate BidServiceRS , which is an interface. To asso-
ciate the stateless session bean with the service, you'll need to implement a javax.ws
.rs.core.Application and return instances for all JAX-RS annotated interfaces.
The Application instance, shown in the next listing, is then registered with the JAX-RS
servlet in web.xml (not shown). This will work for the reference implementation Metro,
but other JAX-RS implementations may have different mechanisms.
Listing 8.10. Configuring JAX-RS interface instances
public class SystemInit extends Application {
public Set<Class<?>> getClasses() {
return Collections.emptySet();
}
public Set<Object> getSingletons() {
Set<Object> classes = new HashSet<Object>();
try {
InitialContext ctx = new InitialContext();
Object bidServiceRS =
ctx.lookup("java:global/WebServiceExperiment/BidService");
classes.add(bidServiceRS);
} catch (Throwable t) {
t.printStackTrace();
}
return classes;
}
}
Now that you've seen a basic example of a JAX-RS service, let's review the annotations in
more depth.
Search WWH ::




Custom Search