8 encoded String in REST WebService with Apache CXF

I am setting a REST Web Service on a 2.5 Web App on Tomcat 6 using CXF 3.0.2. The webservice receives a POST request with no parameters and returns a JSON String with internationals characters (like é, è, à, ...).

The problem is that the calling application seems to receive the String not encoded in UTF-8. I tried with SoapUI but similar problem with the "RAW View" (the "JSON view" seems OK).

I really don't know what could be the problem. In fact, i don't know if the calling app is not reading in UTF-8 or CXF sends a non UTF-8 encoded response.

Java REST Web Service :

    package test;

    @Path("/TestService")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
    public class TestService {

        @Path("/indicateurs")
        @POST
        public String indicateurs() {
            return "iiérrràr_îttt";
        }
    }

cxf-servlet.xml :


    lt;bean id="testService" class="test.TestService"/>
    <jaxrs:server id="testRestService" address="/TestService">
    <jaxrs:serviceBeans>
    <ref bean="testService"/>
    </jaxrs:serviceBeans>
    <jaxrs:providers>
    <bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    <property name="dropRootElement" value="true" />
    <property name="supportUnwrapped" value="true" />
    </bean>
    </jaxrs:providers>
    </jaxrs:server>

SoapUI JSON View :

    iiérrràr_îttt

SoapUI RAW View :

 
    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Date: Tue, 09 Dec 2014 10:54:52 GMT
    Content-Type: application/json;charset=UTF-8
    Transfer-Encoding: chunked
    Connection: close

    iiérrràr_îttt

I managed to find the issue.

As 'luuksen' said, the Producer was OK.

The calling code is a Java middleware using the json-smart library, with has an issue with UTF-8 : https://code.google.com/p/json-smart/issues/detail?id=48.

链接地址: http://www.djcxy.com/p/45622.html

上一篇: RS请求与JAX

下一篇: REST WebService中的8编码字符串与Apache CXF