cancel
Showing results for 
Search instead for 
Did you mean: 

Encoding of content

jlbarrera
Champ in-the-making
Champ in-the-making
Hello

When i get the content of a content in alfresco from web services, i received the text with badly characters.
But if i get, for example, the title, i received well characters.

Only occurs with the content.

Where i can setting encoding for the content?

Thanks
6 REPLIES 6

jlbarrera
Champ in-the-making
Champ in-the-making
More info:

I use a method for get the content:

getContentAsString

This method return the content of a url.

The method getContentAsString return: "dentro de dos años"
But the method would return: "dentro de dos A?os"

Some ideas?

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

I'm not entirly sure where the issue lies here so I have raised an JIRA bug.

You can track the issue here http://www.alfresco.org/jira/browse/AR-682

Cheers,
Roy

jlbarrera
Champ in-the-making
Champ in-the-making
Hello, I solved this problem by the next way  Smiley Happy

I modified the class: org.alfresco.web.app.servlet.DownloadContentServlet

And i add the next code in the method: doGet

          
req.setCharacterEncoding("UTF-8");
      res.setCharacterEncoding("UTF-8");

By this way in my class of web services, when i try get the content of a Node i used the HttpClient Library:

   HttpClient client = new HttpClient();
               
               client.getState().setCredentials(
                     new AuthScope("localhost", 8080, "realm"),
                        new UsernamePasswordCredentials("admin", "admin")
                     );
               GetMethod method = new GetMethod(url.toString());
               method.addRequestHeader("Content-Type", "text/html; charset=UTF-8");
               client.executeMethod(method);
                String cadena=method.getResponseBodyAsString();

And by this way i can get the content of a node in the correct encoding.

Thanks!

rwetherall
Confirmed Champ
Confirmed Champ
Ok, thanks for that.

Roy

jlbarrera
Champ in-the-making
Champ in-the-making
I changed the method of get content of node, and now in the url i pass the ticket:

                             
String ticket = AuthenticationUtils.getCurrentTicket();
               String strUrl = contenido.getUrl() + "?ticket=" + ticket;
               
               URL url = new URL(strUrl);
               
               
               HttpClient client = new HttpClient();
               
               GetMethod method = new GetMethod(url.toString());
               method.addRequestHeader("Content-Type", "text/html; charset=UTF-8");
               client.executeMethod(method);
               String cadena=method.getResponseBodyAsString();

kevinr
Star Contributor
Star Contributor
I have raised the fix to DownloadContentServlet as a bug:
http://www.alfresco.org/jira/browse/AWC-762

Thanks,

Kevin