Search in sources :

Example 16 with PipeLineSessionBase

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

use of nl.nn.adapterframework.core.PipeLineSessionBase 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)

Example 18 with PipeLineSessionBase

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

the class InputOutputPipeLineProcessor method processPipeLine.

public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
    if (pipeLineSession == null) {
        pipeLineSession = new PipeLineSessionBase();
    }
    // reset the PipeLineSession and store the message and its id in the session
    if (messageId == null) {
        messageId = Misc.createSimpleUUID();
        log.error("null value for messageId, setting to [" + messageId + "]");
    }
    if (message == null) {
        throw new PipeRunException(null, "Pipeline of adapter [" + pipeLine.getOwner().getName() + "] received null message");
    }
    // store message and messageId in the pipeLineSession
    pipeLineSession.put(IPipeLineSession.originalMessageKey, message);
    pipeLineSession.put(IPipeLineSession.messageIdKey, messageId);
    return pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 19 with PipeLineSessionBase

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

the class CmisHttpSender method invoke.

public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
    // Prepare the message. We will overwrite things later...
    this.headers = headers;
    int responseCode = -1;
    IPipeLineSession pls = new PipeLineSessionBase();
    pls.put("writer", writer);
    pls.put("url", url);
    ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
    try {
        sendMessageWithTimeoutGuarded(null, null, prc);
        return (Response) pls.get("response");
    } catch (Exception e) {
        throw new CmisConnectionException(getUrl(), responseCode, e);
    }
}
Also used : Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 20 with PipeLineSessionBase

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

the class XslErrorMessageFormatter method format.

@Override
public String format(String message, Throwable t, INamedObject location, String originalMessage, String messageId, long receivedTime) {
    String result = super.format(message, t, location, originalMessage, messageId, receivedTime);
    if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) {
        try {
            Transformer errorTransformer;
            if (StringUtils.isNotEmpty(getStyleSheet())) {
                errorTransformer = XmlUtils.createTransformer(ClassUtils.getResourceURL(this, styleSheet));
            } else {
                String xpath = getXpathExpression();
                // if (StringUtils.isEmpty(xpath)) {
                // xpath="/errorMessage/@message";
                // }
                errorTransformer = XmlUtils.createTransformer(XmlUtils.createXPathEvaluatorSource(xpath));
            }
            ParameterList params = getParameterList();
            if (params != null) {
                try {
                    params.configure();
                } catch (ConfigurationException e) {
                    log.error("exception while configuring parameters", e);
                }
                ParameterResolutionContext prc = new ParameterResolutionContext(message, new PipeLineSessionBase());
                Map<String, Object> parametervalues = null;
                try {
                    parametervalues = prc.getValueMap(params);
                } catch (ParameterException e) {
                    log.error("got exception extracting parameters", e);
                }
                XmlUtils.setTransformerParameters(errorTransformer, parametervalues);
            }
            result = XmlUtils.transformXml(errorTransformer, result);
        } catch (IOException e) {
            log.error(" cannot retrieve [" + styleSheet + "]", e);
        } catch (javax.xml.transform.TransformerConfigurationException te) {
            log.error("got error creating transformer from file [" + styleSheet + "]", te);
        } catch (Exception tfe) {
            log.error("could not transform [" + result + "] using stylesheet [" + styleSheet + "]", tfe);
        }
    } else
        log.warn("no stylesheet defined for XslErrorMessageFormatter");
    return result;
}
Also used : Transformer(javax.xml.transform.Transformer) IOException(java.io.IOException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) INamedObject(nl.nn.adapterframework.core.INamedObject) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Aggregations

PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)38 Test (org.junit.Test)14 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)12 IOException (java.io.IOException)8 AbstractXmlValidator (nl.nn.adapterframework.validation.AbstractXmlValidator)8 JavaxXmlValidator (nl.nn.adapterframework.validation.JavaxXmlValidator)8 XercesXmlValidator (nl.nn.adapterframework.validation.XercesXmlValidator)8 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 Iterator (java.util.Iterator)5 Map (java.util.Map)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)5 HashMap (java.util.HashMap)4 ListenerException (nl.nn.adapterframework.core.ListenerException)4 PipeForward (nl.nn.adapterframework.core.PipeForward)4 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 SenderException (nl.nn.adapterframework.core.SenderException)3 ParseException (java.text.ParseException)2