Restful Service Jersey 2x charset ISO-8859-9 is not working

320 views Asked by At

I m trying to create a restful webservice using jersey 2.13 API + TOMCAT 7. My aim is to show the directories and files on my computer as a response.

Everything works fine except the Turkish encoding. My HTML response includes Turkish chars. I did everything (added ;charset=ISO-8859-9 to the annotation, added meta stuff with charset,added charset to the response header, added language to the response header etc.) but still my page is full of unknown chars instead of Turkish ones.

I couldnt post an image showing the problem because of my low rep. :S Instead here is a link from my server's response

<a href="http://localhost:8080/TezWebServer/rest/servis/klasor?ad=C://**Görüntü Ä°ÅLEME GENEL">KLASOR:Görüntü Ä°ÅLEME GENEL**</a>

this one should be as

<a href="http://localhost:8080/TezWebServer/rest/servis/klasor?ad=C://**GÖRÜNTÜ İŞLEME GENEL">KLASOR:GÖRÜNTÜ İŞLEME GENEL</a>

The same code is working properly using jersey 1x I think this is a bug :S

@GET
@Path("klasor")
@Produces(MediaType.TEXT_HTML+";charset=ISO-8859-9")
public Response dosyalariGosterHTML(@QueryParam("ad") String klasorAdi){
    if(klasorAdi==null||klasorAdi.equals("")){
        klasorAdi = "C:/";
    }

    StringBuffer sb = new StringBuffer();
    sb.append("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html><head><meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-9'/>
<META HTTP-EQUIV='Content-language' CONTENT='tr'><title>Tez İD</title></head><body>");

        try{
            klasorAdi = text_convert_ters(klasorAdi);

            File folder = new File(klasorAdi);
            File[] listOfFiles = folder.listFiles();

            for (int i = 0; i < listOfFiles.length; i++) {
                if (listOfFiles[i].isFile()) {
                    sb.append("<a href='http://localhost:8080/TezWebServer/rest/servis/dosya?adres="+klasorAdi+"/"+ listOfFiles[i].getName()+"'>DOSYA:"+listOfFiles[i].getName()+"</a><br/>");


                } else if (listOfFiles[i].isDirectory()) {
                    sb.append("<a href='http://localhost:8080/TezWebServer/rest/servis/klasor?ad="+klasorAdi+"/"+ listOfFiles[i].getName()+"'>KLASOR:"+listOfFiles[i].getName()+"</a><br/>");
                }
            }
            sb.append("</body></html>");
    }catch(Exception e){
        e.printStackTrace();
        sb.append("Hata:Belirtilen Yol Geçersiz</body></html>");
    }
    return Response.ok(sb.toString()).language(Locale.getDefault()).header("charset", "ISO-8859-9").build();
}



public String text_convert_ters(String eskiStr)
    {
        String yeniStr = "";
        for(int index = 0; index < eskiStr.length(); index++)
        {
            char tmpStr = eskiStr.charAt(index);
            if(tmpStr == '\360') tmpStr='ğ';
            else if(tmpStr == '\320') tmpStr='Ğ';
            else if(tmpStr == '\375') tmpStr='ı';
            else if(tmpStr == '\335') tmpStr='İ';
            else if(tmpStr == '\366') tmpStr='ö';
            else if(tmpStr == '\326') tmpStr='Ö';
            else if(tmpStr == '\374') tmpStr='ü';
            else if(tmpStr == '\334') tmpStr='Ü';
            else if(tmpStr == '\376') tmpStr='ş';
            else if(tmpStr == '\336') tmpStr='Ş';
            else if(tmpStr == '\347') tmpStr='ç';
            else if(tmpStr == '\307') tmpStr='Ç';
            yeniStr = yeniStr + tmpStr;
        }

        return yeniStr;
    }



 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>TezWebServer</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>/axis2-web/index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>benim.tez.projem.rs.servis</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>*.jws</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>
0

There are 0 answers