Search in sources :

Example 1 with INamedObject

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

the class JmsRealm method copyRealm.

/**
 * copies matching properties to any other class
 */
public void copyRealm(Object destination) {
    String logPrefixDest = destination.getClass().getName() + " ";
    if (destination instanceof INamedObject) {
        INamedObject namedDestination = (INamedObject) destination;
        logPrefixDest += "[" + namedDestination.getName() + "] ";
    }
    try {
        BeanMap thisBeanMap = new BeanMap(this);
        BeanMap destinationBeanMap = new BeanMap(destination);
        Iterator<String> iterator = thisBeanMap.keyIterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            Object value = thisBeanMap.get(key);
            if (value != null && !key.equals("class") && destinationBeanMap.containsKey(key)) {
                PropertyUtils.setProperty(destination, key, value);
            }
        }
    } catch (Exception e) {
        log.error(logPrefixDest + "unable to copy properties of JmsRealm", e);
    }
    log.info(logPrefixDest + "loaded properties from jmsRealm [" + toString() + "]");
}
Also used : BeanMap(org.apache.commons.collections.BeanMap) INamedObject(nl.nn.adapterframework.core.INamedObject) INamedObject(nl.nn.adapterframework.core.INamedObject) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 2 with INamedObject

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

Example 3 with INamedObject

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

the class InputOutputPipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    Object preservedObject = message;
    PipeRunResult pipeRunResult = null;
    INamedObject owner = pipeLine.getOwner();
    IExtendedPipe pe = null;
    if (pipe instanceof IExtendedPipe) {
        pe = (IExtendedPipe) pipe;
    }
    if (pe != null) {
        if (StringUtils.isNotEmpty(pe.getGetInputFromSessionKey())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with contents of sessionKey [" + pe.getGetInputFromSessionKey() + "]");
            message = pipeLineSession.get(pe.getGetInputFromSessionKey());
        }
        if (StringUtils.isNotEmpty(pe.getGetInputFromFixedValue())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing input for pipe [" + pe.getName() + "] with fixed value [" + pe.getGetInputFromFixedValue() + "]");
            message = pe.getGetInputFromFixedValue();
        }
        if ((message == null || StringUtils.isEmpty(message.toString())) && StringUtils.isNotEmpty(pe.getEmptyInputReplacement())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] replacing empty input for pipe [" + pe.getName() + "] with fixed value [" + pe.getEmptyInputReplacement() + "]");
            message = pe.getEmptyInputReplacement();
        }
    }
    if (pipe instanceof FixedForwardPipe) {
        FixedForwardPipe ffPipe = (FixedForwardPipe) pipe;
        pipeRunResult = ffPipe.doInitialPipe(message, pipeLineSession);
    }
    if (pipeRunResult == null) {
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    }
    if (pipeRunResult == null) {
        throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] received null result from pipe [" + pipe.getName() + "]d");
    }
    if (pe != null) {
        if (pe.isRestoreMovedElements()) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] restoring from compacted result for pipe [" + pe.getName() + "]");
            Object result = pipeRunResult.getResult();
            if (result != null) {
                String resultString = (String) result;
                pipeRunResult.setResult(restoreMovedElements(resultString, pipeLineSession));
            }
        }
        if (pe.getChompCharSize() != null || pe.getElementToMove() != null || pe.getElementToMoveChain() != null) {
            log.debug("Pipeline of adapter [" + owner.getName() + "] compact received message");
            Object result = pipeRunResult.getResult();
            if (result != null) {
                String resultString = (String) result;
                try {
                    InputStream xmlInput = IOUtils.toInputStream(resultString, "UTF-8");
                    CompactSaxHandler handler = new CompactSaxHandler();
                    handler.setChompCharSize(pe.getChompCharSize());
                    handler.setElementToMove(pe.getElementToMove());
                    handler.setElementToMoveChain(pe.getElementToMoveChain());
                    handler.setElementToMoveSessionKey(pe.getElementToMoveSessionKey());
                    handler.setRemoveCompactMsgNamespaces(pe.isRemoveCompactMsgNamespaces());
                    handler.setContext(pipeLineSession);
                    SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
                    parserFactory.setNamespaceAware(true);
                    SAXParser saxParser = parserFactory.newSAXParser();
                    try {
                        saxParser.parse(xmlInput, handler);
                        resultString = handler.getXmlString();
                    } catch (Exception e) {
                        log.warn("Pipeline of adapter [" + owner.getName() + "] could not compact received message: " + e.getMessage());
                    }
                    handler = null;
                } catch (Exception e) {
                    throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] got error during compacting received message to more compact format: " + e.getMessage());
                }
                pipeRunResult.setResult(resultString);
            }
        }
        if (StringUtils.isNotEmpty(pe.getStoreResultInSessionKey())) {
            if (log.isDebugEnabled())
                log.debug("Pipeline of adapter [" + owner.getName() + "] storing result for pipe [" + pe.getName() + "] under sessionKey [" + pe.getStoreResultInSessionKey() + "]");
            Object result = pipeRunResult.getResult();
            pipeLineSession.put(pe.getStoreResultInSessionKey(), result);
        }
        if (pe.isPreserveInput()) {
            pipeRunResult.setResult(preservedObject);
        }
    }
    if (pe != null) {
        if (pe.isWriteToSecLog()) {
            String secLogMsg = "adapter [" + owner.getName() + "] pipe [" + pe.getName() + "]";
            if (pe.getSecLogSessionKeys() != null) {
                String sk = "";
                StringTokenizer st = new StringTokenizer(pe.getSecLogSessionKeys(), " ,;");
                while (st.hasMoreTokens()) {
                    if (sk.length() > 0) {
                        sk = sk + ",";
                    }
                    String key = st.nextToken();
                    Object value = pipeLineSession.get(key);
                    sk = sk + key + "=" + value;
                }
                secLogMsg = secLogMsg + " sessionKeys [" + sk + "]";
            }
            secLog.info(secLogMsg);
        }
    }
    return pipeRunResult;
}
Also used : InputStream(java.io.InputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringTokenizer(java.util.StringTokenizer) CompactSaxHandler(nl.nn.adapterframework.util.CompactSaxHandler) INamedObject(nl.nn.adapterframework.core.INamedObject) PipeRunException(nl.nn.adapterframework.core.PipeRunException) SAXParser(javax.xml.parsers.SAXParser) INamedObject(nl.nn.adapterframework.core.INamedObject) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) FixedForwardPipe(nl.nn.adapterframework.pipes.FixedForwardPipe) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

INamedObject (nl.nn.adapterframework.core.INamedObject)3 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringTokenizer (java.util.StringTokenizer)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 Transformer (javax.xml.transform.Transformer)1 IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)1 ParameterException (nl.nn.adapterframework.core.ParameterException)1 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 ParameterList (nl.nn.adapterframework.parameters.ParameterList)1 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)1 FixedForwardPipe (nl.nn.adapterframework.pipes.FixedForwardPipe)1 CompactSaxHandler (nl.nn.adapterframework.util.CompactSaxHandler)1 BeanMap (org.apache.commons.collections.BeanMap)1