# Using the MQSeries Control Exit Implementation

The MQSeries control allows you to create your own send, receive, and security exits.

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

- MQSendExit

The MQSeries MQSendExit interface allows you to examine and change the data sent to the queue manager by the WebSphere MQ Client for Java.

- MQReceiveExit

The MQSeries MQReceiveExit interface allows you to examine and change the data received from the queue manager by the WebSphere MQ Client for Java.

- MQSecurityExit

The MQSeries MQSecurityExit interface allows you to customize the security settings for connecting to a queue manager.

Notes: User Exits are supported for TCP connections only; they are not supported for bindings connections.

User Exits are used to modify the data that is transmitted between the MQSeries queue manager and the MQSeries client application. This data is in the form of MQSeries headers and does not involve the contents of the actual message being put and received from the queue.

### Implementing MQSeries Exits

To implement MQSeries Exits, perform the following tasks:

1. Create the Java class that implements the com.ibm.mq.MQSendExit, com.ibm.mq.MQReceiveExit, and com.ibm.mq.MQSecurity interfaces for the send, receive, and security exits, as shown in the following example:

package com.bea.UserExit;
import com.ibm.mq.*;
public class MQUserExit implements MQSendExit, MQReceiveExit, MQSecurityExit {
public MQUserExit()
{
}
public byte[] sendExit(MQChannelExit channelExit,MQChannelDefinition channelDefnition,byte[] agentBuffer)
{
return agentBuffer;
}
public byte[] receiveExit(MQChannelExit channelExit,MQChannelDefinition channelDefnition,byte[] agentBuffer)
{
return agentBuffer;
}
public byte[] securityExit(MQChannelExit channelExit,MQChannelDefinition channelDefnition,byte[] agentBuffer)
{
return agentBuffer;
}
}

You may implement these interfaces in a single class or in separate classes, as required.

For an MQSendExit, the agentBuffer parameter contains the data to be sent. For an MQReceiveExit or an MQSecurityExit, the agentBuffer parameter contains the data just received.

For the MQSendExit and the MQSecurityExit, 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 Client for Java to interpret.

2. Bundle the given class in a Jar file, for example, mquserexits.jar.
3. Place the Jar file in the WebLogic classpath. Edit the setDomainEnv.cmd file located in the WebLogic domain directory to append the Jar file name to the CLASSPATH. To do this, find the following code in the setDomainEnv.cmd file:

set CLASSPATH=%ARDIR%\ant\ant.jar;%JAVA_HOME%\jre\lib\rt.jar

and append the following line to it:

;%EXIT_DIR%\mquserexits.jar

Before you append the code containing the Jar file name to the CLASSPATH, you can define the directory in which the Jar file resides, as follows:

set EXIT_DIR=D:\UserExits