You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Olivier Rousseil (JIRA)" <ji...@apache.org> on 2010/04/22 17:21:50 UTC

[jira] Issue Comment Edited: (CXF-2781) Charset encoding other than UTF-8 (as ISO-8859-1) not working

    [ https://issues.apache.org/jira/browse/CXF-2781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12859841#action_12859841 ] 

Olivier Rousseil edited comment on CXF-2781 at 4/22/10 11:20 AM:
-----------------------------------------------------------------

Ok thanks Sergey. With a StringProvider like this :

package provider;
 
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
 
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
 
@Provider
public class StringProvider implements MessageBodyWriter<String> {
 
    public long getSize(String s, Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
        return -1;
    }
 
    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
        return String.class.isAssignableFrom(type);
    }
 
    public void writeTo(String l, Class<?> clazz, Type type, Annotation[] a, 
                        MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) 
        throws IOException {
        os.write(l.getBytes("ISO-8859-1"));
        
    }
}

and 

<jaxrs:server id="helloService" address="/TEST">
  <jaxrs:serviceBeans>
    <bean class="demo.jaxrs.server.HelloService" />
  </jaxrs:serviceBeans>
  <jaxrs:providers>
    <ref bean="stringProvider" />
  </jaxrs:providers>
</jaxrs:server>	 

<bean id="stringProvider" class="provider.StringProvider"/>

in "applicationContext.xml", it 's working fine.

With RESTEasy, no needs of custom provider... That's why I was confused !

      was (Author: oroussei):
    Ok thanks Sergey. With a StringProvider like this :

package provider;
 
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
 
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
 
@Provider
public class StringProvider implements MessageBodyWriter<String> {
 
    public long getSize(String s, Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
        return -1;
    }
 
    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
        return String.class.isAssignableFrom(type);
    }
 
    public void writeTo(String l, Class<?> clazz, Type type, Annotation[] a, 
                        MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) 
        throws IOException {
        os.write(l.getBytes("ISO-8859-1"));
        
    }
}

and 

<jaxrs:server id="helloService" address="/TEST">
  <jaxrs:serviceBeans>
    <bean class="demo.jaxrs.server.HelloService" />
  </jaxrs:serviceBeans>
  <jaxrs:providers>
    <ref bean="stringProvider" />
  </jaxrs:providers>
</jaxrs:server>	 

<bean id="stringProvider" class="provider.StringProvider"/>

in "applicationContext.xml", it working fine.

With RESTEasy, no needs of custom provider... That's why I was confused !
  
> Charset encoding other than UTF-8 (as ISO-8859-1) not working
> -------------------------------------------------------------
>
>                 Key: CXF-2781
>                 URL: https://issues.apache.org/jira/browse/CXF-2781
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.7
>         Environment: Windows XP SP3 - Eclipse 3.5 - Spring - CXFServlet - Tomcat 5.5.12
>            Reporter: Olivier Rousseil
>
> Simple REST service like this :
> HelloService.java
> package demo.jaxrs.server;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
> @Path("/helloservice/")
> public class HelloService {
>     @GET
>     @Path("/hello")
>     @Produces("text/html;charset=ISO-8859-1")
>     public String sayHello() {
>         return "Hello, my name is Félix Agnès";
>     }
> }
> When called (in my environnement  : http://localhost:58010/geoservices/ws/TEST/helloservice/hello) produce :
> HTTP/1.1 200 OK
> Server: Apache-Coyote/1.1
> Date: Thu, 22 Apr 2010 13:44:18 GMT
> Content-Type: text/html;charset=ISO-8859-1
> Content-Length: 31
> Hello, my name is Félix Agnès
> Latin characters like "éèà" are encoded in UTF-8 !!!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.