¿Cómo puedo obtener todos los parámetros de consulta en Jersey JaxRS?
Estoy construyendo un servicio web genérico y necesito tomar todos los parámetros de consulta en una cadena para analizarlos más tarde. ¿Cómo puedo hacer esto?
81
Author: Paul Bellora, 2011-04-19
2 answers
Puede acceder a un solo parámetro a través de @QueryParam("name")
o a todos los parámetros a través del contexto:
@POST
public Response postSomething(@QueryParam("name") String name, @Context UriInfo uriInfo, String content) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
String nameParam = queryParams.getFirst("name");
}
La clave es la @Context
anotación jax-rs , que se puede usar para acceder:
UriInfo, Request, HttpHeaders, SecurityContext, Proveedores
145
Author: hisdrewness,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-19 15:30:14
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-19 15:30:14
La parte de consulta sin analizar del URI de solicitud se puede obtener desde el objeto UriInfo
:
@GET
public Representation get(@Context UriInfo uriInfo) {
String query = uriInfo.getRequestUri().getQuery();
...
}
32
Author: glerup,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-29 09:31:04
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-29 09:31:04