users@jersey.java.net

Re: [Jersey] JSR311 1.0 vs 1.1

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 23 Sep 2009 16:53:21 +0200

On Sep 20, 2009, at 9:35 PM, Rabick, Mark A (IS) wrote:

> Thanks again Paul. Sorry for the late response.
>
> Is the fix below that you mention in 1.1.2ea also in 1.0.3.1?

No, it is only in 1.1.2-ea.


> Is 1.1.2ea (JAX-RS 1.1) a superset of 1.0.3.1 (JAX-RS 1.0)?

Yes. JAX-RS 1.1 is fully binary backwards compatible with JAX-RS 1.0.
The changes from JAX-RS 1.0 to JAX-RS 1.1 are minimal w.r.t. API
additions and 1.1 is mostly about integration with other EE 6
technologies like EJB 3.1, Servlet 3.0 and JSR 299/330.

Paul.


>
> --mark
>
> _______________________________________________
> Mark A. Rabick - Software Engineer
> Em: mark.rabick_at_ngc.com
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Tuesday, August 25, 2009 2:25 PM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] Problem with suffixes mapping to media types
>
>
> On Aug 25, 2009, at 9:12 PM, Rabick, Mark A (IS) wrote:
>
>
> Paul, thanks for the reply on the conneg filter stuff but I was
> wondering if you had any ideas why only 2 of my 3 suffixes are being
> mapped to the appropriate media type?
>
>
> The URL:
>
> http://localhost:7001/cnodb/rest/v1/ontology.nt
>
> contains the sub-string "nt" in "ontology, and the algorithm was not
> correctly checking for the last occurrence of "nt".
>
> we have not announced 1.1.2-ea yet (i will do that tomorrow), but it
> is available on the maven repo and and you switch to that things
> should work.
>
> Paul.
>
>
>
> -mark
>
> _______________________________________________
> Mark A. Rabick - Software Engineer
> Em: mark.rabick_at_ngc.com
> From: Rabick, Mark A (IS) [mailto:Mark.Rabick_at_ngc.com]
> Sent: Thursday, August 20, 2009 1:22 PM
> To: users_at_jersey.dev.java.net
> Subject: RE: [Jersey] Problem with suffixes mapping to media types
>
> Any ideas
>
> I have mapped 3 suffixes to media types for content type negotiation
> and only 2 of the 3 are working. The resource is:
>
> @ImplicitProduces
> ({CnodbMediaType.APPLICATION_RDF_XML,MediaType.APPLICATION_XML})
>
> @Singleton
>
> @Path("v1/ontology")
>
> public class OntologyResource extends BaseResource {
>
> private byte[] rdfRepresentation;
>
> private byte[] ntripleRepresentation;
>
> private byte[] n3Representation;
>
>
>
> private @javax.ws.rs.core.Context HttpHeaders httpHeaders;
>
> /**
>
> * No-argument Constructor.
>
> * @throws Exception
>
> * @throws NamingException
>
> */
>
> public OntologyResource() throws NamingException, Exception {
>
> rdfRepresentation = null;
>
> ntripleRepresentation = null;
>
> javax.naming.Context context = new InitialContext();
>
> new CnodbModelDb(context);
>
> }
>
> /**
>
> * Retrieve an RDF representation of the current CNODB
> ontology with optional
>
> * instance data..
>
> * @param getInstanceData If true, return the instance
> data as well.
>
> * @param ignoreCache If true, query ontology from
> database, not the stored version.
>
> *
>
> * @response.representation.200.mediaType application/rdf+xml
>
> * @response.representation.200.doc This is the
> representation returned by default.
>
> *
>
> * @return A response containing the ontology and
> instance data if requested.
>
> */
>
> @GET //_at_Path("rdf")
>
> @Produces(CnodbMediaType.APPLICATION_RDF_XML)
>
> public synchronized Response getRDF(
>
> @QueryParam("ind") @DefaultValue("false")
> Boolean getInstanceData,
>
> @QueryParam("ignoreCache")
> @DefaultValue("false") Boolean ignoreCache)
>
> {
>
> System.out.println("getRDF - getInstanceData=" +
> getInstanceData + " ignoreCache=" + ignoreCache);
>
> // commented out for brevity
>
> }
>
> @GET
>
> @Produces(CnodbMediaType.TEXT_NTRIPLE)
>
> public synchronized Response getNTRIPLE(
>
> @QueryParam("ind") @DefaultValue("false")
> Boolean getInstanceData,
>
> @QueryParam("ignoreCache")
> @DefaultValue("false") Boolean ignoreCache)
>
> {
>
> System.out.println("getNTRIPLE - getInstanceData=" +
> getInstanceData + " ignoreCache=" + ignoreCache);
>
> System.out.println("httpHeaders acceptable media
> types: " + httpHeaders.getAcceptableMediaTypes());
>
> // commented out for brevity
>
> }
>
>
>
> @GET
>
> @Produces(CnodbMediaType.TEXT_N3)
>
> public synchronized Response getN3(
>
> @QueryParam("ind") @DefaultValue("false")
> Boolean getInstanceData,
>
> @QueryParam("ignoreCache")
> @DefaultValue("false") Boolean ignoreCache)
>
> {
>
> System.out.println("getN3 - getInstanceData=" +
> getInstanceData + " ignoreCache=" + ignoreCache);
>
> // commented out for brevity
>
> }
>
> }
>
> The CnodbMediaType-s are from this file:
>
> public class CnodbMediaType {
>
>
>
> public static final String TEXT_N3 = "text/n3";
>
> public static final MediaType TEXT_N3_TYPE = new
> MediaType("text","n3");
>
> public final static String APPLICATION_RDF_XML =
> "application/rdf+xml";
>
> public final static MediaType APPLICATION_RDF_XML_TYPE = new
> MediaType("application","rdf+xml");
>
> public static final String TEXT_NTRIPLE = "text/ntriple";
>
> public static final MediaType TEXT_NTRIPLE_TYPE = new
> MediaType("text","ntriple");
>
> }
>
> My Package resource configuration file is mapping the extension
> “rdf” to application/rdf+xml, “nt” to text/ntriple and“n3” to text/
> n3 as follows:
>
> public class CnodbRestResourceConfig extends PackagesResourceConfig {
>
> /**
>
> * This constructor defines the root package for the Jersey
> runtime
>
> * to use to find resource end-points.
>
> */
>
> public CnodbRestResourceConfig() {
>
> super("mil.cnodb.rs");
>
> }
>
>
>
> /**
>
> * This method returns the current media type mappings that
> translate a
>
> * file extension on a URI into a desired {_at_link MediaType}.
>
> * @return The mappings from extension to media
> type.
>
> *
>
> * @see
> com.sun.jersey.api.core.DefaultResourceConfig#getMediaTypeMappings()
>
> */
>
> @Override
>
> public Map<String, MediaType> getMediaTypeMappings() {
>
> Map<String, MediaType> m = new HashMap<String, MediaType>();
>
> m.put("xml", MediaType.APPLICATION_XML_TYPE);
>
> m.put("json", MediaType.APPLICATION_JSON_TYPE);
>
> m.put("html", MediaType.TEXT_HTML_TYPE);
>
> m.put("n3", CnodbMediaType.TEXT_N3_TYPE);
>
> m.put("rdf", CnodbMediaType.APPLICATION_RDF_XML_TYPE);
>
> m.put("nt", CnodbMediaType.TEXT_NTRIPLE_TYPE);
>
> return m;
>
> }
>
> }
>
> If I specify a URL: http://localhost:7001/cnodb/rest/v1/
> ontology.rdf or http://localhost:7001/cnodb/rest/v1/ontology.n3the
> appropriate resource methods are called but if I specify http://localhost:7001/cnodb/rest/v1/ontology.nt
> , I don’t get a response and the resource method getNTRIPLE(…) doea
> not appear to get called. Is there a way I can intercept the HTTP
> request to view the ‘accept’ header and see if in fact the .nt
> suffix is being mapped properly?
>
> --mark
>
> _______________________________________________
> Mark A. Rabick
> Software Engineer
> Northrop Grumman - Integrated Mission Systems (IS/DSD/IMS)
> 3200 Samson Way
> Bellevue, NE 68123
> Em: mark.rabick_at_ngc.com
> Remember PFC Ross A. McGinnis...
> http://www.army.mil/medalofhonor/McGinnis/index.html
> ... MA2 Michael A. Monsoor, Lt. Michael P. Murphy, Cpl. Jason
> Dunham, SFC Paul Ray Smith and the rest...
> http://www.cmohs.org/recipients/most_recent.htm
>
>