Thursday, 10 April 2014

Posting Special Characters to Adobe Experience Manager

In some some business use cases, you may have to post special characters, such as ®, to Adobe Experience Manager. Once posted to AEM, you can use special characters to set node properties, as shown in the following illustration.


By default, you cannot post strings to AEM that contain special characters. For example, you cannot run this CURL command to post special characters to AEM.

curl -H "charset=utf-8" -u admin:admin -X POST --data "test=€ , Š , Œ , ™ , š , œ , ž" http://localhost:4502/content/mynodetest

If you attempt this command with CURL, wrong characters are inserted into AEM. That is, you will see: "Ç , è , î , Ö , Ü , £ , P , Ä , " instead of "€ , Š , Œ , ™ , š , œ , ž , Ž , Ÿ".

To successfully post special characters to AEM and use them to set node values in the AEM JCR, you have to create a custom Sling Servlet that is able to handle UTF-8 (UCS Transformation Format—8-bit) encoded strings. This encoding type is a variable-width encoding that represents every character in the Unicode character set.

The Sling Servlet can decode the strings that contain special characters using Java application logic.

String id = java.net.URLDecoder.decode(request.getParameter("id"), "UTF-8");
String firstName = java.net.URLDecoder.decode(request.getParameter("firstName"),"UTF-8");

To post these special characters to the AEM Sling Servlet, encode the strings, as shown in this Java code example.

String val = java.net.URLEncoder.encode("cust®", "UTF-8");
String firstName = java.net.URLEncoder.encode("TOM®", "UTF-8");

To read this development article, click,   http://helpx.adobe.com/experience-manager/using/post_chars.html.

Adobe Digital Marketing Community

Join the Adobe Digital Marketing Community. Start by clicking this banner

About the Author

I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with over 16 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.

Linked Inhttp://www.linkedin.com/in/scottmacdonald2010
TwitterFollow the Digital Marketing Customer Care team on Twitter @AdobeMktgCare.

4 comments:

  1. Hi, Scott,
    are we be able soon to use AEM restful APIs to post special characters to AEM?
    We are using C# as front end where we post data to AEM.
    Thanks.

    ReplyDelete
  2. You can use C# to post to a Sling Servlet. I have an example on this blog of using a C# client to post data to an AEM Servlet.

    ReplyDelete
  3. Hi Scott,
    thanks for such prompt answer, but where actual problem is?
    Where is that AEM processing pipe goes wrong with special characters?
    What is that causes problem and can it be fixed on Adobe side?
    It causes us a lot of troubles.

    Thanks.

    ReplyDelete
  4. That is a good question. When ppl attempted to upload data with spec chars - for example - using CURL -- it did not work. That is why took the Servlet approach and encoding logic. It works - but you need to write a servlet.

    ReplyDelete