use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class BrowseQueueExecute method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
// -------------------------------
if (isCancelled(request)) {
log.debug("browseQueue was cancelled");
removeFormBean(mapping, request);
return (mapping.findForward("cancel"));
}
// Retrieve form content
// ---------------------
IniDynaActionForm browseQueueForm = (IniDynaActionForm) form;
String form_jmsRealm = (String) browseQueueForm.get("jmsRealm");
String form_destinationName = (String) browseQueueForm.get("destinationName");
String form_destinationType = (String) browseQueueForm.get("destinationType");
boolean form_numberOfMessagesOnly = false;
boolean form_showPayload = false;
if (browseQueueForm.get("numberOfMessagesOnly") != null)
form_numberOfMessagesOnly = ((Boolean) browseQueueForm.get("numberOfMessagesOnly")).booleanValue();
if (browseQueueForm.get("showPayload") != null)
form_showPayload = ((Boolean) browseQueueForm.get("showPayload")).booleanValue();
// initiate MessageSender
JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
jmsBrowser.setName("BrowseQueueAction");
jmsBrowser.setJmsRealm(form_jmsRealm);
jmsBrowser.setDestinationName(form_destinationName);
jmsBrowser.setDestinationType(form_destinationType);
IMessageBrowser browser = jmsBrowser;
IMessageBrowsingIterator it = null;
try {
it = browser.getIterator();
List messages = new ArrayList();
while (it.hasNext()) {
messages.add(it.next());
}
log.debug("Browser returned " + messages.size() + " messages");
browseQueueForm.set("numberOfMessages", Integer.toString(messages.size()));
if (!form_numberOfMessagesOnly) {
/*
try {
for (int i = 0; i < messages.size(); i++) {
Message msg = (Message) messages.get(i);
if (msg instanceof TextMessage) {
TextMessage tm = (TextMessage) msg;
if (log.isDebugEnabled())
log.debug("Found message " + tm.getText());
}
}
} catch (JMSException je) {
log.error(je);
errors.add(
"",
new ActionError(
"errors.generic",
"error occured browsing messages:" + je.getMessage()));
}
*/
browseQueueForm.set("messages", messages);
} else
browseQueueForm.set("messages", new ArrayList());
} catch (ListenerException e) {
error("Error occured browsing messages", e);
} finally {
try {
if (it != null) {
it.close();
}
} catch (ListenerException e1) {
log.error(e1);
}
}
// Report any errors we have discovered back to the original form
if (!errors.isEmpty()) {
StoreFormData(browseQueueForm);
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Successfull: store cookie
String cookieValue = "";
cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
// separator
cookieValue += " ";
cookieValue += "destinationName=\"" + form_destinationName + "\"";
// separator
cookieValue += " ";
cookieValue += "destinationType=\"" + form_destinationType + "\"";
// separator
cookieValue += " ";
cookieValue += "showPayload=\"" + form_showPayload + "\"";
log.debug("*** value : " + AppConstants.getInstance().getString("WEB_QBROWSECOOKIE_NAME", "WEB_QBROWSECOOKIE"));
Cookie sendJmsCookie = new Cookie(AppConstants.getInstance().getString("WEB_QBROWSECOOKIE_NAME", "WEB_QBROWSECOOKIE"), cookieValue);
sendJmsCookie.setMaxAge(Integer.MAX_VALUE);
log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + sendJmsCookie.getName() + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
try {
response.addCookie(sendJmsCookie);
} catch (Throwable e) {
log.warn("unable to add cookie to request. cookie value [" + sendJmsCookie.getValue() + "]");
}
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class CoreListenerProcessor method getMessage.
public String getMessage(ICorrelatedPullingListener listener, String correlationID, IPipeLineSession pipeLineSession) throws ListenerException, TimeOutException {
if (log.isDebugEnabled()) {
log.debug(getLogPrefix(listener, pipeLineSession) + "starts listening for return message with correlationID [" + correlationID + "]");
}
String result;
Map threadContext = new HashMap();
try {
threadContext = listener.openThread();
Object msg = listener.getRawMessage(correlationID, threadContext);
if (msg == null) {
log.info(getLogPrefix(listener, pipeLineSession) + "received null reply message");
} else {
log.info(getLogPrefix(listener, pipeLineSession) + "received reply message");
}
result = listener.getStringFromRawMessage(msg, threadContext);
} finally {
try {
log.debug(getLogPrefix(listener, pipeLineSession) + "is closing");
listener.closeThread(threadContext);
} catch (ListenerException le) {
log.error(getLogPrefix(listener, pipeLineSession) + "got error on closing", le);
}
}
return result;
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class PostboxRetrieverPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (!(input instanceof String)) {
throw new PipeRunException(this, "String expected, got a [" + input.getClass().getName() + "]");
}
Map threadContext = null;
try {
threadContext = getListener().openThread();
Object rawMessage = getListener().retrieveRawMessage((String) input, threadContext);
if (rawMessage == null)
return new PipeRunResult(findForward("emptyPostbox"), getResultOnEmptyPostbox());
String result = getListener().getStringFromRawMessage(rawMessage, threadContext);
return new PipeRunResult(getForward(), result);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "caught exception", e);
} finally {
try {
getListener().closeThread(threadContext);
} catch (ListenerException le) {
log.error(getLogPrefix(session) + "got error closing listener");
}
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class IsolatedServiceCaller method callServiceIsolated.
public String callServiceIsolated(String serviceName, String correlationID, String message, HashMap context, boolean targetIsJavaListener) throws ListenerException {
Guard guard = new Guard();
guard.addResource();
IsolatedServiceExecutor ise = new IsolatedServiceExecutor(serviceName, correlationID, message, context, targetIsJavaListener, guard);
getTaskExecutor().execute(ise);
try {
guard.waitForAllResources();
} catch (InterruptedException e) {
throw new ListenerException(ClassUtils.nameOf(this) + " was interupted", e);
}
if (ise.getThrowable() != null) {
if (ise.getThrowable() instanceof ListenerException) {
throw (ListenerException) ise.getThrowable();
} else {
throw new ListenerException(ise.getThrowable());
}
} else {
return (String) ise.getReply();
}
}
use of nl.nn.adapterframework.core.ListenerException 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;
}
Aggregations