uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

24.4.5 javax.ws.rs.core.ext.Providers

The javax.ws.rs.core.ext.Providers saves the providers that operate in a deployed Web resource.

The following example describes the usage of javax.ws.rs.core.ext.Providers that is injected into the field of a root resource class:

package com.sample.resources;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
 
//Root resource class
@Path("root")
public class Resource{  
 
  //A field in which the Providers is injected by using the Context annotation
  private @Context Providers providers;
 
  //resource method
  @GET
  public String getValue() {
    //acquire the exception mapping provider from the providers field
    return this.providers.getExceptionMapper(RuntimeException.class);
  }
}

Consider the context root of the Web application (WAR file) containing the exception mapping provider com.sample.providers.EntityProviderReader that can process the root resource class com.sample.resources.Resource and the java.lang.RuntimeException to be example and that the Web application is published on a host named sample.com. In the above example, with the HTTP GET request corresponding to the URL http://sample.com/example/root, first, the javax.ws.rs.core.ext.Providers context is injected into the providers field and then the getValue() method that can process the HTTP GET request is called. Therefore, if you use the getValue() method and acquire the exception mapping provider that can process the java.lang.RuntimeException from the providers field, the com.sample.providers.EntityProviderReader instance is acquired.