Hi Jo,
Jo Størset wrote:
>
> Den 15. mai. 2008 kl. 15.54 skrev Marc Hadley:
>
>> On May 15, 2008, at 8:13 AM, Jo Størset wrote:
>>>
>>> I wan't to serve text/html by default to browsers, but also be able
>>> to deliver application/xml on the same url,
>>> is there any way to achieve this with jersey?
>>>
>> If you are prepared to relax the same url constraint a little you
>> could use URL-based conneg such that:
>>
>> someuri.html => text/html
>> someuri.xml => application/xml
>>
>> This can be set up globally using the application configuration and
>> you only to implement a resource class with @Path("someuri") and have
>> methods that return HTML and XML.
>
> Maybe a dumb question, late friday afternoon, but what's the easiest way
> to configure this?
>
At the moment you need to create your own ResourceConfig (or
ApplicationConfig class), for example:
import com.sun.ws.rest.api.core.ClasspathResourceConfig;
import java.util.Map;
import javax.ws.rs.core.MediaType;
public class Config extends ClasspathResourceConfig {
public Config(Map<String, Object> props) {
super(props);
getMediaTypeMappings().put("txt",
new MediaType("text", "plain"));
}
}
The 311-EG are still sorting out the URI building aspects related to URI
conneg to avoid having to modify URI building code when enabling such a
feature.
We need some servlet init-params as well for this...
Paul.
> By the way, servlet filter and a custom MessageBodyWriter worked as
> expected. I think I'll use a servlet filter for now, so then I need the
> option of an explicit url for the xml variant, and thought I'd try this
> mechanism.
>
> Jo
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109