on 10-27-2017 6:26 PM
Hello, guys.
Currently working on a project that involves javascript with HCI PI and when we try to pass the message body to the script other characters turn to this ��, its suppose to be like this é tried to put encoding or parsing the string to byte but failed. what can i do to avoid such error, thanks
Hello Elpedio,
Agree with Sergio.
You need to maintain character encoding while reading the data in Script and generating output out of your script .Below might help you.
Beginning of the script:
def Message TestData (Message message)
{
// Extract message body and properties
def body = message.getBody(String.class);
def props = message.getProperties();
// Create a new JDOM XML Parser
SAXBuilder builder = new SAXBuilder();
// Obtain the XML data from the message body received, and build it using the parser
InputStream is = new ByteArrayInputStream(body.getBytes("UTF-8"));
Document doc = builder.build(is);
................... code goes on as per your requirement
After you are done with all the transformation:
// Create a new XMLOutputter object to write the new
XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat().setOmitDeclaration(true));
// Write the modified XML data into a ByteArrayInputStream Object, which can then be set as the message's body
is = new ByteArrayInputStream(outputter.outputString(doc).getBytes("UTF-8"));
message.setBody(is);
return message;
}
Regards,
Sriprasad Shivaram Bhat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
make sure your enconding is utf-8
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.