11 Managing Message Conversion in Instant Messaging

This chapter explains how to configure and manage message conversion for Oracle Communications Instant Messaging Server.

About Message Conversion

If enabled, a Message Converter is invoked for every message or each message part going through the server. The Message Converter may leave the message part intact or modify or remove the message part. Message Conversion can be used to manipulate the message packets that pass through the server. Message packets can either be from a one-to-one chat or from a group-chat conversation.

Managing Message Conversion in the Instant Messaging Server

Message Conversion can be used to manipulate the message packets that pass through the server. Message packets can either be from a one-to-one chat or from a group-chat conversation. The abstract class com.sun.im.provider.MessageConverter needs to be implemented to write a custom provider for Message Conversion.

Implementing the Custom Message Conversion Provider

To implement the conversion provider, you must extend the MessageCoverter class and override the corresponding methods.

Following is an example of implementing a custom message conversion provider:

package com.sun.im.provider;
/**
Custom provider for Message Conversion must extend this abstract class.
*/
public abstract class MessageConverter
{
/**
* Convert a message part.
* This method may make modification to the content, content-
* type and content-name of the provided MessagePart object.
*
* @param part incoming message part to convert.
* If the contents of the part once modified are null, the part is
* removed.
* @deprecated instead use com.sun.im.service.Message
* @exception Exception the converter may throw an Exception.
* If so the exception is logged in the server log file and the message
* is not relayed to any recipients.
* The sender receives a negative delivery status.
*/
public void convert(com.sun.im.service.MessagePart part) throws Exception
{
return;
}
/**
* Convert a message part.
* This method may make modification to the content, content-
* type and content-name of the provided MessagePart object.
* It needs to be overwritten by actual message converters.
* The default behaviour of this method is to call
* convert(com.sun.im.service.MessagePart)
* so all the extensions to MessageConverter written prior
* to version 7.0 will still work with later versions.
* @param message incoming message to convert. If the contents
* of the message once modified are null, the message is 
* removed. Implementing the Custom Message Conversion Provider
* If so the exception is logged in the server log file and
* the message is not relayed to any recipients.
*/
public void convert(com.sun.im.service.Message message) throws Exception
{
com.sun.im.service.MessagePart parts[] = message.getParts();
convert(parts[0]);
}
}

Message Converter Provider Example

Following is an example of a custom message converter provider:

public class MessageConverterSample extends MessageConverter
{
private FileWriter fstream;
private BufferedWriter out;
static {
try {
fstream = new FileWriter("/tmp/MessageConverter");
out = new BufferedWriter(fstream);
} catch (IOException ex) {
Logger.getLogger(MessageConverterSample.class.getName())
.log(Level.SEVERE, null, ex);
}
}
public void convert(com.sun.im.service.Message message) throws Exception
{
Log.debug( MessageConverter:convert() called );
String convertedMessage = message.getContent() + " \
\nDISCLAIMER : Messages are archived for security reasons";
message.setContent(convertedMessage);
out.write( Converted message is + message.getContent());
}
}

Compiling the Custom Message Converter Provider

Compile your custom message converter provider using the following JAR file in the classpath: imservice.jar.

Use the imconfutil command to include the JAR file in your classpath.

imconfutil -c InstantMessaging_home/config/iim.conf.xml set-prop iim_server.classpath=your-custom-provider

Enabling and Disabling the Instant Messaging Message Converter Provider

This section describes how to enable and disable the Instant Messaging Server message converter provider.

To enable message conversion and the message converter provider:

  1. Enable message conversion.

    imconfutil -c InstantMessaging_home/config/iim.conf.xml set-prop iim_server.conversion=true
    
  2. Enable your custom message converter provider.

    imconfutil -c InstantMessaging_home/iim.conf.xml set-prop iim_server.conversion.provider=fully-qualified-name-of-your-custom-provider
    
  3. Restart the server.

    imadmin refresh server
    

To disable message conversion, use the following command:

imconfutil -c InstantMessaging_home/iim.conf.xml set-prop iim_server.filter.enable=false