use of com.ing.ifsa.IFSAQueue in project iaf by ibissource.
the class IfsaRequesterSender method sendMessage.
/**
* Execute a request to the IFSA service.
* @return in Request/Reply, the retrieved message or TIMEOUT, otherwise null
*/
public String sendMessage(String dummyCorrelationId, String message, Map params, String bifName, byte[] btcData) throws SenderException, TimeOutException {
String result = null;
QueueSession session = null;
QueueSender sender = null;
Map udzMap = null;
try {
log.debug(getLogPrefix() + "creating session and sender");
session = createSession();
IFSAQueue queue;
if (params != null && params.size() > 0) {
// Use first param as serviceId
String serviceId = (String) params.get("serviceId");
if (serviceId == null) {
serviceId = getServiceId();
}
String occurrence = (String) params.get("occurrence");
if (occurrence != null) {
int i = serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/', serviceId.indexOf('/') + 1) + 1) + 1);
int j = serviceId.indexOf('/', i + 1);
serviceId = serviceId.substring(0, i + 1) + occurrence + serviceId.substring(j);
}
queue = getMessagingSource().lookupService(getMessagingSource().polishServiceId(serviceId));
if (queue == null) {
throw new SenderException(getLogPrefix() + "got null as queue for serviceId [" + serviceId + "]");
}
if (log.isDebugEnabled()) {
log.info(getLogPrefix() + "got Queue to send messages on [" + queue.getQueueName() + "]");
}
// Use remaining params as outgoing UDZs
udzMap = new HashMap();
udzMap.putAll(params);
udzMap.remove("serviceId");
udzMap.remove("occurrence");
} else {
queue = getServiceQueue();
}
sender = createSender(session, queue);
log.debug(getLogPrefix() + "sending message with bifName [" + bifName + "]");
TextMessage sentMessage = sendMessage(session, sender, message, udzMap, bifName, btcData);
log.debug(getLogPrefix() + "message sent");
if (isSynchronous()) {
log.debug(getLogPrefix() + "waiting for reply");
Message msg = getRawReplyMessage(session, queue, sentMessage);
try {
long tsReplyReceived = System.currentTimeMillis();
long tsRequestSent = sentMessage.getJMSTimestamp();
long tsReplySent = msg.getJMSTimestamp();
// }
if (log.isInfoEnabled()) {
log.info(getLogPrefix() + "A) RequestSent [" + DateUtils.format(tsRequestSent) + "]");
log.info(getLogPrefix() + "B) ReplySent [" + DateUtils.format(tsReplySent) + "] diff (~queing + processing) [" + (tsReplySent - tsRequestSent) + "]");
log.info(getLogPrefix() + "C) ReplyReceived [" + DateUtils.format(tsReplyReceived) + "] diff (transport of reply )[" + (tsReplyReceived - tsReplySent) + "]");
// log.info(getLogPrefix()+"C2) msgRcvd.businessProcStartRcvd ["+DateUtils.format(businessProcStartRcvd) +"] ");
// log.info(getLogPrefix()+"D) msgRcvd.jmsTimestamp ["+DateUtils.format(jmsTimestampRcvd) +"] diff ["+(jmsTimestampRcvd-businessProcStartSent)+"]");
// log.info(getLogPrefix()+"E) msgRcvd.businessProcFinishRcvd ["+DateUtils.format(businessProcFinishRcvd)+"] diff ["+(businessProcFinishRcvd-jmsTimestampRcvd)+"] (=time spend on IFSA bus sending result?)");
// log.info(getLogPrefix()+"F) timestampAfterRcvd ["+DateUtils.format(timestampAfterRcvd) +"] diff ["+(timestampAfterRcvd-businessProcFinishRcvd)+"] ");
// log.info(getLogPrefix()+"business processing time (E-C1) ["+(businessProcFinishRcvd-businessProcStartSent)+"] ");
}
// if (businessProcessTimes!=null) {
// businessProcessTimes.addValue(businessProcFinishRcvd-businessProcStartSent);
// }
} catch (JMSException e) {
log.warn(getLogPrefix() + "exception determining processing times", e);
}
if (msg instanceof TextMessage) {
result = ((TextMessage) msg).getText();
} else {
if (msg.getClass().getName().endsWith("IFSAReportMessage")) {
if (msg instanceof IFSAReportMessage) {
IFSAReportMessage irm = (IFSAReportMessage) msg;
if (isThrowExceptions()) {
throw new SenderException(getLogPrefix() + "received IFSAReportMessage [" + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason [" + irm.getNoReplyReason() + "]");
}
log.warn(getLogPrefix() + "received IFSAReportMessage [" + ToStringBuilder.reflectionToString(irm) + "], NoReplyReason [" + irm.getNoReplyReason() + "]");
result = "<IFSAReport>" + "<NoReplyReason>" + irm.getNoReplyReason() + "</NoReplyReason>" + "</IFSAReport>";
}
} else {
log.warn(getLogPrefix() + "received neither TextMessage nor IFSAReportMessage but [" + msg.getClass().getName() + "]");
result = msg.toString();
}
}
if (result == null) {
log.info(getLogPrefix() + "received null reply");
} else {
if (log.isDebugEnabled()) {
if (AppConstants.getInstance().getBoolean("log.logIntermediaryResults", false)) {
log.debug(getLogPrefix() + "received reply [" + result + "]");
} else {
log.debug(getLogPrefix() + "received reply");
}
} else {
log.info(getLogPrefix() + "received reply");
}
}
} else {
result = sentMessage.getJMSMessageID();
}
} catch (JMSException e) {
throw new SenderException(getLogPrefix() + "caught JMSException in sendMessage()", e);
} catch (IfsaException e) {
throw new SenderException(getLogPrefix() + "caught IfsaException in sendMessage()", e);
} finally {
if (sender != null) {
try {
log.debug(getLogPrefix() + "closing sender");
sender.close();
} catch (JMSException e) {
log.debug(getLogPrefix() + "Exception closing sender", e);
}
}
closeSession(session);
}
if (isThrowExceptions() && result != null && result.startsWith("<exception>")) {
throw new SenderException("Retrieved exception message from IFSA bus: " + result);
}
return result;
}
Aggregations