uCosminexus Application Server, Web Service Development Guide

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

24.4.1 javax.ws.rs.core.UriInfo

The javax.ws.rs.core.UriInfo contains each component (query parameter or matrix parameter) that configures a URI and provides information about each HTTP request. Note that you can acquire the post-normalization information by using each method of the javax.ws.rs.core.UriInfo context.

The following example shows the usage of javax.ws.rs.core.UriInfo that is injected in the fields 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.core.UriInfo;
 
//Root resource class
@Path("/root")
public class Resource {
  //A field in which the UriInfo is injected by using the Context annotation
  private @Context UriInfo uriInfo;
 
  //Resource method
  @GET
  public String getValue() {
    String value = this.uriInfo.getQueryParameters().getFirst("query");
    return value;
  }
}

Consider the context root of the Web application (WAR file) containing the root resource class com.sample.resources.Resource to be example, and that the Web application is published on a host named sample.com. In this example, with the HTTP GET request corresponding to the URL , first, the javax.ws.rs.core.UriInfo context is injected into the uriInfo field and then the getValue() method that can process the HTTP GET request is called. Therefore, if you acquire the query parameter query from the uriInfo field by using the getValue() method, the value 10 is acquired.