use of nl.nn.adapterframework.core.PipeLine 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.PipeLine in project iaf by ibissource.
the class CleanupDatabaseJob method getAllMessageLogs.
private List<MessageLogObject> getAllMessageLogs(IbisManager ibisManager) {
List<MessageLogObject> messageLogs = new ArrayList<>();
for (IAdapter adapter : ibisManager.getRegisteredAdapters()) {
for (Receiver<?> receiver : adapter.getReceivers()) {
collectMessageLogs(messageLogs, receiver.getMessageLog());
}
PipeLine pipeline = adapter.getPipeLine();
for (int i = 0; i < pipeline.getPipes().size(); i++) {
IPipe pipe = pipeline.getPipe(i);
if (pipe instanceof MessageSendingPipe) {
MessageSendingPipe msp = (MessageSendingPipe) pipe;
collectMessageLogs(messageLogs, msp.getMessageLog());
}
}
}
return messageLogs;
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class PipeTestBase method setup.
@Before
public void setup() throws Exception {
pipe = createPipe();
autowireByType(pipe);
pipe.registerForward(new PipeForward("success", "exit"));
pipe.setName(pipe.getClass().getSimpleName() + " under test");
pipeline = getConfiguration().createBean(PipeLine.class);
pipeline.addPipe(pipe);
PipeLineExit exit = new PipeLineExit();
exit.setPath("exit");
exit.setState(ExitState.SUCCESS);
pipeline.registerPipeLineExit(exit);
adapter = getConfiguration().createBean(Adapter.class);
adapter.setName("TestAdapter-for-".concat(pipe.getClass().getSimpleName()));
adapter.setPipeLine(pipeline);
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class ApiServiceDispatcher method mapResponses.
private JsonObjectBuilder mapResponses(IAdapter adapter, MediaTypes contentType, JsonObjectBuilder schemas) {
JsonObjectBuilder responses = Json.createObjectBuilder();
PipeLine pipeline = adapter.getPipeLine();
Json2XmlValidator inputValidator = getJsonValidator(pipeline, false);
Json2XmlValidator outputValidator = getJsonValidator(pipeline, true);
JsonObjectBuilder schema = null;
String schemaReferenceElement = null;
List<XSModel> models = new ArrayList<XSModel>();
if (inputValidator != null) {
models.addAll(inputValidator.getXSModels());
schemaReferenceElement = inputValidator.getMessageRoot(true);
}
if (outputValidator != null) {
models.addAll(outputValidator.getXSModels());
// all non-empty exits should refer to this element
schemaReferenceElement = outputValidator.getRoot();
}
if (!models.isEmpty()) {
schema = Json.createObjectBuilder();
}
addComponentsToTheSchema(schemas, models);
Map<String, PipeLineExit> pipeLineExits = pipeline.getPipeLineExits();
for (String exitPath : pipeLineExits.keySet()) {
PipeLineExit ple = pipeLineExits.get(exitPath);
int exitCode = ple.getExitCode();
if (exitCode == 0) {
exitCode = 200;
}
JsonObjectBuilder exit = Json.createObjectBuilder();
Status status = Status.fromStatusCode(exitCode);
exit.add("description", status.getReasonPhrase());
if (!ple.isEmptyResult()) {
JsonObjectBuilder content = Json.createObjectBuilder();
if (StringUtils.isNotEmpty(schemaReferenceElement)) {
String reference = null;
if (StringUtils.isNotEmpty(ple.getResponseRoot()) && outputValidator == null) {
reference = ple.getResponseRoot();
} else {
List<String> references = Arrays.asList(schemaReferenceElement.split(","));
if (ple.isSuccessExit()) {
reference = references.get(0);
} else {
reference = references.get(references.size() - 1);
}
}
// JsonObjectBuilder add method consumes the schema
schema.add("schema", Json.createObjectBuilder().add("$ref", SCHEMA_DEFINITION_PATH + reference));
content.add(contentType.getContentType(), schema);
}
exit.add("content", content);
}
responses.add("" + exitCode, exit);
}
return responses;
}
use of nl.nn.adapterframework.core.PipeLine in project iaf by ibissource.
the class ParameterTest method testPutInSessionPipeWithDomdocParamsUsedMoreThanOnce.
@Test
public // Test for #2256 PutParametersInSession with xpathExpression with type=domdoc results in "Content is not allowed in prolog"
void testPutInSessionPipeWithDomdocParamsUsedMoreThanOnce() throws Exception {
try (TestConfiguration configuration = new TestConfiguration()) {
PipeLine pipeline = configuration.createBean(PipeLine.class);
String firstPipe = "PutInSession under test";
String secondPipe = "PutInSession next pipe";
String testMessage = "<Test>\n" + " <Child><name>X</name></Child>\n" + " <Child><name>Y</name></Child>\n" + " <Child><name>Z</name></Child>\n" + "</Test>";
String testMessageChild1 = "<Child><name>X</name></Child>";
PutInSession pipe = configuration.createBean(PutInSession.class);
pipe.setName(firstPipe);
pipe.setPipeLine(pipeline);
Parameter p = new Parameter();
p.setName("xmlMessageChild");
p.setXpathExpression("Test/Child[1]");
p.setType(ParameterType.DOMDOC);
pipe.addParameter(p);
pipeline.addPipe(pipe);
PutInSession pipe2 = configuration.createBean(PutInSession.class);
pipe2.setName(secondPipe);
pipe2.setPipeLine(pipeline);
Parameter p2 = new Parameter();
p2.setName("xmlMessageChild2");
p2.setSessionKey("xmlMessageChild");
p2.setXpathExpression("Child/name/text()");
pipe2.addParameter(p2);
pipeline.addPipe(pipe2);
PipeLineExit exit = new PipeLineExit();
exit.setPath("exit");
exit.setState(ExitState.SUCCESS);
pipeline.registerPipeLineExit(exit);
pipeline.configure();
CorePipeLineProcessor cpp = configuration.createBean(CorePipeLineProcessor.class);
CorePipeProcessor pipeProcessor = configuration.createBean(CorePipeProcessor.class);
cpp.setPipeProcessor(pipeProcessor);
PipeLineSession session = configuration.createBean(PipeLineSession.class);
pipeline.setOwner(pipe);
PipeLineResult pipeRunResult = cpp.processPipeLine(pipeline, "messageId", new Message(testMessage), session, firstPipe);
assertEquals(ExitState.SUCCESS, pipeRunResult.getState());
assertEquals(testMessage, pipeRunResult.getResult().asString());
MatchUtils.assertXmlEquals(testMessageChild1, session.getMessage("xmlMessageChild").asString());
assertEquals("X", session.getMessage("xmlMessageChild2").asString());
}
}
Aggregations