Character Set

An X-PUSH Server processes transmitted strings using the following basic principle:

Transmit a bit stream delivered by a message provider directly to a Nexacro Client without modifications.

An X-PUSH Server transmits to a Nexacro Client contents encoded in a specific character without modifications. Therefore, the server itself does not require any special charset configurations. However, the message provider and Nexacro adapter encode and decode strings and must be set to the same charset.

The message provider API and Nexacro Client adapter - provided by X-PUSH at the time of deployment - are set to UTF-8 by default. Generally, you do not have to modify the settings. If you do not use the message provider API or you plan to develop a message provider in another language, the strings that will be transmitted to an X-PUSH Server must be encoded in UTF-8.

To provide messages in a character set other than UTF-8, you must set up the Nexacro Client adapter in the same character set.

The byte[] values are transmitted by a message provider and received by the Message Formatter are left as-is, and the same character set must be used to convert said values to string objects.

In short, the charset must be configured (or considered) for the following:

Charset in a Message Provider

After creating a PushMessage instance, set the charset via the setCharsetName() method. Unless otherwise configured, the default setting is UTF-8.

pushMessageProvider.connect(host, port, id, password);

PushMessage pushMessage = new PushMessage();

// set character set. default is "utf-8"
pushMessage.setCharsetName("utf-8");

// set message type.
pushMessage.setTopicType("OPDT");

// set mesage id.
pushMessage.setTopicId("ALL");

// add data as defined in layout
pushMessage.addData("ALL");
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String currentTime = "CURRENT TIME : "+formatter.format(new Date());

// send message
pushMessageProvider.sendPushMessage(pushMessage);

// close connection
pushMessageProvider.close();

In the case of an embedded message provider, the charset can be configured by using the PushMessage class.

Charset in a Nexacro Client

The default charset setting in Nexacro Platform is UTF-8. The designated value can be found in the below file when each project created.

[project folder]\globalvars.xml

Charset in a Message Formatter

A bit stream transmitted to an X-PUSH Server is delivered to the Message Formatter in the byte[] format.

As in the following example, bit streams are decoded using the new String(byte[] bytes, String charsetName) method, and formatted strings are encoded using the String.getBytes(String charsetName) method. As before, the charset is used at this time must be the same as that used in the message provider and Nexacro Client.

public List<byte[]> format(UserProfile userProfile, final String topicType,
final String topicId, List<byte[]> valueBytesList) {

	List<byte[]> formattedValueBytesList = new ArrayList<byte[]>();

	for(int i=0; i<valueBytesList.size(); i++) {
		byte[] valueBytes = valueBytesList.get(i);
		byte[] formattedValueBytes = new byte[0];
		try {
			String value = new String(valueBytes, "utf-8");
			String formattedValue
				= value.replace("current time", (new Date()).toString());
			formattedValueBytes = formattedValue.getBytes("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		formattedValueBytesList.add(formattedValueBytes);
	}
	return formattedValueBytesList;
}