users@jersey.java.net

Re: [Jersey] .xml extension is stripped?

From: Charles Brooking <public+java_at_charlie.brooking.id.au>
Date: Wed, 09 Dec 2009 21:41:46 +1000

Paul Sandoz wrote:
> Are you using the Jersey URI content negotiation feature, where
> suffixes are mapped to media types, for example "xml" -> "text/xml" ?
>
> If so Jersey will remove the ".xml" in such cases from the path.

If that is indeed the case, you can use a method like this for getting
the name:

    // Useful because file extensions are removed by Jersey due to
    // our use of media type mappings (eg .xml to application/xml)
    public static String getFileName(UriInfo uriInfo) {
        List<PathSegment> segments = uriInfo.getPathSegments();
        return segments.get(segments.size() - 1).getPath();
    }


Later
Charlie