Search in sources :

Example 16 with ListenerException

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"));
}
Also used : Cookie(javax.servlet.http.Cookie) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) ArrayList(java.util.ArrayList) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) StringTagger(nl.nn.adapterframework.util.StringTagger) ActionForward(org.apache.struts.action.ActionForward) ListenerException(nl.nn.adapterframework.core.ListenerException) JmsMessageBrowser(nl.nn.adapterframework.jms.JmsMessageBrowser) ArrayList(java.util.ArrayList) List(java.util.List) IniDynaActionForm(nl.nn.adapterframework.webcontrol.IniDynaActionForm)

Example 17 with ListenerException

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;
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with ListenerException

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");
        }
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ListenerException(nl.nn.adapterframework.core.ListenerException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 19 with ListenerException

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();
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Guard(nl.nn.adapterframework.util.Guard)

Example 20 with ListenerException

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;
}
Also used : IFSAHeader(com.ing.ifsa.IFSAHeader) ListenerException(nl.nn.adapterframework.core.ListenerException) QueueReceiver(javax.jms.QueueReceiver) INamedObject(nl.nn.adapterframework.core.INamedObject) MessageWrapper(nl.nn.adapterframework.receivers.MessageWrapper) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) QueueSession(javax.jms.QueueSession) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage) IFSATextMessage(com.ing.ifsa.IFSATextMessage)

Aggregations

ListenerException (nl.nn.adapterframework.core.ListenerException)84 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)19 HashMap (java.util.HashMap)18 Map (java.util.Map)18 JMSException (javax.jms.JMSException)16 SenderException (nl.nn.adapterframework.core.SenderException)14 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)11 Session (javax.jms.Session)10 LinkedHashMap (java.util.LinkedHashMap)9 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)9 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)9 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 QueueSession (javax.jms.QueueSession)8 File (java.io.File)7 MessageConsumer (javax.jms.MessageConsumer)7 Message (javax.jms.Message)6