Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of @Context UriInfo in Spring Rest

I have worked in Jersey and RESTEasy framework earlier and now we will be using Spring Rest for a new project , I don't want to pass all the query params and matrix params as parameters in the method , and usually I would annotate the method with @Context UriInfo and would get all the parameters inside my method in Jersey or RESTEasy Framework for complex parameters.

I would like to know if there is any @Context UriInfo in Spring REST, which is similar to RESTEasy or Jersey Framework. I would like to get all the query params or matrix params and other params if any inside the method instead of passing them as a parameter in the method.

like image 363
Vignesh Avatar asked Jan 09 '16 05:01

Vignesh


People also ask

What is UriInfo in rest?

UriInfo -> Captures path variables and query parameters. SecurityContext -> Provides access to security related information for a request. ResourceContext -> Provides access to instances of resource classes.

What is JAX-RS spring?

JAX-RS is only a specification and it needs a compatible implementation to be used. On the other hand, Spring MVC is a complete framework with REST capabilities. Like JAX-RS, it also provides us with useful annotations to abstract from low-level details.

How do you use UriInfo?

Method SummaryGet the absolute path of the request in the form of a UriBuilder. Get the base URI of the application. Get the base URI of the application in the form of a UriBuilder. Get a read-only list of the currently matched resource class instances.

What is difference between Jersey and spring rest?

Jersey is the JAX-RS API example implementation provided by Sun, while Spring REST is of course Spring's implementation of the same API/JSRs. The major difference is that Spring REST easily integrates into other Spring APIs (if you wish) such as Spring Data Rest.


1 Answers

I did not find any spring class equivalent to UriInfo. But we can take same info from httpservlet request. Suppose, a url is http:localhost:8080/services/test?one=1&two=2, then,

    hsr.getServletContext.getContextPath() gives "/services"
    hsr.getRequestURI() gives "/services/test"
    hsr.getRequestURL() gives complete url "http:localhost:8080/services/test"
    hsr.getQueryString() gives "one=1&two=2"
    hsr.getServletPath() gives "/test"
    hsr.getParameterMap() gives all query strings in a Map as key value pair

You can set and use these values in URIinfo object

like image 57
Kaliappan Avatar answered Nov 02 '22 10:11

Kaliappan