Use channel exits

 

WebSphere MQ classes for Java allows you to provide your own send, receive, and security exits.

To implement an exit, you define a new Java™ class that implements the appropriate interface. Three exit interfaces are defined in the WebSphere MQ package:

Channel exits are supported for client connections only; they are not supported for bindings connections.

Any SSL encryption defined for a connection is performed after the send exit has been invoked. Similarly, decryption is performed before the receive or security exits are invoked.

The following sample defines a class that implements all three:

class MyMQExits implements MQSendExit, MQReceiveExit, MQSecurityExit {
 
  // This method comes from the send exit
  public byte[] sendExit(MQChannelExit channelExitParms,
                         MQChannelDefinition channelDefParms,
                         byte agentBuffer[])
  {
     // fill in the body of the send exit here
  }
 
 
  // This method comes from the receive exit
  public byte[] receiveExit(MQChannelExit channelExitParms,
                            MQChannelDefinition channelDefParms,
                            byte agentBuffer[])
  {
     // fill in the body of the receive exit here
  }
 
 
  // This method comes from the security exit
  public byte[] securityExit(MQChannelExit channelExitParms,
                             MQChannelDefinition channelDefParms,
                             byte agentBuffer[])
  {
     // fill in the body of the security exit here
  }
 
}

Each exit is passed an MQChannelExit and an MQChannelDefinition object instance. These objects represent the MQCXP and MQCD structures defined in the procedural interface.

For a send exit, the agentBuffer parameter contains the data that is about to be sent. For a receive exit or a security exit, the agentBuffer parameter contains the data that has just been received. You do not need a length parameter, because the expression agentBuffer.length indicates the length of the array. We cannot change the size of the agentBuffer in an exit .

For the send and security exits, your exit code should return the byte array that you want to send to the server. For a receive exit, your exit code must return the modified data that you want WebSphere MQ classes for Java to interpret.

The simplest possible exit body is:

{
  return agentBuffer;
}

If your program is to run as a downloaded Java applet, the security restrictions that apply mean that we cannot read or write any local files. If your exit needs a configuration file, we can place the file on the Web and use the java.net.URL class to download it and examine its contents.

Having defined a class that implements the MQSecurityExit interface, an application can use the security exit by assigning an instance of the class to the MQEnvironment.securityExit field before creating an MQQueueManager object. An application can use a send or a receive exit in a similar way. For example, the following code fragment shows you how to use the security, send, and receive exits that are implemented in the class MyMQExits, which was defined previously:

MyMQExits myexits = new MyMQExits();
MQEnvironment.securityExit = myexits;
MQEnvironment.sendExit = myexits;
MQEnvironment.receiveExit = myexits;
:
MQQueueManager jupiter = new MQQueueManager("JUPITER");

If an application connects to a queue manager by setting channel related fields or environment properties in the MQEnvironment class, no user data can be passed to channel exit classes when they are called. However, if an application uses a client channel definition table to connect to a queue manager, any user data specified in a client connection channel definition is passed to channel exit classes when they are called. For more information about using a client channel definition table, see Using a client channel definition table.

If you package channel exit classes in separate JAR files or class files, make sure that WebSphere MQ base Java can locate these files. For an application that is not running in an application server, we can do this in either of the following ways:

For an application that is running in an application server, store the files in the directory shown in Table 1.

The directory for channel exit programs
Platform Directory
AIX, HP-UX, Linux, and Solaris

/var/mqm/exits (32-bit channel exit programs)
/var/mqm/exits64 (64-bit channel exit programs)

Windows install_data_dir\exits

install_data_dir is the directory that you chose for the WebSphere MQ data files during installation. The default directory is C:\\IBM\WebSphere MQ.


uj11170_