use of com.ing.ifsa.IFSATextMessage in project iaf by ibissource.
the class PullingIfsaProviderListener method getRawMessage.
/**
* Retrieves messages to be processed by the server, implementing an IFSA-service, but does no processing on it.
*/
public Object getRawMessage(Map threadContext) throws ListenerException {
Object result = null;
QueueSession session = null;
QueueReceiver receiver = null;
threadContext.remove(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
try {
session = getSession(threadContext);
try {
receiver = getReceiver(threadContext, session);
result = receiver.receive(getTimeOut());
while (result == null && canGoOn() && !JtaUtil.inTransaction()) {
result = receiver.receive(getTimeOut());
}
} catch (Exception e) {
throw new ListenerException(getLogPrefix(), e);
} finally {
releaseReceiver(receiver);
}
} finally {
if (sessionNeedsToBeSavedForAfterProcessMessage(result)) {
threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
} else {
releaseSession(session);
}
}
if (result instanceof IFSAPoisonMessage) {
IFSAHeader header = ((IFSAPoisonMessage) result).getIFSAHeader();
String source;
try {
source = header.getIFSA_Source();
} catch (Exception e) {
source = "unknown due to exeption:" + e.getMessage();
}
String msg = getLogPrefix() + "received IFSAPoisonMessage " + "source [" + source + "]" + "content [" + ToStringBuilder.reflectionToString((IFSAPoisonMessage) result) + "]";
log.warn(msg);
}
try {
if ((result instanceof IFSATextMessage || result instanceof IFSAPoisonMessage) && JtaUtil.inTransaction()) {
threadContext.put(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY, result);
result = new MessageWrapper(result, this);
}
} catch (Exception e) {
throw new ListenerException("cannot wrap non serialzable message in wrapper", e);
}
return result;
}
use of com.ing.ifsa.IFSATextMessage in project iaf by ibissource.
the class IfsaFacade method sendMessage.
/**
* Sends a message,and if transacted, the queueSession is committed.
* <p>This method is intended for <b>clients</b>, as <b>server</b>s
* will use the <code>sendReply</code>.
* @return the correlationID of the sent message
*/
public TextMessage sendMessage(QueueSession session, QueueSender sender, String message, Map udzMap, String bifName, byte[] btcData) throws IfsaException {
try {
if (!isRequestor()) {
throw new IfsaException(getLogPrefix() + "Provider cannot use sendMessage, should use sendReply");
}
IFSATextMessage msg = (IFSATextMessage) session.createTextMessage();
msg.setText(message);
if (udzMap != null && msg instanceof IFSAMessage) {
// Handle UDZs
log.debug(getLogPrefix() + "add UDZ map to IFSAMessage");
// process the udzMap
Map udzObject = (Map) ((IFSAMessage) msg).getOutgoingUDZObject();
udzObject.putAll(udzMap);
}
String replyToQueueName = "-";
// Client side
if (messageProtocol.equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) {
// set reply-to address
Queue replyTo = getMessagingSource().getClientReplyQueue(session);
msg.setJMSReplyTo(replyTo);
replyToQueueName = replyTo.getQueueName();
}
if (messageProtocol.equals(IfsaMessageProtocolEnum.FIRE_AND_FORGET)) {
// not applicable
}
if (StringUtils.isNotEmpty(bifName)) {
msg.setBifName(bifName);
}
if (btcData != null && btcData.length > 0) {
msg.setBtcData(btcData);
}
if (log.isDebugEnabled()) {
log.debug(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message [" + message + "]");
} else {
if (log.isInfoEnabled()) {
log.info(getLogPrefix() + " messageProtocol [" + messageProtocol + "] replyToQueueName [" + replyToQueueName + "] sending message");
}
}
// send the message
sender.send(msg);
// perform commit
if (isJmsTransacted() && !(messagingSource.isXaEnabledForSure() && JtaUtil.inTransaction())) {
session.commit();
log.debug(getLogPrefix() + "committing (send) transaction");
}
return msg;
} catch (Exception e) {
throw new IfsaException(e);
}
}
Aggregations