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