use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PullingIfsaProviderListener method getStringFromRawMessage.
/**
* Extracts string from message obtained from {@link #getRawMessage(Map)}. May also extract
* other parameters from the message and put those in the threadContext.
* @return input message for adapter.
*/
public String getStringFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
if (rawMessage instanceof IMessageWrapper) {
return getStringFromWrapper((IMessageWrapper) rawMessage, threadContext);
}
if (rawMessage instanceof IFSAPoisonMessage) {
IFSAPoisonMessage pm = (IFSAPoisonMessage) rawMessage;
IFSAHeader header = pm.getIFSAHeader();
String source;
try {
source = header.getIFSA_Source();
} catch (Exception e) {
source = "unknown due to exeption:" + e.getMessage();
}
return "<poisonmessage>" + " <source>" + source + "</source>" + " <contents>" + XmlUtils.encodeChars(ToStringBuilder.reflectionToString(pm)) + "</contents>" + "</poisonmessage>";
}
TextMessage message = null;
try {
message = (TextMessage) rawMessage;
} catch (ClassCastException e) {
log.warn(getLogPrefix() + "message received was not of type TextMessage, but [" + rawMessage.getClass().getName() + "]", e);
return null;
}
try {
return message.getText();
} catch (JMSException e) {
throw new ListenerException(getLogPrefix(), e);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PullingIfsaProviderListener method afterMessageProcessed.
public void afterMessageProcessed(PipeLineResult plr, Object rawMessage, Map threadContext) throws ListenerException {
try {
if (isJmsTransacted() && !(getMessagingSource().isXaEnabledForSure() && JtaUtil.inTransaction())) {
QueueSession session = (QueueSession) threadContext.get(THREAD_CONTEXT_SESSION_KEY);
try {
session.commit();
} catch (JMSException e) {
log.error(getLogPrefix() + "got error committing the received message", e);
}
if (isSessionsArePooled()) {
threadContext.remove(THREAD_CONTEXT_SESSION_KEY);
releaseSession(session);
}
}
} catch (Exception e) {
log.error(getLogPrefix() + "exception in closing or releasing session", e);
}
// on request-reply send the reply.
if (getMessageProtocolEnum().equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) {
Message originalRawMessage;
if (rawMessage instanceof Message) {
originalRawMessage = (Message) rawMessage;
} else {
originalRawMessage = (Message) threadContext.get(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
}
if (originalRawMessage == null) {
String id = (String) threadContext.get(IPipeLineSession.messageIdKey);
String cid = (String) threadContext.get(IPipeLineSession.businessCorrelationIdKey);
log.warn(getLogPrefix() + "no original raw message found for messageId [" + id + "] correlationId [" + cid + "], cannot send result");
} else {
QueueSession session = getSession(threadContext);
try {
String result = "<exception>no result</exception>";
if (plr != null && plr.getResult() != null) {
result = plr.getResult();
}
sendReply(session, originalRawMessage, result);
} catch (IfsaException e) {
try {
sendReply(session, originalRawMessage, "<exception>" + e.getMessage() + "</exception>");
} catch (IfsaException e2) {
log.warn(getLogPrefix() + "exception sending errormessage as reply", e2);
}
throw new ListenerException(getLogPrefix() + "Exception on sending result", e);
} finally {
releaseSession(session);
}
}
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PushingIfsaProviderListener method getStringFromRawMessage.
/**
* Extracts string from message obtained from {@link #getRawMessage(Map)}. May also extract
* other parameters from the message and put those in the threadContext.
* @return input message for adapter.
*/
public String getStringFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
if (rawMessage instanceof IMessageWrapper) {
return getStringFromWrapper((IMessageWrapper) rawMessage, threadContext);
}
if (rawMessage instanceof IFSAPoisonMessage) {
IFSAPoisonMessage pm = (IFSAPoisonMessage) rawMessage;
IFSAHeader header = pm.getIFSAHeader();
String source;
try {
source = header.getIFSA_Source();
} catch (Exception e) {
source = "unknown due to exeption:" + e.getMessage();
}
return "<poisonmessage>" + " <source>" + source + "</source>" + " <contents>" + XmlUtils.encodeChars(ToStringBuilder.reflectionToString(pm)) + "</contents>" + "</poisonmessage>";
}
TextMessage message = null;
try {
message = (TextMessage) rawMessage;
} catch (ClassCastException e) {
log.warn(getLogPrefix() + "message received was not of type TextMessage, but [" + rawMessage.getClass().getName() + "]", e);
return null;
}
try {
String result = message.getText();
threadContext.put(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY, message);
return result;
} catch (JMSException e) {
throw new ListenerException(getLogPrefix(), e);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class EjbListenerPortConnector method start.
/**
* Start Listener-port to which the Listener is connected.
*
* Sets internal stated to closed=false
*
* @throws nl.nn.adapterframework.core.ListenerException
*/
public void start() throws ListenerException {
try {
if (listenerPortMBean != null) {
getAdminService().invoke(listenerPortMBean, "start", null, null);
// Register again, to be sure, b/c a registration can have been
// removed by some other controlling code.
listenerPortPoller.registerEjbListenerPortConnector(this);
}
closed = false;
} catch (Exception ex) {
throw new ListenerException(ex);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class IfsaEjbBeanBase method processRequest.
protected String processRequest(ServiceRequest request) throws ServiceException {
log.debug(">>> processRequest() Processing IFSA Request, generic handling");
Map threadContext = new HashMap();
try {
// listener.populateThreadContext(request, threadContext, null);
String message = listener.getStringFromRawMessage(request, threadContext);
String cid = listener.getIdFromRawMessage(request, threadContext);
String replyText = listener.getHandler().processRequest(listener, cid, message, threadContext);
if (log.isDebugEnabled()) {
log.debug("processRequest(): ReplyText=[" + replyText + "]");
}
return replyText;
} catch (ListenerException ex) {
log.error(ex, ex);
listener.getExceptionListener().exceptionThrown(listener, ex);
// Do not invoke rollback, but let IFSA take care of that
throw new ServiceException(ex);
} finally {
log.debug("<<< processRequest() finished generic handling");
// listener.destroyThreadContext(threadContext);
}
}
Aggregations