You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Javier Delgadillo <jd...@esri.com> on 2012/11/20 18:13:08 UTC

Getting the extension from the original request is case of .xml and .json

All,

I have the following method in my JAX-RS service implementation:

  @GET
  @Path("/{path:.*}")
  public Response doGet( @PathParam("path") String path, @Context UriInfo info )

If someone issues a GET /foo.xml, in path I get the value "foo".  How do I figure out if the original request had a .xml suffix (or .json for that matter as it exhibits the same behavior)?

--
Javier Delgadillo
Esri / Implementation Services
(909) 793-2853 x1068


Re: Getting the extension from the original request is case of .xml and .json

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
On 20/11/12 17:13, Javier Delgadillo wrote:
> All,
>
> I have the following method in my JAX-RS service implementation:
>
>    @GET
>    @Path("/{path:.*}")
>    public Response doGet( @PathParam("path") String path, @Context UriInfo info )
>
> If someone issues a GET /foo.xml, in path I get the value "foo".  How do I figure out if the original request had a .xml suffix (or .json for that matter as it exhibits the same behavior)?

Perhaps the simpler option is to basically add

@Produces({"application/xml", "application/json" })

and let the runtime and providers manage the response accordingly.
If you do need to know what the extension was, try injecting HttpHeaders 
and get the value of Accept from there, if it is application/json then 
it had a ".json" extension, etc.

Finally, you can get HttpServletContext injected - this will also show 
the original request URI

HTH, Sergey

>
> --
> Javier Delgadillo
> Esri / Implementation Services
> (909) 793-2853 x1068
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com