Hi,
The problem is "ontology" contains "nt" and String.indexOf is being
utilized instead of String.lastIndexOf. A silly bug that i will fix.
Note that this processing occurs after the request filters have been
processed. What i need to do is turn this functionality into a proper
filter and allow developers to utilize that directly or use the
settings in ResourceConfig (if a developer has already added such a
filter the resource config settings are ignored).
Paul.
On Aug 19, 2009, at 7:58 PM, Rabick, Mark A (IS) wrote:
> 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.n3 the
> 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
>
>