Search in sources :

Example 31 with ListenerException

use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.

the class WebServiceListener method processRequest.

@Override
public String processRequest(String correlationId, String message, Map requestContext) throws ListenerException {
    if (isSoap()) {
        try {
            String request = soapWrapper.getBody(message);
            String result = super.processRequest(correlationId, request, requestContext);
            String reply = soapWrapper.putInEnvelope(result, null);
            return reply;
        } catch (Exception e) {
            throw new ListenerException(e);
        }
    } else {
        return super.processRequest(correlationId, message, requestContext);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 32 with ListenerException

use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.

the class BisJmsListener method prepareReply.

public String prepareReply(String rawReply, Map threadContext) throws ListenerException {
    String originalMessageText = (String) threadContext.get(MESSAGETEXT_KEY);
    String messageBodyNamespace = (String) threadContext.get(MESSAGEBODYNAMESPACE_KEY);
    if (isLayByNamespace() && messageBodyNamespace != null) {
        rawReply = XmlUtils.addRootNamespace(rawReply, messageBodyNamespace);
    }
    String errorCode = null;
    if (StringUtils.isNotEmpty(getErrorCodeSessionKey())) {
        errorCode = (String) threadContext.get(getErrorCodeSessionKey());
    }
    String messageHeader;
    String payload;
    String result;
    try {
        messageHeader = bisUtils.prepareMessageHeader(originalMessageText, isMessageHeaderInSoapBody());
        if (isOmitResult()) {
            result = null;
        } else {
            result = prepareResult(errorCode, threadContext);
        }
        payload = bisUtils.prepareReply(rawReply, isMessageHeaderInSoapBody() ? messageHeader : null, result, isResultInPayload());
    } catch (Exception e) {
        throw new ListenerException(e);
    }
    return super.prepareReply(payload, threadContext, isMessageHeaderInSoapBody() ? null : messageHeader);
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 33 with ListenerException

use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.

the class RestListenerServlet method service.

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String path = request.getPathInfo();
    String restPath = request.getServletPath();
    String body = "";
    if (restPath.contains("rest-public")) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        String headers = request.getHeader("Access-Control-Request-Headers");
        if (headers != null)
            response.setHeader("Access-Control-Allow-Headers", headers);
        response.setHeader("Access-Control-Expose-Headers", "ETag, Content-Disposition");
        String pattern = sd.findMatchingPattern(path);
        if (pattern != null) {
            Map methodConfig = sd.getMethodConfig(pattern, "OPTIONS");
            if (methodConfig == null) {
                // If set, it means the adapter handles the OPTIONS request
                Iterator iter = sd.getAvailableMethods(pattern).iterator();
                StringBuilder sb = new StringBuilder();
                // Append preflight OPTIONS request
                sb.append("OPTIONS");
                while (iter.hasNext()) {
                    sb.append(", ").append(iter.next());
                }
                response.setHeader("Access-Control-Allow-Methods", sb.toString());
                if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
                    response.setStatus(200);
                    // Preflight OPTIONS request should not return any data.
                    return;
                }
            }
        }
    }
    String ifNoneMatch = request.getHeader("If-None-Match");
    String ifMatch = request.getHeader("If-Match");
    String contentType = request.getHeader("accept");
    if (log.isTraceEnabled())
        log.trace("path [" + path + "] If-Match [" + ifMatch + "] If-None-Match [" + ifNoneMatch + "] contentType [" + contentType + "]");
    ISecurityHandler securityHandler = new HttpSecurityHandler(request);
    IPipeLineSession messageContext = new PipeLineSessionBase();
    messageContext.put(IPipeLineSession.securityHandlerKey, securityHandler);
    Enumeration paramnames = request.getParameterNames();
    while (paramnames.hasMoreElements()) {
        String paramname = (String) paramnames.nextElement();
        String paramvalue = request.getParameter(paramname);
        if (log.isTraceEnabled())
            log.trace("setting parameter [" + paramname + "] to [" + paramvalue + "]");
        messageContext.put(paramname, paramvalue);
    }
    if (!ServletFileUpload.isMultipartContent(request)) {
        body = Misc.streamToString(request.getInputStream(), "\n", false);
    }
    try {
        log.trace("RestListenerServlet calling service [" + path + "]");
        String result = sd.dispatchRequest(restPath, path, request, contentType, body, messageContext, response, getServletContext());
        if (result == null && messageContext.containsKey("exitcode") && messageContext.containsKey("validateEtag")) {
            int status = Integer.parseInt("" + messageContext.get("exitcode"));
            response.setStatus(status);
            // TODO: overbodig?
            if (log.isDebugEnabled())
                log.trace("aborted request with status [" + status + "]");
            return;
        }
        String etag = (String) messageContext.get("etag");
        if (StringUtils.isNotEmpty(etag))
            response.setHeader("etag", etag);
        int statusCode = 0;
        if (messageContext.containsKey("exitcode"))
            statusCode = Integer.parseInt("" + messageContext.get("exitcode"));
        if (statusCode > 0)
            response.setStatus(statusCode);
        if (StringUtils.isEmpty(result)) {
            log.trace("RestListenerServlet finished with result set in pipeline");
        } else {
            contentType = (String) messageContext.get("contentType");
            if (StringUtils.isNotEmpty(contentType)) {
                response.setHeader("Content-Type", contentType);
            }
            String contentDisposition = (String) messageContext.get("contentDisposition");
            if (StringUtils.isNotEmpty(contentDisposition)) {
                response.setHeader("Content-Disposition", contentDisposition);
            }
            String allowedMethods = (String) messageContext.get("allowedMethods");
            if (StringUtils.isNotEmpty(allowedMethods)) {
                response.setHeader("Allow", allowedMethods);
            }
            response.getWriter().print(result);
            log.trace("RestListenerServlet finished with result [" + result + "] etag [" + etag + "] contentType [" + contentType + "] contentDisposition [" + contentDisposition + "]");
        }
    } catch (ListenerException e) {
        log.warn("RestListenerServlet caught exception, will rethrow as ServletException", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : ISecurityHandler(nl.nn.adapterframework.core.ISecurityHandler) ListenerException(nl.nn.adapterframework.core.ListenerException) Enumeration(java.util.Enumeration) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 34 with ListenerException

use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.

the class SpringJmsConnector method onMessage.

public void onMessage(Message message, Session session) throws JMSException {
    TransactionStatus txStatus = null;
    long onMessageStart = System.currentTimeMillis();
    long jmsTimestamp = message.getJMSTimestamp();
    threadsProcessing.increase();
    Thread.currentThread().setName(getReceiver().getName() + "[" + threadsProcessing.getValue() + "]");
    try {
        if (TX != null) {
            txStatus = txManager.getTransaction(TX);
        }
        Map threadContext = new HashMap();
        try {
            IPortConnectedListener listener = getListener();
            threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
            // if (log.isDebugEnabled()) log.debug("transaction status before: "+JtaUtil.displayTransactionStatus());
            getReceiver().processRawMessage(listener, message, threadContext);
        // if (log.isDebugEnabled()) log.debug("transaction status after: "+JtaUtil.displayTransactionStatus());
        } catch (ListenerException e) {
            getReceiver().increaseRetryIntervalAndWait(e, getLogPrefix());
            if (txStatus != null) {
                txStatus.setRollbackOnly();
            }
        } finally {
            if (txStatus == null && jmsContainer.isSessionTransacted()) {
                log.debug(getLogPrefix() + "committing JMS session");
                session.commit();
            }
        }
    } finally {
        if (txStatus != null) {
            txManager.commit(txStatus);
        }
        threadsProcessing.decrease();
        if (log.isInfoEnabled()) {
            long onMessageEnd = System.currentTimeMillis();
            log.info(getLogPrefix() + "A) JMSMessageTime [" + DateUtils.format(jmsTimestamp) + "]");
            log.info(getLogPrefix() + "B) onMessageStart [" + DateUtils.format(onMessageStart) + "] diff (~'queing' time) [" + (onMessageStart - jmsTimestamp) + "]");
            log.info(getLogPrefix() + "C) onMessageEnd   [" + DateUtils.format(onMessageEnd) + "] diff (process time) [" + (onMessageEnd - onMessageStart) + "]");
        }
    // boolean simulateCrashAfterCommit=true;
    // if (simulateCrashAfterCommit) {
    // toggle=!toggle;
    // if (toggle) {
    // JtaUtil.setRollbackOnly();
    // throw new JMSException("simulate crash just before final commit");
    // }
    // }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) IPortConnectedListener(nl.nn.adapterframework.core.IPortConnectedListener) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with ListenerException

use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.

the class ReceiverBase method openAllResources.

protected void openAllResources() throws ListenerException {
    // on exit resouces must be in a state that runstate is or can be set to 'STARTED'
    try {
        if (getSender() != null) {
            getSender().open();
        }
        if (getErrorSender() != null) {
            getErrorSender().open();
        }
        if (getErrorStorage() != null) {
            getErrorStorage().open();
        }
        if (getMessageLog() != null) {
            getMessageLog().open();
        }
    } catch (Exception e) {
        throw new ListenerException(e);
    }
    getListener().open();
    throwEvent(RCV_STARTED_RUNNING_MONITOR_EVENT);
    if (getListener() instanceof IPullingListener) {
        // start all threads
        listenerContainer.start();
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) IPullingListener(nl.nn.adapterframework.core.IPullingListener) SenderException(nl.nn.adapterframework.core.SenderException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

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