Search in sources :

Example 1 with IPipeLineSession

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

the class LdapSender method storeLdapException.

public void storeLdapException(Throwable t, ParameterResolutionContext prc) {
    IPipeLineSession pls = null;
    if (prc != null) {
        pls = prc.getSession();
    }
    if (StringUtils.isNotEmpty(getErrorSessionKey()) && pls != null && t != null) {
        XmlBuilder ldapError = new XmlBuilder("ldapError");
        ldapError.addAttribute("class", ClassUtils.nameOf(t));
        String message = t.getMessage();
        int magicPos = message.indexOf(LDAP_ERROR_MAGIC_STRING);
        if (magicPos >= 0) {
            int dashPos = message.indexOf('-', magicPos);
            if (dashPos > magicPos) {
                String codeString = message.substring(magicPos + LDAP_ERROR_MAGIC_STRING.length(), dashPos).trim();
                ldapError.addAttribute("code", codeString);
                int bracketPos = message.indexOf(']', dashPos);
                if (bracketPos > dashPos) {
                    String description = message.substring(dashPos + 1, bracketPos).trim();
                    ldapError.addAttribute("description", description);
                    String msgPart1 = message.substring(0, magicPos).trim();
                    String msgPart2 = message.substring(bracketPos + 1).trim();
                    if (msgPart1.endsWith(":")) {
                        msgPart1 = msgPart1.substring(0, msgPart1.length() - 1).trim();
                    }
                    if (msgPart2.startsWith(";")) {
                        msgPart2 = msgPart2.substring(1).trim();
                    }
                    message = (msgPart1 + " " + msgPart2).trim();
                }
            }
        }
        ldapError.setValue(message);
        String reasonXml = ldapError.toXML();
        if (log.isDebugEnabled()) {
            log.debug("sessionKey [" + getErrorSessionKey() + "] loaded with error message [" + reasonXml + "]");
        }
        pls.put(getErrorSessionKey(), reasonXml);
    }
    log.debug("exit storeLdapException");
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Example 2 with IPipeLineSession

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

the class TestPipeLine method processMessage.

private PipeLineResult processMessage(IAdapter adapter, String message, boolean writeSecLogMessage) {
    String messageId = "testmessage" + Misc.createSimpleUUID();
    IPipeLineSession pls = new PipeLineSessionBase();
    Map ibisContexts = XmlUtils.getIbisContext(message);
    String technicalCorrelationId = null;
    if (ibisContexts != null) {
        String contextDump = "ibisContext:";
        for (Iterator it = ibisContexts.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            String value = (String) ibisContexts.get(key);
            if (log.isDebugEnabled()) {
                contextDump = contextDump + "\n " + key + "=[" + value + "]";
            }
            if (key.equals(IPipeLineSession.technicalCorrelationIdKey)) {
                technicalCorrelationId = value;
            } else {
                pls.put(key, value);
            }
        }
        if (log.isDebugEnabled()) {
            log.debug(contextDump);
        }
    }
    Date now = new Date();
    PipeLineSessionBase.setListenerParameters(pls, messageId, technicalCorrelationId, now, now);
    if (writeSecLogMessage) {
        secLog.info("message [" + message + "]");
    }
    // Temporarily change threadName so logging for pipeline to test will
    // not be suppressed (see property 'log.thread.rejectRegex')
    String ctName = Thread.currentThread().getName();
    String ntName = StringUtils.replace(ctName, "WebControlTestPipeLine", "WCTestPipeLine");
    try {
        Thread.currentThread().setName(ntName);
        return adapter.processMessage(messageId, message, pls);
    } finally {
        Thread.currentThread().setName(ctName);
    }
}
Also used : Iterator(java.util.Iterator) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) Map(java.util.Map) Date(java.util.Date) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 3 with IPipeLineSession

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

the class HttpListenerServlet method invoke.

public void invoke(String message, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    ISecurityHandler securityHandler = new HttpSecurityHandler(request);
    IPipeLineSession messageContext = new PipeLineSessionBase();
    messageContext.put(IPipeLineSession.securityHandlerKey, securityHandler);
    messageContext.put("httpListenerServletRequest", request);
    messageContext.put("httpListenerServletResponse", response);
    String service = request.getParameter(SERVICE_ID_PARAM);
    Enumeration paramnames = request.getParameterNames();
    while (paramnames.hasMoreElements()) {
        String paramname = (String) paramnames.nextElement();
        String paramvalue = request.getParameter(paramname);
        if (log.isDebugEnabled()) {
            log.debug("HttpListenerServlet setting parameter [" + paramname + "] to [" + paramvalue + "]");
        }
        messageContext.put(paramname, paramvalue);
    }
    try {
        log.debug("HttpListenerServlet calling service [" + service + "]");
        String result = sd.dispatchRequest(service, null, message, messageContext);
        response.getWriter().print(result);
    } catch (ListenerException e) {
        log.warn("HttpListenerServlet 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) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 4 with IPipeLineSession

use of nl.nn.adapterframework.core.IPipeLineSession 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 5 with IPipeLineSession

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

the class ServiceClassLoader method reload.

@Override
public void reload() throws ConfigurationException {
    super.reload();
    if (adapterName == null) {
        throw new ConfigurationException("Name of adapter to provide configuration jar not specified");
    }
    IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
    if (adapter != null) {
        IPipeLineSession pipeLineSession = new PipeLineSessionBase();
        PipeLineResult processResult = adapter.processMessage(getCorrelationId(), configurationName, pipeLineSession);
        Object object = pipeLineSession.get("configurationJar");
        if (object != null) {
            if (object instanceof byte[]) {
                readResources((byte[]) object, configurationName);
            } else {
                throw new ConfigurationException("SessionKey configurationJar not a byte array");
            }
        } else {
            throw new ConfigurationException("SessionKey configurationJar not found");
        }
    } else {
        throw new ConfigurationException("Could not find adapter: " + adapterName);
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Aggregations

IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)20 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)12 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)7 SenderException (nl.nn.adapterframework.core.SenderException)6 IOException (java.io.IOException)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 ParameterException (nl.nn.adapterframework.core.ParameterException)3 PipeForward (nl.nn.adapterframework.core.PipeForward)3 TimeOutException (nl.nn.adapterframework.core.TimeOutException)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 TibjmsAdmin (com.tibco.tibjms.admin.TibjmsAdmin)2 TibjmsAdminException (com.tibco.tibjms.admin.TibjmsAdminException)2 Enumeration (java.util.Enumeration)2 Connection (javax.jms.Connection)2