Resource Methods can now produce multiple content-types

2 views
Skip to first unread message

Daniel Worhtington-Bodart

unread,
May 13, 2011, 2:30:47 PM5/13/11
to utterlyidle
This works for both Annotations and DSL

@Path("text")
public static class GetsWithMultipleMimeTypes {
@GET
@Produces({"text/plain", "text/xml"})
public String get() {
return "<xml/>";
}
}

or

application.add(get("text").
produces("text/plain").produces("text/xml").
resource(method(on(Some.class).someMethod())));

Matt Savage

unread,
May 15, 2011, 12:15:05 AM5/15/11
to utter...@googlegroups.com
Sweet!

Daniel Worhtington-Bodart

unread,
May 26, 2011, 9:52:41 AM5/26/11
to utterlyidle
Had to make a slight change to the DSL to support produces and consume
correctly, please specify them in a single call NOT by chaining the
mothods. So as follows

@Test
public void supportsProduces() throws Exception {
TestApplication application = new TestApplication();
application.add(get("/bar").produces("text/html", "text/
xml").resource(method(on(Bar.class).hello())));
assertThat(application.responseAsString(RequestBuilder.get("/
bar").accepting("text/html")), is("Hello"));
assertThat(application.responseAsString(RequestBuilder.get("/
bar").accepting("text/xml")), is("Hello"));
assertThat(application.handle(RequestBuilder.get("/
bar").accepting("text/plain")).status(), is(Status.NOT_ACCEPTABLE));
Reply all
Reply to author
Forward
0 new messages