rest - Restful Service Jersey 2x charset ISO-8859-9 is not working -
i m trying create restful webservice using jersey 2.13 api + tomcat 7. aim show directories , files on computer response.
everything works fine except turkish encoding. html response includes turkish chars. did (added ;charset=iso-8859-9 annotation, added meta stuff charset,added charset response header, added language response header etc.) still page full of unknown chars instead of turkish ones.
i couldnt post image showing problem because of low rep. :s instead here link 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 1 should 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 working using jersey 1x think 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(); (int = 0; < 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>
Comments
Post a Comment