Search in sources :

Example 81 with PipeRunResult

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

Example 82 with PipeRunResult

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

the class LockerPipeProcessor method processPipe.

public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
    PipeRunResult pipeRunResult;
    IExtendedPipe extendedPipe = null;
    Locker locker = null;
    String objectId = null;
    if (pipe instanceof IExtendedPipe) {
        extendedPipe = (IExtendedPipe) pipe;
        locker = extendedPipe.getLocker();
    }
    if (locker != null) {
        try {
            objectId = locker.lock();
        } catch (Exception e) {
            throw new PipeRunException(pipe, "error while setting lock", e);
        }
    }
    if (objectId != null) {
        try {
            pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
        } finally {
            try {
                locker.unlock(objectId);
            } catch (Exception e) {
                throw new PipeRunException(pipe, "error while removing lock", e);
            }
        }
    } else {
        pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
    }
    return pipeRunResult;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Locker(nl.nn.adapterframework.util.Locker) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) PipeRunException(nl.nn.adapterframework.core.PipeRunException)

Example 83 with PipeRunResult

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

the class ShowConfigurationStatusTest method testAllConfigs.

@Test
public void testAllConfigs() throws ConfigurationException, PipeRunException, DomBuilderException, SAXException, IOException, TransformerException {
    ShowConfigurationStatus showConfigurationStatus = new ShowConfigurationStatus();
    PipeLine pipeLine = new PipeLine();
    Adapter adapter = (Adapter) ibisContext.getIbisManager().getRegisteredAdapter("WebControlShowConfigurationStatus");
    pipeLine.setAdapter(adapter);
    showConfigurationStatus.registerForward(createPipeSuccessForward());
    showConfigurationStatus.configure(pipeLine);
    session.put("configuration", "*ALL*");
    MockHttpServletRequest request = new MockHttpServletRequest();
    session.put(IPipeLineSession.HTTP_REQUEST_KEY, request);
    PipeRunResult pipeRunResult = showConfigurationStatus.doPipe(null, session);
    compareXML("webcontrol/allConfigs.xml", (String) pipeRunResult.getResult());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) Test(org.junit.Test)

Example 84 with PipeRunResult

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

the class Json2XmlValidatorSmileyTest method xmlToJsonViaPipe.

public String xmlToJsonViaPipe(String xml) throws ConfigurationException, PipeStartException, PipeRunException {
    Json2XmlValidator json2xml = new Json2XmlValidator();
    json2xml.setWarn(false);
    json2xml.setSchema(xsd);
    json2xml.setRoot("x");
    json2xml.setOutputFormat(json2xml.FORMAT_JSON);
    json2xml.setThrowException(true);
    json2xml.registerForward(new PipeForward("success", null));
    json2xml.configure();
    json2xml.start();
    IPipeLineSession pipeLineSession = new PipeLineSessionBase();
    PipeRunResult prr = json2xml.doPipe(xml, pipeLineSession);
    return (String) prr.getResult();
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Json2XmlValidator(nl.nn.adapterframework.pipes.Json2XmlValidator) PipeForward(nl.nn.adapterframework.core.PipeForward) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 85 with PipeRunResult

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

the class Json2XmlValidatorSmileyTest method jsonToXmlViaPipe.

public String jsonToXmlViaPipe(String json) throws ConfigurationException, PipeStartException, PipeRunException {
    Json2XmlValidator json2xml = new Json2XmlValidator();
    json2xml.setWarn(false);
    json2xml.setSchema(xsd);
    json2xml.setRoot("x");
    json2xml.setThrowException(true);
    json2xml.registerForward(new PipeForward("success", null));
    json2xml.configure();
    json2xml.start();
    IPipeLineSession pipeLineSession = new PipeLineSessionBase();
    PipeRunResult prr = json2xml.doPipe(json, pipeLineSession);
    return (String) prr.getResult();
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Json2XmlValidator(nl.nn.adapterframework.pipes.Json2XmlValidator) PipeForward(nl.nn.adapterframework.core.PipeForward) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Aggregations

PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)89 PipeRunException (nl.nn.adapterframework.core.PipeRunException)65 PipeForward (nl.nn.adapterframework.core.PipeForward)23 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)22 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)21 IOException (java.io.IOException)17 ParameterException (nl.nn.adapterframework.core.ParameterException)14 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)11 Test (org.junit.Test)11 File (java.io.File)10 Map (java.util.Map)10 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 InputStream (java.io.InputStream)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 Parameter (nl.nn.adapterframework.parameters.Parameter)6 FileInputStream (java.io.FileInputStream)4 StringReader (java.io.StringReader)4 Iterator (java.util.Iterator)4 StringTokenizer (java.util.StringTokenizer)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4