132 WCTME: Application Development and Case Study
// administration message as well as the correct parameter names
using our
// input
startMessage.start();
MQeAdminMsg response = sendMsgAndWait(startMessage);
if (response.getRC() != MQeAdminMsg.RC_Success) {
throw new MQeException(response.getReason());
}
} catch (Exception e) {
System.out.println(
"MQeAdmin: Error creating starting Listener. " + e);
System.out.println(
"MQeAdmin: Check that another server is not running and that
nothing else is using this port");
e.printStackTrace();
}
}
/**
* Stops the Queue Managers Listener
*/
public void stopListener() {
try {
MQeCommunicationsListenerAdminMsg startMessage =
new MQeCommunicationsListenerAdminMsg();
// set the name of the resource we wish to create
startMessage.setName("Listener 1");
// provide the parameters to the method that will set the action of
the
// administration message as well as the correct parameter names
using our
// input
startMessage.stop();
MQeAdminMsg response = sendMsgAndWait(startMessage);
if (response.getRC() != MQeAdminMsg.RC_Success) {
throw new MQeException(response.getReason());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* method to delete the listener using an administration message
*/
Chapter 5. Messaging 133
public void deleteListener() {
try {
MQeCommunicationsListenerAdminMsg deleteMessage =
new MQeCommunicationsListenerAdminMsg();
// set the name of the resource we wish to create
deleteMessage.setName("Listener 1");
// provide the parameters to the method that will set the action of
the
// administration message as well as the correct parameter names
using our
// input
deleteMessage.setAction(MQeAdminMsg.Action_Delete);
MQeAdminMsg response = sendMsgAndWait(deleteMessage);
if (response.getRC() != MQeAdminMsg.RC_Success) {
throw new MQeException(response.getReason());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Adds a remote queue definition. This is used by the client to setup
* a remote queue definition to the servers local queue.
*
* @param remoteQueueManagerName
* @param queueName
*/
public void addRemoteQueueDefinition(
String remoteQueueManagerName,
String queueName) {
try {
this.remoteQueueManagerName = remoteQueueManagerName;
this.queueName = queueName;
MQeRemoteQueueAdminMsg remQueueMsg =
new MQeRemoteQueueAdminMsg(remoteQueueManagerName, queueName);
remQueueMsg.setTargetQMgr(
MQeQueueManager.getDefaultQueueManager().getName());
MQeFields parms = new MQeFields();
parms.putByte(
MQeQueueAdminMsg.Queue_Mode,
MQeQueueAdminMsg.Queue_Asynchronous);
parms.putAscii(MQeQueueAdminMsg.Queue_FileDesc, queueStore);
remQueueMsg.create(parms);
MQeAdminMsg response = sendMsgAndWait(remQueueMsg);
134 WCTME: Application Development and Case Study
if (response.getRC() != MQeAdminMsg.RC_Success) {
if (response
.getReason()
.indexOf(
String.valueOf(MQeExceptionCodes.Except_QMgr_QExists))
== -1) {
throw new MQeException(response.getReason());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* method to show how a connection definition may be created using an
administration
* message. This is used by the client to setup a connection definition to
the
* server so messages can be sent.
*
* @param receiverQMIPAddress
* @param receiverQMPort
*/
public void createConnection(
String receiverQMIPAddress,
String receiverQMPort) {
try {
MQeConnectionAdminMsg connectionMessage =
new MQeConnectionAdminMsg();
// Set the name of the resource we wish to create. The connection
definition name
// is always the same as the name of the remote queue manager to
which its
// information will allow you to go
connectionMessage.setName(remoteQueueManagerName);
// Call the method that will automatically set the correct MQeFields
for our connection.
connectionMessage.create(
//"com.ibm.mqe.adapters.MQeTcpipHttpAdapter:"
"Network:" + receiverQMIPAddress + ":" + receiverQMPort,
null,
null,
"DefaultChannel",
Chapter 5. Messaging 135
"Example connection");
MQeAdminMsg response = sendMsgAndWait(connectionMessage);
} catch (Exception e) {
System.out.println("MQeAdmin: Error creating connection " + e);
e.printStackTrace();
}
}
/**
* method to show how a connection definition may be deleted using an
administration
* message
*/
public void deleteConnection() {
try {
MQeConnectionAdminMsg deleteMessage = new MQeConnectionAdminMsg();
// set the target queue manager
deleteMessage.setTargetQMgr(myQmName);
deleteMessage.setName(remoteQueueManagerName);
deleteMessage.setAction(MQeAdminMsg.Action_Delete);
// indicate that we require a reply message
deleteMessage.putInt(MQe.Msg_Style, MQe.Msg_Style_Request);
// use default reply-to queue on the target queue manager.
deleteMessage.putAscii(
MQe.Msg_ReplyToQ,
MQe.Admin_Reply_Queue_Name);
deleteMessage.putAscii(MQe.Msg_ReplyToQMgr, myQmName);
// create a unique tag that we can identify the reply with
String match = "Msg" + System.currentTimeMillis();
deleteMessage.putArrayOfByte(MQe.Msg_CorrelID, match.getBytes());
System.out.println(
"MQeAdmin: delete connection administration message created");
// now put the administration message to the default administration
queue
qm.putMessage(
myQmName,
MQe.Admin_Queue_Name,
deleteMessage,
null,
136 WCTME: Application Development and Case Study
0);
// create the filter so we get the match
MQeFields filter = new MQeFields();
filter.putArrayOfByte(MQe.Msg_CorrelID, match.getBytes());
// now wait for a reply
MQeAdminMsg response =
(MQeAdminMsg) qm.waitForMessage(
myQmName,
MQe.Admin_Reply_Queue_Name,
filter,
null,
0,
3000);
// the administration message has a method that will get out the
return code
switch (response.getRC()) {
case MQeAdminMsg.RC_Success :
System.out.println("MQeAdmin: connection deleted");
break;
case MQeAdminMsg.RC_Fail :
System.out.println(
"MQeAdmin: connection not deleted, failed with: "
+ response.getReason());
break;
case MQeAdminMsg.RC_Mixed :
processMixedResult(response);
break;
}
if (response.getRC() != MQeAdminMsg.RC_Success) {
throw new MQeException(response.getReason());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* A utility method to process a mixed response from sending an admin
message
* @param response
* @throws Exception
*/
public void processMixedResult(MQeAdminMsg response) throws Exception {
if (response
.getReason()
.indexOf(

Get IBM Workplace Client Technology Micro Edition Version 5.7.1: Application Development and Case Study now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.