Search in sources :

Example 31 with PipeRunResult

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

the class EtagHandlerPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    String uriPatternSessionKey = null;
    ParameterValueList pvl = null;
    ParameterList parameterList = getParameterList();
    if (parameterList != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
            if (pvl != null) {
                for (int i = 0; i < parameterList.size(); i++) {
                    Parameter parameter = parameterList.getParameter(i);
                    if ("uriPattern".equalsIgnoreCase(parameter.getName()))
                        uriPatternSessionKey = (String) parameter.getValue(pvl, prc);
                }
            }
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    // hash over data genereren, uit cache lezen en teruggeven, in cache updaten, verwijderen uit cache, cache naar disk wegschrijven, cache legen
    String cacheKey = null;
    if (uriPatternSessionKey != null && !uriPatternSessionKey.isEmpty())
        cacheKey = getRestPath() + "_" + uriPatternSessionKey.toLowerCase();
    else
        cacheKey = getRestPath() + "_" + getUriPattern();
    if (cache != null && cache.containsKey(cacheKey)) {
        Object returnCode = false;
        if (getAction().equalsIgnoreCase("generate")) {
            cache.put(cacheKey, RestListenerUtils.formatEtag(getRestPath(), getUriPattern(), input.hashCode()));
            returnCode = true;
        } else if (getAction().equalsIgnoreCase("get")) {
            returnCode = cache.get(cacheKey);
        } else if (getAction().equalsIgnoreCase("set")) {
            cache.put(cacheKey, input.toString());
            returnCode = true;
        } else if (getAction().equalsIgnoreCase("delete")) {
            returnCode = cache.remove(cacheKey);
        } else if (getAction().equalsIgnoreCase("flush")) {
            if (cache instanceof ApiEhcache) {
                ((ApiEhcache) cache).flush();
                returnCode = true;
            }
        } else if (getAction().equalsIgnoreCase("clear")) {
            cache.clear();
            returnCode = true;
        } else {
            throw new PipeRunException(this, getLogPrefix(session) + "action not found [" + getAction() + "]");
        }
        if (log.isDebugEnabled())
            log.debug("found eTag cacheKey [" + cacheKey + "] with action [" + getAction() + "]");
        return new PipeRunResult(getForward(), returnCode);
    } else {
        PipeForward pipeForward = findForward("exception");
        String msg;
        if (cache == null)
            msg = "failed to locate cache";
        else
            msg = "failed to locate eTag [" + cacheKey + "] in cache";
        if (pipeForward == null) {
            throw new PipeRunException(this, getLogPrefix(session) + msg);
        }
        return new PipeRunResult(pipeForward, "");
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) ApiEhcache(nl.nn.adapterframework.http.rest.ApiEhcache) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 32 with PipeRunResult

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

the class FileLineIteratorPipe method doPipe.

/**
 * Open a reader for the file named according the input messsage and
 * transform it.
 * Move the input file to a done directory when transformation is finished
 * and return the names of the generated files.
 *
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.IPipeLineSession)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, "got null input instead of String containing filename");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, "expected String containing filename as input, got [" + ClassUtils.nameOf(input) + "], value [" + input + "]");
    }
    String filename = input.toString();
    File file = new File(filename);
    try {
        PipeRunResult result = super.doPipe(file, session);
        if (!StringUtils.isEmpty(getMove2dirAfterTransform())) {
            File move2 = new File(getMove2dirAfterTransform(), file.getName());
            file.renameTo(move2);
        }
        return result;
    } catch (PipeRunException e) {
        if (!StringUtils.isEmpty(getMove2dirAfterError())) {
            File move2 = new File(getMove2dirAfterError(), file.getName());
            file.renameTo(move2);
        }
        throw e;
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) File(java.io.File)

Example 33 with PipeRunResult

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

the class StreamPipeTest method doPipeHttpRequestCheckAntiVirusPassedTest.

@Test
public void doPipeHttpRequestCheckAntiVirusPassedTest() throws Exception {
    StreamPipe streamPipe = new StreamPipe();
    streamPipe.setCheckAntiVirus(true);
    streamPipe.registerForward(createPipeSuccessForward());
    MockMultipartHttpServletRequest request = createMultipartHttpRequest(streamPipe, true);
    streamPipe.addParameter(createHttpRequestParameter(request, session));
    streamPipe.configure();
    PipeRunResult pipeRunResult = streamPipe.doPipe("", session);
    assertEquals("success", pipeRunResult.getPipeForward().getName());
    String expectedResult = "<parts>" + "<part type=\"string\" name=\"string1\" sessionKey=\"part_string\" size=\"19\"/>" + "<part type=\"file\" name=\"doc001.pdf\" sessionKey=\"part_file\" size=\"26358\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>" + "<part type=\"file\" name=\"doc002.pdf\" sessionKey=\"part_file2\" size=\"25879\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>" + "</parts>";
    assertEquals(expectedResult, pipeRunResult.getResult());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) Test(org.junit.Test)

Example 34 with PipeRunResult

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

the class StreamPipeTest method doPipeHttpRequestCheckAntiVirusFailedTest.

@Test
public void doPipeHttpRequestCheckAntiVirusFailedTest() throws Exception {
    StreamPipe streamPipe = new StreamPipe();
    streamPipe.setCheckAntiVirus(true);
    PipeForward pipeAntiVirusFailedForward = new PipeForward();
    pipeAntiVirusFailedForward.setName(StreamPipe.ANTIVIRUS_FAILED_FORWARD);
    streamPipe.registerForward(pipeAntiVirusFailedForward);
    streamPipe.registerForward(createPipeSuccessForward());
    MockMultipartHttpServletRequest request = createMultipartHttpRequest(streamPipe, true, true);
    streamPipe.addParameter(createHttpRequestParameter(request, session));
    streamPipe.configure();
    PipeRunResult pipeRunResult = streamPipe.doPipe("", session);
    assertEquals("antiVirusFailed", pipeRunResult.getPipeForward().getName());
    String expectedResult = "multipart contains file [doc002.pdf] with antivirus status [Fail] and message []";
    assertEquals(expectedResult, pipeRunResult.getResult());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) PipeForward(nl.nn.adapterframework.core.PipeForward) Test(org.junit.Test)

Example 35 with PipeRunResult

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

the class XsltPipeTest method basic.

@Test
public void basic() throws ConfigurationException, PipeStartException, IOException, PipeRunException {
    pipe.setStyleSheetName("/Xslt3/orgchart.xslt");
    pipe.setXslt2(true);
    pipe.configure();
    pipe.start();
    String input = getFile("/Xslt3/employees.xml");
    log.debug("inputfile [" + input + "]");
    String expected = getFile("/Xslt3/orgchart.xml");
    PipeRunResult prr = pipe.doPipe(input, session);
    String xmlOut = (String) prr.getResult();
    assertEquals(expected, xmlOut.trim());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Test(org.junit.Test)

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