use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PullingJmsListener method openThread.
public Map openThread() throws ListenerException {
Map threadContext = new HashMap();
try {
if (!isSessionsArePooled()) {
Session session = createSession();
threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
MessageConsumer mc = getMessageConsumer(session, getDestination());
threadContext.put(THREAD_CONTEXT_MESSAGECONSUMER_KEY, mc);
}
return threadContext;
} catch (Exception e) {
throw new ListenerException("exception in [" + getName() + "]", e);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PullingJmsListener method afterMessageProcessed.
public void afterMessageProcessed(PipeLineResult plr, Object rawMessage, Map threadContext) throws ListenerException {
String cid = (String) threadContext.get(IPipeLineSession.technicalCorrelationIdKey);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "in PullingJmsListener.afterMessageProcessed()");
try {
Destination replyTo = (Destination) threadContext.get("replyTo");
// handle reply
if (isUseReplyTo() && (replyTo != null)) {
Session session = null;
log.debug(getLogPrefix() + "sending reply message with correlationID [" + cid + "], replyTo [" + replyTo.toString() + "]");
long timeToLive = getReplyMessageTimeToLive();
boolean ignoreInvalidDestinationException = false;
if (timeToLive == 0) {
Message messageSent = (Message) rawMessage;
long expiration = messageSent.getJMSExpiration();
if (expiration != 0) {
timeToLive = expiration - new Date().getTime();
if (timeToLive <= 0) {
log.warn(getLogPrefix() + "message [" + cid + "] expired [" + timeToLive + "]ms, sending response with 1 second time to live");
timeToLive = 1000;
// In case of a temporary queue it might already
// have disappeared.
ignoreInvalidDestinationException = true;
}
}
}
if (threadContext != null) {
session = (Session) threadContext.get(THREAD_CONTEXT_SESSION_KEY);
}
if (session == null) {
try {
session = getSession(threadContext);
send(session, replyTo, cid, prepareReply(plr.getResult(), threadContext), getReplyMessageType(), timeToLive, stringToDeliveryMode(getReplyDeliveryMode()), getReplyPriority(), ignoreInvalidDestinationException);
} finally {
releaseSession(session);
}
} else {
send(session, replyTo, cid, plr.getResult(), getReplyMessageType(), timeToLive, stringToDeliveryMode(getReplyDeliveryMode()), getReplyPriority(), ignoreInvalidDestinationException);
}
} else {
if (getSender() == null) {
log.debug(getLogPrefix() + "itself has no sender to send the result (An enclosing Receiver might still have one).");
} else {
if (log.isDebugEnabled()) {
log.debug(getLogPrefix() + "no replyTo address found or not configured to use replyTo, using default destination" + "sending message with correlationID[" + cid + "] [" + plr.getResult() + "]");
}
getSender().sendMessage(cid, plr.getResult());
}
}
// rollback, but no commit).
if (!isTransacted()) {
if (isJmsTransacted()) {
// the following if transacted using transacted sessions, instead of XA-enabled sessions.
Session session = (Session) threadContext.get(THREAD_CONTEXT_SESSION_KEY);
if (session == null) {
log.warn("Listener [" + getName() + "] message [" + (String) threadContext.get("id") + "] has no session to commit or rollback");
} else {
String successState = getCommitOnState();
if (successState != null && successState.equals(plr.getState())) {
session.commit();
} else {
log.warn("Listener [" + getName() + "] message [" + (String) threadContext.get("id") + "] not committed nor rolled back either");
// TODO: enable rollback, or remove support for JmsTransacted altogether (XA-transactions should do it all)
// session.rollback();
}
if (isSessionsArePooled()) {
threadContext.remove(THREAD_CONTEXT_SESSION_KEY);
releaseSession(session);
}
}
} else {
// TODO: dit weghalen. Het hoort hier niet, en zit ook al in getIdFromRawMessage. Daar hoort het ook niet, overigens...
if (getAckMode() == Session.CLIENT_ACKNOWLEDGE) {
log.debug("[" + getName() + "] acknowledges message with id [" + cid + "]");
((TextMessage) rawMessage).acknowledge();
}
}
}
} catch (Exception e) {
throw new ListenerException(e);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PushingJmsListener method afterMessageProcessed.
public void afterMessageProcessed(PipeLineResult plr, Object rawMessage, Map threadContext) throws ListenerException {
String cid = (String) threadContext.get(IPipeLineSession.technicalCorrelationIdKey);
// session is/must be saved in threadcontext by JmsConnector
Session session = (Session) threadContext.get(jmsConnector.THREAD_CONTEXT_SESSION_KEY);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + "in PushingJmsListener.afterMessageProcessed()");
try {
Destination replyTo = (Destination) threadContext.get("replyTo");
// handle reply
if (isUseReplyTo() && (replyTo != null)) {
log.debug("sending reply message with correlationID[" + cid + "], replyTo [" + replyTo.toString() + "]");
long timeToLive = getReplyMessageTimeToLive();
boolean ignoreInvalidDestinationException = false;
if (timeToLive == 0) {
Message messageReceived = (Message) rawMessage;
long expiration = messageReceived.getJMSExpiration();
if (expiration != 0) {
timeToLive = expiration - new Date().getTime();
if (timeToLive <= 0) {
log.warn("message [" + cid + "] expired [" + timeToLive + "]ms, sending response with 1 second time to live");
timeToLive = 1000;
// In case of a temporary queue it might already
// have disappeared.
ignoreInvalidDestinationException = true;
}
}
}
Map properties = getMessagePropertiesToSet(threadContext);
send(session, replyTo, cid, prepareReply(plr.getResult(), threadContext), getReplyMessageType(), timeToLive, stringToDeliveryMode(getReplyDeliveryMode()), getReplyPriority(), ignoreInvalidDestinationException, properties);
} else {
if (getSender() == null) {
log.info("[" + getName() + "] has no sender, not sending the result.");
} else {
if (log.isDebugEnabled()) {
log.debug("[" + getName() + "] no replyTo address found or not configured to use replyTo, using default destination" + "sending message with correlationID[" + cid + "] [" + plr.getResult() + "]");
}
getSender().sendMessage(cid, plr.getResult());
}
}
// commit, but no rollback).
if (plr != null && !isTransacted() && isJmsTransacted() && StringUtils.isNotEmpty(getCommitOnState()) && !getCommitOnState().equals(plr.getState())) {
if (session == null) {
log.error(getLogPrefix() + "session is null, cannot roll back session");
} else {
log.warn(getLogPrefix() + "got exit state [" + plr.getState() + "], rolling back session");
session.rollback();
}
}
} catch (Exception e) {
if (e instanceof ListenerException) {
throw (ListenerException) e;
} else {
throw new ListenerException(e);
}
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class XmlJmsBrowserSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queueBrowserElement;
String root = null;
String jmsRealm = null;
String queueConnectionFactoryName = null;
String destinationName = null;
String destinationType = null;
try {
queueBrowserElement = XmlUtils.buildElement(message);
root = queueBrowserElement.getTagName();
jmsRealm = XmlUtils.getChildTagAsString(queueBrowserElement, "jmsRealm");
queueConnectionFactoryName = XmlUtils.getChildTagAsString(queueBrowserElement, "queueConnectionFactoryName");
destinationName = XmlUtils.getChildTagAsString(queueBrowserElement, "destinationName");
destinationType = XmlUtils.getChildTagAsString(queueBrowserElement, "destinationType");
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
}
JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
jmsBrowser.setName("XmlQueueBrowserSender");
if (jmsRealm != null) {
jmsBrowser.setJmsRealm(jmsRealm);
}
if (queueConnectionFactoryName != null) {
jmsBrowser.setQueueConnectionFactoryName(queueConnectionFactoryName);
}
jmsBrowser.setDestinationName(destinationName);
jmsBrowser.setDestinationType(destinationType);
IMessageBrowser browser = jmsBrowser;
IMessageBrowsingIterator it = null;
boolean remove = false;
if (root.equalsIgnoreCase("browse")) {
// OK
} else {
if (root.equalsIgnoreCase("remove")) {
remove = true;
} else {
throw new SenderException(getLogPrefix() + "unknown root element [" + root + "]");
}
}
XmlBuilder result = new XmlBuilder("result");
XmlBuilder items;
if (remove) {
items = new XmlBuilder("itemsRemoved");
} else {
items = new XmlBuilder("items");
}
try {
int count = 0;
it = browser.getIterator();
while (it.hasNext()) {
count++;
JmsMessageBrowserIteratorItem jmsMessageBrowserIteratorItem = (JmsMessageBrowserIteratorItem) it.next();
if (remove) {
jmsBrowser.deleteMessage(jmsMessageBrowserIteratorItem.getJMSMessageID());
} else {
// browse
XmlBuilder item = new XmlBuilder("item");
XmlBuilder timestamp = new XmlBuilder("timestamp");
timestamp.setValue(new java.util.Date(jmsMessageBrowserIteratorItem.getJMSTimestamp()).toString());
item.addSubElement(timestamp);
XmlBuilder messageId = new XmlBuilder("messageId");
messageId.setValue(jmsMessageBrowserIteratorItem.getJMSMessageID());
item.addSubElement(messageId);
XmlBuilder correlationId = new XmlBuilder("correlationId");
correlationId.setValue(jmsMessageBrowserIteratorItem.getCorrelationId());
item.addSubElement(correlationId);
XmlBuilder msg = new XmlBuilder("message");
msg.setCdataValue(jmsMessageBrowserIteratorItem.getText());
item.addSubElement(msg);
items.addSubElement(item);
}
}
if (remove) {
items.setValue(Integer.toString(count));
} else {
items.addAttribute("count", count);
}
result.addSubElement(items);
} catch (ListenerException e) {
throw new SenderException(getLogPrefix() + "got exception browsing messages", e);
} finally {
try {
if (it != null) {
it.close();
}
} catch (ListenerException e) {
log.warn(getLogPrefix() + "exception on closing message browser iterator", e);
}
}
return result.toXML();
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class JmsMessageBrowser method getMessageCount.
public int getMessageCount() throws ListenerException {
QueueBrowser queueBrowser = null;
Session session = null;
try {
session = createSession();
if (StringUtils.isEmpty(getSelector())) {
queueBrowser = session.createBrowser((Queue) getDestination());
} else {
queueBrowser = session.createBrowser((Queue) getDestination(), getSelector());
}
int count = 0;
for (Enumeration enm = queueBrowser.getEnumeration(); enm.hasMoreElements(); enm.nextElement()) {
count++;
}
return count;
} catch (Exception e) {
throw new ListenerException("cannot determin messagecount", e);
} finally {
try {
if (queueBrowser != null) {
queueBrowser.close();
}
} catch (JMSException e) {
throw new ListenerException("error closing queuebrowser", e);
}
closeSession(session);
}
}
Aggregations