use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class Json2XmlValidatorTest method validate.
@Override
public String validate(String rootNamespace, String schemaLocation, boolean addNamespaceToSchema, boolean ignoreUnknownNamespaces, String inputFile, String[] expectedFailureReasons) throws IOException, ConfigurationException, PipeRunException {
init();
PipeLineSessionBase session = new PipeLineSessionBase();
// instance.setSchemasProvider(getSchemasProvider(schemaLocation, addNamespaceToSchema));
instance.setSchemaLocation(schemaLocation);
instance.setAddNamespaceToSchema(addNamespaceToSchema);
instance.setIgnoreUnknownNamespaces(ignoreUnknownNamespaces);
// instance.registerForward("success");
instance.setThrowException(true);
instance.setFullSchemaChecking(true);
instance.setTargetNamespace(rootNamespace);
instance.registerForward(new PipeForward("failure", null));
instance.registerForward(new PipeForward("parserError", null));
instance.configure(null);
validator.setSchemasProvider(getSchemasProvider(schemaLocation, addNamespaceToSchema));
validator.setIgnoreUnknownNamespaces(ignoreUnknownNamespaces);
validator.configure("setup");
String testXml = inputFile != null ? getTestXml(inputFile + ".xml") : null;
System.out.println("testXml [" + inputFile + ".xml] contents [" + testXml + "]");
String xml2json = (String) jsonPipe.doPipe(testXml, session).getResult();
System.out.println("testXml [" + inputFile + ".xml] to json [" + xml2json + "]");
String testJson = inputFile != null ? getTestXml(inputFile + ".json") : null;
System.out.println("testJson [" + testJson + "]");
try {
PipeRunResult prr = instance.doPipe(testJson, session);
String result = (String) prr.getResult();
System.out.println("result [" + ToStringBuilder.reflectionToString(prr) + "]");
String event;
if (prr.getPipeForward().getName().equals("success")) {
event = "valid XML";
} else {
if (prr.getPipeForward().getName().equals("failure")) {
event = "Invalid XML";
} else {
event = prr.getPipeForward().getName();
}
}
evaluateResult(event, session, null, expectedFailureReasons);
try {
String validationResult = validator.validate(result, session, "check result", null, null, false);
evaluateResult(validationResult, session, null, expectedFailureReasons);
return result;
} catch (Exception e) {
fail("result XML must be valid");
}
return result;
} catch (PipeRunException pre) {
evaluateResult("Invalid XML", session, pre, expectedFailureReasons);
}
return null;
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class LabelFormat method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
try {
String result;
if (getDirection().equalsIgnoreCase(DIRECTION_XML2LABEL)) {
Variant v = new Variant(input);
DocumentBuilder documentBuilder = XmlUtils.getDocumentBuilderFactory().newDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(new StringReader(v.asString())));
result = XmlToLabelFormat.doTransformation(document).toString();
return new PipeRunResult(getForward(), result);
} else {
Variant v = new Variant(input);
XMLReader reader = XMLReaderFactory.createXMLReader("nl.nn.adapterframework.extensions.rekenbox.CalcboxOutputReader");
CalcboxContentHandler handler = new CalcboxContentHandler(v.asString());
reader.setContentHandler(handler);
return new PipeRunResult(getForward(), handler.getStringResult());
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot transform", e);
}
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class RekenBoxCaller method doPipe.
/**
* positie 1 t/m 8 bepalen de naam van de executable, of tot aan de ':' (wat het eerst komt)
*/
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if (!(input instanceof String))
throw new PipeRunException(this, getLogPrefix(session) + "expected java.lang.String, got [" + input.getClass().getName() + "], value [" + input + "]");
String sInput = (String) input;
// log.debug("Pipe ["+name+"] got input ["+sInput+"]");
String rekenboxName = getRekenBoxName();
if (StringUtils.isEmpty(rekenboxName)) {
rekenboxName = sInput;
if (rekenboxName.length() >= 8)
rekenboxName = rekenboxName.substring(0, 8);
// find end or position of first colon.
rekenboxName = (rekenboxName + ":").substring(0, (rekenboxName + ":").indexOf(":")).trim();
}
if (rekenboxName.equals("")) {
throw new PipeRunException(this, getLogPrefix(session) + "cannot determine rekenboxName from [" + sInput + "]");
}
int i = rekenboxName.length();
int n = sInput.length();
while (i < n && " :;".indexOf(sInput.charAt(i)) >= 0) {
i++;
}
String rekenboxInput = sInput.substring(i);
String exeName = runPath + rekenboxName + "." + executableExtension;
if (!(new File(exeName).exists())) {
throw new PipeRunException(this, getLogPrefix(session) + "executable file [" + exeName + "] does not exist; requestmessage: [" + sInput + "]");
}
if (getRekenboxSessionKey() != null) {
session.put(getRekenboxSessionKey(), rekenboxName);
}
String baseFileName = getBaseFileName();
String inputFileName = inputOutputDirectory + baseFileName + ".INV";
String outputFileName = inputOutputDirectory + baseFileName + ".UIT";
String callAndArgs;
String callType = getCommandLineType();
if ((callType == null) || (callType.equals("switches"))) {
callAndArgs = exeName + " /I" + inputFileName + " /U" + outputFileName + " /P" + templateDir;
} else if (callType.equals("straight")) {
callAndArgs = exeName + " " + inputFileName + " " + outputFileName + " " + templateDir;
} else if (callType.equals("redirected")) {
callAndArgs = exeName + " " + inputFileName + " " + templateDir;
} else
throw new PipeRunException(this, getLogPrefix(session) + "unknown commandLineType: " + callType);
try {
// put input in a file
Misc.stringToFile(rekenboxInput, inputFileName);
// precreating outputfile is necessary for L76HB000
log.debug(getLogPrefix(session) + " precreating outputfile [" + outputFileName + "]");
new File(outputFileName).createNewFile();
log.debug(getLogPrefix(session) + " will issue command [" + callAndArgs + "]");
// execute
Runtime rt = Runtime.getRuntime();
Process child = rt.exec(callAndArgs);
String result;
if (callType.equals("redirected")) {
result = Misc.streamToString(child.getInputStream(), "\n", true);
} else {
child.waitFor();
// read output
result = Misc.fileToString(outputFileName, "\n", true);
}
log.debug(getLogPrefix(session) + " completed call. Process exit code is: " + child.exitValue());
// log.debug("Pipe ["+name+"] retrieved result ["+result+"]");
return new PipeRunResult(getForward(), result);
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "got Exception executing rekenbox", e);
} finally {
// cleanup
if (isCleanup()) {
new File(inputFileName).delete();
new File(outputFileName).delete();
}
}
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class WsdlGeneratorPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
InputStream inputStream = (InputStream) session.get("file");
if (inputStream == null) {
throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
}
File tempDir;
String fileName;
try {
tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
fileName = (String) session.get("fileName");
if (FileUtils.extensionEqualsIgnoreCase(fileName, "zip")) {
FileUtils.unzipStream(inputStream, tempDir);
} else {
File file = new File(tempDir, fileName);
Misc.streamToFile(inputStream, file);
file.deleteOnExit();
}
} catch (IOException e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on uploading and unzipping/writing file", e);
}
File propertiesFile = new File(tempDir, getPropertiesFileName());
PipeLine pipeLine;
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(tempDir.getPath());
Thread.currentThread().setContextClassLoader(directoryClassLoader);
if (propertiesFile.exists()) {
pipeLine = createPipeLineFromPropertiesFile(propertiesFile);
} else {
File xsdFile = FileUtils.getFirstFile(tempDir);
pipeLine = createPipeLineFromXsdFile(xsdFile);
}
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
if (originalClassLoader != null) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
Object result = null;
OutputStream zipOut = null;
OutputStream fullWsdlOut = null;
try {
Adapter adapter = new Adapter();
adapter.setConfiguration(new Configuration(null));
String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
adapter.setName(fileBaseName);
GenericReceiver genericReceiver = new GenericReceiver();
EsbJmsListener esbJmsListener = new EsbJmsListener();
esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
genericReceiver.setListener(esbJmsListener);
adapter.registerReceiver(genericReceiver);
pipeLine.setAdapter(adapter);
Wsdl wsdl = null;
wsdl = new Wsdl(pipeLine);
wsdl.setIndent(true);
wsdl.setDocumentation(getWsdlDocumentation(wsdl.getFilename()));
wsdl.init();
File wsdlDir = FileUtils.createTempDir(tempDir);
// zip (with includes)
File zipOutFile = new File(wsdlDir, wsdl.getFilename() + ".zip");
zipOutFile.deleteOnExit();
zipOut = new FileOutputStream(zipOutFile);
wsdl.setUseIncludes(true);
wsdl.zip(zipOut, null);
// full wsdl (without includes)
File fullWsdlOutFile = new File(wsdlDir, wsdl.getFilename() + ".wsdl");
fullWsdlOutFile.deleteOnExit();
fullWsdlOut = new FileOutputStream(fullWsdlOutFile);
wsdl.setUseIncludes(false);
wsdl.wsdl(fullWsdlOut, null);
Dir2Xml dx = new Dir2Xml();
dx.setPath(wsdlDir.getPath());
result = dx.getDirList();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
} finally {
try {
if (zipOut != null) {
zipOut.close();
}
if (fullWsdlOut != null) {
fullWsdlOut.close();
}
} catch (IOException e1) {
log.warn("exception closing outputstream", e1);
}
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.core.PipeRunResult in project iaf by ibissource.
the class DirectWrapperPipe method doPipeWithTimeoutGuarded.
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
String result;
ParameterValueList pvl = null;
if (getParameterList() != null) {
ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
try {
pvl = prc.getValues(getParameterList());
} catch (ParameterException e) {
throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
}
}
String destination = getParameterValue(pvl, DESTINATION);
String cmhVersion = getParameterValue(pvl, CMHVERSION);
String addOutputNamespace = getParameterValue(pvl, ADDOUTPUTNAMESPACE);
EsbSoapWrapperPipe eswPipe = new EsbSoapWrapperPipe();
if (addOutputNamespace != null) {
if ("on".equalsIgnoreCase(addOutputNamespace)) {
eswPipe.setAddOutputNamespace(true);
}
}
if (destination != null) {
Parameter p = new Parameter();
p.setName(DESTINATION);
p.setValue(destination);
eswPipe.addParameter(p);
}
if (cmhVersion != null) {
if (StringUtils.isNumeric(cmhVersion)) {
eswPipe.setCmhVersion(Integer.parseInt(cmhVersion));
}
}
PipeForward pf = new PipeForward();
pf.setName("success");
eswPipe.registerForward(pf);
try {
eswPipe.configure();
PipeRunResult prr = eswPipe.doPipe(input, session);
result = (String) prr.getResult();
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session) + "Exception on wrapping input", e);
}
return result;
}
Aggregations