Reputation: 21134
Is it possible to reply to a MSGW job in AS400 from JT400?
I've got the Job element and I can know if it's in MSGW status by Job.MESSAGE_REPLY_WAITING
Ex: normally I use "C" via WRKACTJOB
Upvotes: 4
Views: 1614
Reputation: 21134
This is the code that works. I think it can be shortened and optimized.
There must be a better way!
public boolean answer(String answer) throws MyOperationException {
if (answer == null || answer.length() > 1) {
throw new MyOperationException();
}
MessageQueue msgq = new MessageQueue(as.getAS400(), QSYSObjectPathName.toPath(MyAS400.LIBRARY_LIST, "QSYSOPR", "MSGQ"));
msgq.setSelectMessagesNeedReply(true);
msgq.setListDirection(false);
try {
Enumeration m = msgq.getMessages();
while (m.hasMoreElements()) {
QueuedMessage msg = (QueuedMessage) m.nextElement();
if (msg.getFromJobNumber().trim().equals(getNumber())) {
msgq.reply(msg.getKey(), answer);
return true;
}
}
} catch (AS400SecurityException | ErrorCompletingRequestException | InterruptedException | IOException | ObjectDoesNotExistException ex) {
ex.printStackTrace();
}
return false;
}
If you don't know the message queue, you can use ObjectList.
Upvotes: 0
Reputation: 23793
David's correct...but missing a couple steps I think..and note I've not tried this either..
Get the joblog:
Job.getJobLog()
Get the queued messages
JobLog.getMessages
Get the Message Queue
QueuedMessage.getQueue()
Then reply
MessageQueue.reply()
Upvotes: 4
Reputation: 4014
I haven't actually tried this, but take a look at the reply
function in MessageQueue (JTOpen).
Upvotes: 2