On Feb 26, 2009, at 5:51 PM, Rabick, Mark A (MS) wrote:
>> On Feb 25, 2009, at 6:08 PM, Rabick, Mark A (MS) wrote:
>>
>>>> As far as the URI-based content negotiation, are you suggesting I
>>>> could couple the URI 'versioning' (../v1/...) in addition
>> to custom/
>>>> specific media types when the client can't send an "Accept:
>>>> application/foo-vi?
>>>>
>>>
>>> I think a suffix is better e.g. ".foo-v1" or ".foo-v2". Then it is
>>> easier to use existing Jersey functionality or write your
>> own filter.
>>>
>>> Are you talking about a suffix in a URI fragment? For example, if I
>>> have 2 versions of 'Foo' JAXB objects.
>>>
>>
>> A suffix at the end of the URI path, but not part of the application
>> and @Path.
>
> Not part of the application I assume would be not in the 'context-
> root'
> of the web app. Sorry to belabor this but how can a suffix be at the
> end of the URI path, but NOT Included in an @Path?
> Can you give an example?
Here is a specific example from the camel web component:
https://svn.apache.org/repos/asf/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/util/CamelResourceConfig.java
public class CamelResourceConfig extends PackagesResourceConfig {
public CamelResourceConfig() {
super(createProperties());
}
protected static Map<String, Object> createProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PackagesResourceConfig.PROPERTY_PACKAGES,
"org.apache.camel.web");
WadlGeneratorConfig config = WadlGeneratorConfig
.generator(WadlGeneratorApplicationDoc.class)
.prop("applicationDocsFile", "classpath:/application-
doc.xml")
.generator(WadlGeneratorGrammarsSupport.class)
.prop("grammarsFile", "classpath:/application-
grammars.xml")
.generator(WadlGeneratorResourceDocSupport.class)
.prop("resourceDocFile", "classpath:/resourcedoc.xml")
.build();
properties.put(ResourceConfig.PROPERTY_WADL_GENERATOR_CONFIG,
config);
return properties;
}
public Map<String, MediaType> getMediaTypeMappings() {
Map<String, MediaType> m = new HashMap<String, MediaType>();
m.put("html", MediaType.TEXT_HTML_TYPE);
m.put("xml", MediaType.APPLICATION_XML_TYPE);
m.put("json", MediaType.APPLICATION_JSON_TYPE);
m.put("dot", MediaType.valueOf(Constants.DOT_MIMETYPE));
return m;
}
}
See the method "getMediaTypeMappings". Notice that it declares a
mapping of suffix to media type.
Thus whenever there is say a request URI:
http://localhost:8080/path/foo.html
Jersey will modify the request URI to be:
http://localhost:8080/path/foo
and modify the Accept header to be:
Accept: text/html
The above modifications will occur *before* Jersey processes the
request and dispatches to a methods on a resource class. It is
essentially a request filter.
Hope that helps,
Paul.
>
>
>
>>> Ie. http://host:8080/fooapplication/foo.foo-v1/
>>>
>>> public class FooV1Resource {
>>>
>>> @GET @Path("/foo.foo-v1/{id}")
>>> @Produces("application/foo-v1")
>>> public FooV1(String @PathParam("id") String fooId) {
>>>
>>> FooV2 foo2 = FooDatabase.getFooById(fooId);
>>> FooV1 foo1 = convertFoo2ToFoo1(foo2)
>>> return foo1;
>>> }
>>> }
>>>
>>> Ie. http://host:8080/fooapplication/foo.foo-v2/
>>>
>>> public class FooV2Resource {
>>>
>>> @GET @Path("/foo.foo-v2/{id}")
>>> @Produces("application/foo-v2")
>>> public FooV2(String @PathParam("id") String fooId) {
>>> FooV2 foo2 = FooDatabase.getFooById(fooId);
>>> return foo2;
>>> }
>>> }
>>>
>>> With the appropriate ContextResolvers based on the media types, of
>>> course...
>>>
>>> What 'existing Jersey functionality' are you referring to that
>>> suffixes would help with?
>>>
>>
>> See:
>>
>>
> https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-
> 1.0.2/api/jersey/com/sun/jersey/api/core/
> ResourceConfig.html#getMediaTyp
> eMappings()
>>
>> Paul.
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>