cancel
Showing results for 
Search instead for 
Did you mean: 

Problems using special characters (á,é,ñ...)

igomez
Champ on-the-rise
Champ on-the-rise
Hi.

I have a Java app which create new people and communties throught Alfresco WebScripts.

But I have a problem with the encoding because when I insert some special characters (á, é, í, ñ, Ü, ö…) Alfresco get them like ������.

This is my code (add person):

      
String alfrescoUser = "usr0000000123";
String alfrescoFirstName = "José Miguel";
String alfrescoLastName = "Español";
String alfrescoEmail = "pruebas@mail_pruebas123.com";
      
JSONObject personaJSON = new JSONObject();
personaJSON.put("userName", alfrescoUser);
personaJSON.put("firstName", alfrescoFirstName);
personaJSON.put("lastName", alfrescoLastName);
personaJSON.put("email", alfrescoEmail);
      
postRequest = new HttpPost("http://'+ host + ":" + port + "/alfresco/service/api/people?alf_ticket=" + alfTicket);

input = new StringEntity(personaJSON.toString());
input.setContentType("application/json; charset=UTF-8");
input.setContentEncoding("UTF-8");
postRequest.setHeader("Content-Type","application/json; charset=UTF-8");
postRequest.setEntity(input);
response = httpClient.execute(postRequest);

I tried the following solutions but none of them have worked.


1- File setenv.bat in tomcat/bin:


set JAVA_HOME=C:\Alfresco\java               
set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8 -Djava.file.encoding=UTF-8 -Duser.languaje=es -Duser.region=ES -XX:PermSize=256m
set CATALINA_OPTS=%CATALINA_OPTS% -Dfile.encoding="UTF-8"

2- File tomcat/conf/web.xml:
    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>fileEncoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
          <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

3- File tomcat/conf/server.xml:

    <Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1" 
               connectionTimeout="20000"
               redirectPort="8443" />

I put some traces in my Java code and the output data are ok:

Datos de la persona : {"password":"nadadenada","userName":"usuario_pruebas04","email":"pruebas@mail_pruebas123.com","firstName":"Usuario","lastName":"Pruebás"}Codigo: 200

But the response is not ok (lastName is Prueb\ufffds instead of Pruebá)

Respuesta del servidor …. 

<< Response: HTTP/1.1 200 OK
{
   "url": "\/alfresco\/service\/api\/person\/usuario_pruebas06",
   "userName": "usuario_pruebas06",
   "enabled": true,
   "firstName": "Usuario",
   "lastName": "Prueb\ufffds",
   "jobtitle": null,
   "organization": null,
   "location": null,
   "telephone": null,
   "mobile": null,
   "email": "pruebas@mail_pruebas123.com",
   "companyaddress1": null,
   "companyaddress2": null,
   "companyaddress3": null,
   "companypostcode": null,
   "companytelephone": null,
   "companyfax": null,
   "companyemail": null,
   "skype": null,
   "instantmsg": null,
   "userStatus": null,
   "userStatusTime": null,
   "googleusername": null,
   "quota": -1,
   "sizeCurrent": 0,
   "emailFeedDisabled": false,
   "persondescription": null
}

Some ideas???

Many thanks.
9 REPLIES 9

mrogers
Star Contributor
Star Contributor
The response does not seem to match the parameters e.g. first name is Jose rather than "Usario"

Assuming that was just a posting error. 

In general JSON responses can either be in a particular character set or the characters can be encoded.   Looks like your response may be super encoded.   What is actually created on Alfresco?

igomez
Champ on-the-rise
Champ on-the-rise
Yes, sorry, just a post error Smiley Happy

I tried again with this data:

      
String alfrescoUser = "usr_001";
String alfrescoFirstName = "María";
String alfrescoLastName = "López";
String alfrescoEmail = "pruebas@mail_pruebas123.com";
String alfrescoPassword = "———";

JSON:
 {"password":"———","userName":"usr_001","email":"pruebas@mail_pruebas123.com","firstName":"María","lastName":"López"}

Response:
{
   "url": "\/alfresco\/service\/api\/person\/usr_001",
   "userName": "usr_001",
   "enabled": true,
   "firstName": "Mar\ufffda",
   "lastName": "L\ufffdpez",
   "jobtitle": null,
   "organization": null,
   "location": null,
   "telephone": null,
   "mobile": null,
   "email": "pruebas@mail_pruebas123.com",
   "companyaddress1": null,
   "companyaddress2": null,
   "companyaddress3": null,
   "companypostcode": null,
   "companytelephone": null,
   "companyfax": null,
   "companyemail": null,
   "skype": null,
   "instantmsg": null,
   "userStatus": null,
   "userStatusTime": null,
   "googleusername": null,
   "quota": -1,
   "sizeCurrent": 0,
   "emailFeedDisabled": false,
   "persondescription": null
}

Into Alfresco the user continues with bad character encoding:
Activada
   
Mar�a L�pez
   
usr_001
   
   
pruebas@mail_pruebas123.com

igomez
Champ on-the-rise
Champ on-the-rise
I'm trying to load users with a Firefox Extension called "Poster" that make POST, GET, PUT petitions with your desired data.

I put the same data that I put in mi Java code ({"password":"welcome","userName":"usuario_pruebas06","email":"pruebas@mail_pruebas123.com","firstName":"Usuario","lastName":"Pruebás"}) and, in this case, the data are ok.

So I think that my problem is in my Java code or something, but I don't know where because I put UTF-8 in every headers…


Many thanks for your time.

mrogers
Star Contributor
Star Contributor
I suspect that personaJSON.put("userName", alfrescoUser);
has not actually written UTF-8.

igomez
Champ on-the-rise
Champ on-the-rise
I'm doing some tests to detect the problem…

So in Eclipse, in "Run configurations" I put the encoding in UTF-8, in the VM Arguments I put -Dfile.encoding=UTF-8 and the problem still persists.

I'm trying to covert the string persona to UTF-8 but nothing happens

      
postRequest.setHeader("Content-Type","application/json; charset=UTF-8");
postRequest = new HttpPost("http://'+ host + ":" + port + "/alfresco/service/api/people?alf_ticket=" + finder.getValue());
String persona = "{\"password\":\"welcome\",\"userName\":\"usr_0023\",\"email\":\"pruebas@mail_pruebas123.com\",\"firstName\":\"Usuário\",\"lastName\":\"Pruebás\"}";
byte[] utf81 = persona.getBytes("UTF-8");
String personaUTF = new String(utf81, "UTF8");
System.out.print("Persona UTF : " + personaUTF);

input = new StringEntity(personaUTF);      
input.setContentEncoding("UTF-8");
input.setContentType("application/json;charset=UTF-8");
postRequest.setEntity(input);

response = httpClient.execute(postRequest);
response.addHeader("Content-Type","application/json; charset=UTF-8");

Trace:

Persona UTF : {"password":"welcome","userName":"usr_0023","email":"pruebas@mail_pruebas123.com","firstName":"Usuário","lastName":"Pruebás"}
Codigo: 200
Respuesta del servidor ….

<< Response: HTTP/1.1 200 OK
{
   "url": "\/alfresco\/service\/api\/person\/usr_0023",
   "userName": "usr_0023",
   "enabled": true,
   "firstName": "Usu\ufffdrio",
   "lastName": "Prueb\ufffds",
   "jobtitle": null,
   "organization": null,
   "location": null,
   "telephone": null,
   "mobile": null,
   "email": "pruebas@mail_pruebas123.com",
   "companyaddress1": null,
   "companyaddress2": null,
   "companyaddress3": null,
   "companypostcode": null,
   "companytelephone": null,
   "companyfax": null,
   "companyemail": null,
   "skype": null,
   "instantmsg": null,
   "userStatus": null,
   "userStatusTime": null,
   "googleusername": null,
   "quota": -1,
   "sizeCurrent": 0,
   "emailFeedDisabled": false,
   "persondescription": null
}

This is frustrating  Smiley Sad

dreiberg
Champ in-the-making
Champ in-the-making
Hi,

I'm facing the same issue.
I've created a java script based http get webscript and it seems when I fetch the request parameters they're broken.

So, if you found a solution in the mean time, any help would be appreciated.

Thanks

mincd_evolpe
Champ in-the-making
Champ in-the-making
Try adding the Country value to the JAVA_OPTS in:
/alfresco/tomcat/scripts/ctl.sh

eg. for Polish language you can add:
-Duser.country=PL -Duser.region=PL -Duser.language=pl

hope it helps

sharan
Champ in-the-making
Champ in-the-making
Hello,
on windows platform getting some special characters from server.
using war file in tomcat server

The following steps i fallowed:
1. add URIEncoding = "UTF-8" in server.xml
2. Configure Tomcat: Java set as JVM to JAVA
3. in apache tomcat add deafult char set in httpd.conf file : add line at bottom #addDefaultCharset utf8
4. inside programfile/apache software foundation/tomcat 7.0/bin : a create setenv.bat file file contains
    set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF8

still the problem is not resolved.

fcorti
Elite Collaborator
Elite Collaborator

Hi all,


We are seeing this topic is interesting (and useful) for a lot of people but it is starting to contain many questions (and use cases) in one thread.
Please open new questions to continue the discussion on single use cases and issues.

Many thanks.