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;
}
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, "");
}
}
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;
}
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());
}
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;
}
Aggregations