Paul Sandoz wrote:
Hi,
Perhaps there are other ways we can improve this as well.
e.g. @Produces on a template processor?
Template Processor can be used to generate multiple formats html, json,
etc so it's probably not a good idea.
Open to suggestions!
Paul.
On Apr 2, 2009, at 9:51 AM, Paul Sandoz wrote:
Hi,
Are you using @ImplicitProduces ? and implicit views?
I am using bookstore example from the trunk. Adding the
DummyTemplateProcessor is the only modification of the example.
Bookstore already contains @ImplicitProduces("text/html;qs=5") but it
doesn't seem to produce correct headers.
IIRC the accept header sent by Safari (or Chrome?) is such that
text/xml is the most acceptable.
Yes this is accept header I am getting from Chrome:
Accept =
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
You need to use @ImplicitProduces to ensure that text/html or whatever
is required is the most acceptable.
For example:
@ImplicitProduces("text/html;qs=5")
the "qs" value will be multiplied by the 'q' value in the Accept header
and the result will be used to sort media types to find the most
acceptable one with the highest result.
If you are using explicit views for everything (HTML and XML) then you
will need to utilize a filter to modify the accept header and change
the order of the media types so that the HTML media type is the most
preferred. Which should also work if you do not want to use the
@ImplicitProduces annotation.
As a workaround I am currently using a filter that modifies Accept
headers of request and if it contains text/html then it will move it to
the front. But I would prefer if it works without this workaround
filter.
Paul.
On Apr 2, 2009, at 7:54 AM, Dusan Hornik wrote:
Hello
I am trying to use Jersey and velocity template processor to render the
vm pages.
My problem is that the content-type I am getting in response is
text/xml for Webkit browsers (Safari, Chrome).
To reproduce this I created DummTemplateProcessor class in bookstore
1.0.3-SNAPSHOT
---
@Provider
public class DummyTemplateProcessor implements TemplateProcessor
{
public String resolve(final String name)
{
return name;
}
public void writeTo(final String fullyQualifedName, final Object model,
final OutputStream out) throws IOException
{
final DataOutputStream dataOutputStream = new
DataOutputStream(out);
dataOutputStream.writeBytes("<html><body>"+fullyQualifedName
+ " <br></body></html>");
}
}
---
Accessing http://localhost:8080/bookstore/anystring from webkit browser
will return "<html><body>anystring
<br></body></html>" with content type text/xml.
James Strachan wrote:
2009/2/5 Paul Sandoz
<Paul.Sandoz@sun.com>:
On Feb 4, 2009, at 6:45 PM, James
Strachan wrote:
Its much less essential, but
supporting the nicer new MIME strings on
@Produces would be great too - so you can use a single constant in
your code to refer to a set of MIME types (e.g. application/xml,
text/xml and application/json for example) to avoid having to cut and
paste a String[] expression in each method using the @Produces
annotation.
I've raised an issue for this so we don't forget - but its more a case
of making things more consistent and DRY, so way less important than
support in @ImplicitProduces :)
https://jersey.dev.java.net/issues/show_bug.cgi?id=202
Thanks, for now i am not implementing proposed JAX-RS 1.1 features
because
they have yet to be approved. Once approved i will start implementing
such
features in earnest!
Cool no worries! Just wanted to pop a test case in the issue tracker
before I forgot.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@jersey.dev.java.net
For additional commands, e-mail: users-help@jersey.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@jersey.dev.java.net
For additional commands, e-mail: users-help@jersey.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@jersey.dev.java.net
For additional commands, e-mail: users-help@jersey.dev.java.net