views:

1031

answers:

3

Hi, I'm using Jetty to test a webservice we have and I am trying to get it to respond with no charset under the content-type header.

Does anyone know how to do this?

I've tried intercepting the Response and setting the CharacterEncoding to null or "" but that gives Exceptions.

I am using Jetty 6.1.6.

A: 

The charset is very useful info. Instead of trying to force a good product (Jetty) to do the wrong thing I would rather try to teach the consumer of the service to do the right thing (recognize and honor charset).

Mihai Nita
Unfortunatley the consumer is Microsoft :(
PintSizedCat
+1  A: 

I think that this not a matter of which servlet container you use, but what you do with the response inside your servlet. If you set your character encoding by calling ServletResponse's setContentType (2.3) or setCharacterEncoding (2.4, 2.5) with parameter null or "" it should work (didn't try myself). But be sure to call the methods named above before calling getWriter, otherwise setting the encoding will have no effect!

Kai
Unfortunatley, setting the CharacterEncoding doesn't work like that, if it's null then iso-8859-1 is used by default. And if the contentType is set to plain old text/xml iso-8859-1 is used as default as well. :(
PintSizedCat
Sorry, as I said: Didin't try myself. What about setCharacterEncoding("")?
Kai
+1  A: 

I tried it my self now, but I must admit, my jetty is a very old one (4.2., but does everything the way I need it). I compared it to tomcat (4.1.29, old too). I checked the content type with the following code:

URL tomcatUrl = new URL("http://localhost:18080/ppi/jobperform/headertest")//tomcat;
URLConnection tconnect = tomcatUrl.openConnection();
System.out.println("tomcat: " + tconnect.getContentType());


URL jettyUrl = new URL("http://localhost:13818/ppi/jobperform/headertest")//jetty;
URLConnection jconnect = jettyUrl.openConnection();
System.out.println("jetty: " + jconnect.getContentType());

And the result was as follows:

Servlet code:

    response.setContentType("");
    response.getWriter().write("Return");

=>
tomcat: ;charset=ISO-8859-1
jetty:

Servlet code:

     response.setContentType("text/plain");
     response.getWriter().write("Return");

=>
tomcat: text/plain;charset=ISO-8859-1
jetty: text/plain

Servlet code:

response.setContentType("text/plain;charset=UTF-8");
response.getWriter().write("Return");

=>
tomcat: text/plain;charset=UTF-8
jetty: text/plain;charset=UTF-8

So it looks as if the older jetty does exactly what you want, while tomcat does what you got from the newer jetty.

Kai
I'll actually have to try something out you've given me an idea for. Thanks +1
PintSizedCat