Writing user 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:
- Note:
- User 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.
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 you cannot read or write any local files. If your exit needs a configuration file, you can place the file on the Web and use the java.net.URL class to download it and examine its contents.
WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.
IBM is a trademark of the IBM Corporation in the United States, other countries, or both.