Search in sources :

Example 11 with PipeForward

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

the class Json2XmlValidator method alignJson.

protected PipeRunResult alignJson(String messageToValidate, IPipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException {
    ValidationContext context;
    ValidatorHandler validatorHandler;
    try {
        context = validator.createValidationContext(session, getRootValidations(responseMode), getInvalidRootNamespaces());
        validatorHandler = validator.getValidatorHandler(session, context);
    } catch (ConfigurationException e) {
        throw new PipeRunException(this, "Cannot create ValidationContext", e);
    }
    String resultEvent;
    String out = null;
    try {
        Json2Xml aligner = new Json2Xml(validatorHandler, context.getXsModels(), isCompactJsonArrays(), getMessageRoot(responseMode), isStrictJsonArraySyntax());
        if (StringUtils.isNotEmpty(getTargetNamespace())) {
            aligner.setTargetNamespace(getTargetNamespace());
        }
        aligner.setDeepSearch(isDeepSearch());
        aligner.setErrorHandler(context.getErrorHandler());
        aligner.setFailOnWildcards(isFailOnWildcards());
        ParameterList parameterList = getParameterList();
        if (parameterList != null) {
            ParameterResolutionContext prc = new ParameterResolutionContext(messageToValidate, session, isNamespaceAware(), false);
            Map<String, Object> parametervalues = null;
            parametervalues = prc.getValueMap(parameterList);
            aligner.setOverrideValues(parametervalues);
        }
        JsonStructure jsonStructure = Json.createReader(new StringReader(messageToValidate)).read();
        if (getOutputFormat(session, responseMode).equalsIgnoreCase(FORMAT_JSON)) {
            Xml2Json xml2json = new Xml2Json(aligner, isCompactJsonArrays(), !isJsonWithRootElements());
            aligner.setContentHandler(xml2json);
            aligner.startParse(jsonStructure);
            out = xml2json.toString();
        } else {
            Source source = aligner.asSource(jsonStructure);
            out = XmlUtils.source2String(source, isProduceNamespaceLessXml());
        }
    } catch (Exception e) {
        resultEvent = validator.finalizeValidation(context, session, e);
    }
    resultEvent = validator.finalizeValidation(context, session, null);
    PipeForward forward = determineForward(resultEvent, session, responseMode);
    PipeRunResult result = new PipeRunResult(forward, out);
    return result;
}
Also used : ValidatorHandler(javax.xml.validation.ValidatorHandler) PipeForward(nl.nn.adapterframework.core.PipeForward) Source(javax.xml.transform.Source) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException) ValidationContext(nl.nn.adapterframework.validation.ValidationContext) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) ParameterList(nl.nn.adapterframework.parameters.ParameterList) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Xml2Json(nl.nn.adapterframework.align.Xml2Json) Json2Xml(nl.nn.adapterframework.align.Json2Xml) JsonStructure(javax.json.JsonStructure)

Example 12 with PipeForward

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

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

the class StreamPipeTest method createPipeSuccessForward.

private PipeForward createPipeSuccessForward() {
    PipeForward pipeForward = new PipeForward();
    pipeForward.setName("success");
    return pipeForward;
}
Also used : PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 14 with PipeForward

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

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

the class WsdlXmlValidatorMixedModeTest method getOutputValidator.

public WsdlXmlValidator getOutputValidator() throws ConfigurationException {
    WsdlXmlValidator val = new ApiWsdlXmlValidator();
    val.setWsdl(WSDL);
    val.setSoapBody(RESPONSE_SOAP_BODY);
    val.setThrowException(true);
    val.setSchemaLocation("http://ibissource.org/XSD/Generic/MessageHeader/2 schema1 http://api.ibissource.org/GetPolicyDetails schema2");
    val.registerForward(new PipeForward("success", null));
    val.configure();
    return val;
}
Also used : ApiWsdlXmlValidator(nl.nn.adapterframework.extensions.api.ApiWsdlXmlValidator) PipeForward(nl.nn.adapterframework.core.PipeForward) ApiWsdlXmlValidator(nl.nn.adapterframework.extensions.api.ApiWsdlXmlValidator)

Aggregations

PipeForward (nl.nn.adapterframework.core.PipeForward)49 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)23 PipeRunException (nl.nn.adapterframework.core.PipeRunException)21 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)10 Test (org.junit.Test)8 IOException (java.io.IOException)7 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)7 ParameterException (nl.nn.adapterframework.core.ParameterException)6 ParameterList (nl.nn.adapterframework.parameters.ParameterList)6 IPipe (nl.nn.adapterframework.core.IPipe)4 Map (java.util.Map)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)3 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)3 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)3 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)3 ApiWsdlXmlValidator (nl.nn.adapterframework.extensions.api.ApiWsdlXmlValidator)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)3 InputStream (java.io.InputStream)2