Search in sources :

Example 16 with PipeLineSession

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

the class IbisObjectService method getObjectByPath.

@Override
public ObjectData getObjectByPath(String repositoryId, String path, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extension) {
    if (!eventDispatcher.contains(CmisEvent.GET_OBJECT_BY_PATH)) {
        return objectService.getObjectByPath(repositoryId, path, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, extension);
    } else {
        XmlBuilder cmisXml = new XmlBuilder("cmis");
        cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
        cmisXml.addSubElement(buildXml("path", path));
        cmisXml.addSubElement(buildXml("filter", filter));
        cmisXml.addSubElement(buildXml("includeAllowableActions", includeAllowableActions));
        cmisXml.addSubElement(buildXml("includeRelationships", includeRelationships));
        cmisXml.addSubElement(buildXml("renditionFilter", renditionFilter));
        cmisXml.addSubElement(buildXml("includePolicyIds", includePolicyIds));
        cmisXml.addSubElement(buildXml("includeAcl", includeAcl));
        PipeLineSession context = new PipeLineSession();
        context.put(CmisUtils.CMIS_CALLCONTEXT_KEY, callContext);
        Element cmisElement = eventDispatcher.trigger(CmisEvent.GET_OBJECT_BY_PATH, cmisXml.toXML(), context);
        return CmisUtils.xml2ObjectData(cmisElement, context);
    }
}
Also used : Element(org.w3c.dom.Element) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession)

Example 17 with PipeLineSession

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

the class XslErrorMessageFormatter method format.

@Override
public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) {
    Message result = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime);
    if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) {
        try {
            Transformer errorTransformer;
            if (StringUtils.isNotEmpty(getStyleSheet())) {
                URL url = ClassUtils.getResourceURL(this, styleSheet);
                errorTransformer = XmlUtils.createTransformer(url);
            } 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);
                }
                Map<String, Object> parametervalues = null;
                try {
                    parametervalues = params.getValues(new Message(errorMessage), new PipeLineSession()).getValueMap();
                } catch (ParameterException e) {
                    log.error("got exception extracting parameters", e);
                }
                XmlUtils.setTransformerParameters(errorTransformer, parametervalues);
            }
            result = new Message(XmlUtils.transformXml(errorTransformer, result.asSource()));
        } 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) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) URL(java.net.URL) 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)

Example 18 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession 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);
    try (PipeLineSession messageContext = new PipeLineSession()) {
        messageContext.setSecurityHandler(securityHandler);
        messageContext.put("httpListenerServletRequest", request);
        messageContext.put("httpListenerServletResponse", response);
        String service = request.getParameter(SERVICE_ID_PARAM);
        Enumeration<String> paramnames = request.getParameterNames();
        while (paramnames.hasMoreElements()) {
            String paramname = 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) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession)

Example 19 with PipeLineSession

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

the class RestListenerServlet method service.

@Override
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", CorsAllowOrigin);
        String headers = request.getHeader("Access-Control-Request-Headers");
        if (headers != null)
            response.setHeader("Access-Control-Allow-Headers", headers);
        response.setHeader("Access-Control-Expose-Headers", CorsExposeHeaders);
        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);
    try (PipeLineSession messageContext = new PipeLineSession()) {
        messageContext.setSecurityHandler(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) {
            if (!response.isCommitted()) {
                log.warn("RestListenerServlet caught exception, return internal server error", e);
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
            } else {
                log.warn("RestListenerServlet caught exception, response already committed", e);
                throw new ServletException("RestListenerServlet caught exception, response already committed", e);
            }
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) ISecurityHandler(nl.nn.adapterframework.core.ISecurityHandler) ListenerException(nl.nn.adapterframework.core.ListenerException) Enumeration(java.util.Enumeration) Iterator(java.util.Iterator) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Map(java.util.Map)

Example 20 with PipeLineSession

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

the class JmsSender method sendMessage.

public Message sendMessage(Message message, PipeLineSession session, String soapHeader) throws SenderException, TimeoutException {
    Session s = null;
    MessageProducer mp = null;
    String correlationID = session == null ? null : session.getMessageId();
    ParameterValueList pvl = null;
    if (paramList != null) {
        try {
            pvl = paramList.getValues(message, session);
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "cannot extract parameters", e);
        }
    }
    try {
        if (isSoap()) {
            if (soapHeader == null) {
                if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) {
                    ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam());
                    if (soapHeaderParamValue == null) {
                        log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]");
                    } else {
                        soapHeader = soapHeaderParamValue.asStringValue("");
                    }
                }
            }
            message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader);
            if (log.isDebugEnabled())
                log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]");
        }
        s = createSession();
        mp = getMessageProducer(s, getDestination(session, pvl));
        Destination replyQueue = null;
        // create message
        javax.jms.Message msg = createMessage(s, correlationID, message);
        if (getMessageType() != null) {
            msg.setJMSType(getMessageType());
        }
        if (getDeliveryMode() != DeliveryMode.NOT_SET) {
            msg.setJMSDeliveryMode(getDeliveryMode().getDeliveryMode());
            mp.setDeliveryMode(getDeliveryMode().getDeliveryMode());
        }
        if (getPriority() >= 0) {
            msg.setJMSPriority(getPriority());
            mp.setPriority(getPriority());
        }
        // set properties
        if (pvl != null) {
            setProperties(msg, pvl);
        }
        if (getReplyToName() != null) {
            replyQueue = getDestination(getReplyToName());
        } else {
            if (isSynchronous()) {
                replyQueue = getMessagingSource().getDynamicReplyQueue(s);
            }
        }
        if (replyQueue != null) {
            msg.setJMSReplyTo(replyQueue);
            if (log.isDebugEnabled())
                log.debug("replyTo set to queue [" + replyQueue.toString() + "]");
        }
        // send message
        send(mp, msg);
        if (log.isDebugEnabled()) {
            log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((getReplyToName() != null) ? "replyTo [" + getReplyToName() + "]" : ""));
        } else {
            if (log.isInfoEnabled()) {
                log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((getReplyToName() != null) ? "replyTo [" + getReplyToName() + "]" : ""));
            }
        }
        if (isSynchronous()) {
            String replyCorrelationId = null;
            if (getReplyToName() != null) {
                switch(getLinkMethod()) {
                    case MESSAGEID:
                        replyCorrelationId = msg.getJMSMessageID();
                        break;
                    case CORRELATIONID:
                        replyCorrelationId = correlationID;
                        break;
                    case CORRELATIONID_FROM_MESSAGE:
                        replyCorrelationId = msg.getJMSCorrelationID();
                        break;
                    default:
                        throw new IllegalStateException("unknown linkMethod [" + getLinkMethod() + "]");
                }
            }
            if (log.isDebugEnabled())
                log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms");
            MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId);
            try {
                javax.jms.Message rawReplyMsg = mc.receive(getReplyTimeout());
                if (rawReplyMsg == null) {
                    throw new TimeoutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms");
                }
                if (getResponseHeadersList().size() > 0) {
                    Enumeration<?> propertyNames = rawReplyMsg.getPropertyNames();
                    while (propertyNames.hasMoreElements()) {
                        String jmsProperty = (String) propertyNames.nextElement();
                        if (getResponseHeadersList().contains(jmsProperty)) {
                            session.put(jmsProperty, rawReplyMsg.getObjectProperty(jmsProperty));
                        }
                    }
                }
                return extractMessage(rawReplyMsg, session, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper);
            } finally {
                if (mc != null) {
                    try {
                        mc.close();
                    } catch (JMSException e) {
                        log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e);
                    }
                }
            }
        }
        return new Message(msg.getJMSMessageID());
    } catch (JMSException e) {
        throw new SenderException(e);
    } catch (IOException e) {
        throw new SenderException(e);
    } catch (NamingException e) {
        throw new SenderException(e);
    } catch (SAXException e) {
        throw new SenderException(e);
    } catch (TransformerException e) {
        throw new SenderException(e);
    } catch (JmsException e) {
        throw new SenderException(e);
    } finally {
        if (mp != null) {
            try {
                mp.close();
            } catch (JMSException e) {
                log.warn("JmsSender [" + getName() + "] got exception closing message producer", e);
            }
        }
        closeSession(s);
    }
}
Also used : Destination(javax.jms.Destination) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) MessageConsumer(javax.jms.MessageConsumer) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) Message(nl.nn.adapterframework.stream.Message) JMSException(javax.jms.JMSException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ParameterException(nl.nn.adapterframework.core.ParameterException) NamingException(javax.naming.NamingException) MessageProducer(javax.jms.MessageProducer) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Session(javax.jms.Session) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Aggregations

PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)270 Message (nl.nn.adapterframework.stream.Message)210 Test (org.junit.Test)202 SenderException (nl.nn.adapterframework.core.SenderException)43 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)33 UrlMessage (nl.nn.adapterframework.stream.UrlMessage)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 IOException (java.io.IOException)25 Parameter (nl.nn.adapterframework.parameters.Parameter)23 PipeForward (nl.nn.adapterframework.core.PipeForward)21 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)17 Date (java.util.Date)15 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)14 InputStream (java.io.InputStream)11 TimeoutException (nl.nn.adapterframework.core.TimeoutException)11 ParameterList (nl.nn.adapterframework.parameters.ParameterList)11 Map (java.util.Map)10 SimpleDateFormat (java.text.SimpleDateFormat)9 SOAPMessage (javax.xml.soap.SOAPMessage)9 URL (java.net.URL)8