Search in sources :

Example 36 with PipeRunException

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

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

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

the class TestIfsaService method doPost.

private String doPost(IPipeLineSession session) throws PipeRunException {
    Object form_file = session.get("file");
    String form_message = null;
    form_message = (String) session.get("message");
    if (form_file == null && (StringUtils.isEmpty(form_message))) {
        throw new PipeRunException(this, getLogPrefix(session) + "Nothing to send or test");
    }
    String form_applicationId = (String) session.get("applicationId");
    String form_serviceId = (String) session.get("serviceId");
    String form_messageProtocol = (String) session.get("messageProtocol");
    if (form_file != null) {
        if (form_file instanceof InputStream) {
            InputStream inputStream = (InputStream) form_file;
            String form_fileName = (String) session.get("fileName");
            String form_fileEncoding = (String) session.get("fileEncoding");
            try {
                if (inputStream.available() > 0) {
                    String fileEncoding;
                    if (StringUtils.isNotEmpty(form_fileEncoding)) {
                        fileEncoding = form_fileEncoding;
                    } else {
                        fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
                    }
                    if (StringUtils.endsWithIgnoreCase(form_fileName, ".zip")) {
                        try {
                            form_message = processZipFile(session, inputStream, fileEncoding, form_applicationId, form_serviceId, form_messageProtocol);
                        } catch (Exception e) {
                            throw new PipeRunException(this, getLogPrefix(session) + "exception on processing zip file", e);
                        }
                    } else {
                        form_message = Misc.streamToString(inputStream, "\n", fileEncoding, false);
                    }
                }
            } catch (IOException e) {
                throw new PipeRunException(this, getLogPrefix(session) + "exception on converting stream to string", e);
            }
        } else {
            form_message = form_file.toString();
        }
        session.put("message", form_message);
    }
    if (StringUtils.isNotEmpty(form_message)) {
        try {
            String result = processMessage(form_applicationId, form_serviceId, form_messageProtocol, form_message);
            session.put("result", result);
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on sending message", e);
        }
    }
    return "<dummy/>";
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 39 with PipeRunException

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

the class XsltPipeErrorTest method documentNotFound.

@Test
public void documentNotFound() throws Exception {
    // error not during configure(), but during doPipe()
    ErrorOutputStream errorOutputStream = new ErrorOutputStream();
    System.setErr(new PrintStream(errorOutputStream));
    XsltPipe xsltPipe = new XsltPipe();
    xsltPipe.registerForward(createPipeSuccessForward());
    xsltPipe.setStyleSheetName("/Xslt/documentNotFound/root.xsl");
    xsltPipe.setXslt2(false);
    xsltPipe.configure();
    xsltPipe.start();
    String input = getFile("/Xslt/documentNotFound/in.xml");
    String errorMessage = null;
    try {
        xsltPipe.doPipe(input, session);
    } catch (PipeRunException e) {
        errorMessage = e.getMessage();
    }
    assertEquals(true, errorOutputStream.isEmpty());
    assertEquals(0, testAppender.getNumberOfAlerts());
    assertEquals(true, errorMessage.contains("java.io.FileNotFoundException"));
}
Also used : PrintStream(java.io.PrintStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Test(org.junit.Test)

Example 40 with PipeRunException

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

the class Json2WsdlXmlValidatorTest method validatePlainText.

public void validatePlainText(String input, String expectedError) throws Exception {
    String wsdl = "/GetPolicyDetailsTravel/wsdl/GetPolicyDetailsTravel.wsdl";
    String soapBody = "GetPolicyDetailsTravel_Response";
    WsdlXmlValidator val = new WsdlXmlValidator();
    val.setWsdl(wsdl);
    val.setThrowException(true);
    val.registerForward(new PipeForward("success", null));
    val.setSoapBody(soapBody);
    val.configure();
    PipeRunResult result;
    try {
        result = val.doPipe(input, session);
        String resultStr = (String) result.getResult();
        fail("expected error [" + expectedError + "]");
    } catch (PipeRunException e) {
        String msg = e.getMessage();
        if (msg == null || msg.indexOf(expectedError) < 0) {
            fail("expected [" + expectedError + "] in error message, but was [" + msg + "]");
        }
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeForward(nl.nn.adapterframework.core.PipeForward)

Aggregations

PipeRunException (nl.nn.adapterframework.core.PipeRunException)101 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)65 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)40 IOException (java.io.IOException)34 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)32 PipeForward (nl.nn.adapterframework.core.PipeForward)20 ParameterException (nl.nn.adapterframework.core.ParameterException)16 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)13 Parameter (nl.nn.adapterframework.parameters.Parameter)12 InputStream (java.io.InputStream)10 File (java.io.File)9 Map (java.util.Map)9 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 PipeStartException (nl.nn.adapterframework.core.PipeStartException)6 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5