Search in sources :

Example 6 with PipeLine

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);
}
Also used : Dir2Xml(nl.nn.adapterframework.util.Dir2Xml) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) Configuration(nl.nn.adapterframework.configuration.Configuration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Adapter(nl.nn.adapterframework.core.Adapter) IOException(java.io.IOException) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) GenericReceiver(nl.nn.adapterframework.receivers.GenericReceiver) FileOutputStream(java.io.FileOutputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) PipeLine(nl.nn.adapterframework.core.PipeLine) File(java.io.File)

Example 7 with PipeLine

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;
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ArrayList(java.util.ArrayList) PipeLine(nl.nn.adapterframework.core.PipeLine) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 8 with PipeLine

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);
}
Also used : Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit) Before(org.junit.Before)

Example 9 with 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;
}
Also used : Status(javax.ws.rs.core.Response.Status) Json2XmlValidator(nl.nn.adapterframework.pipes.Json2XmlValidator) ArrayList(java.util.ArrayList) XSModel(org.apache.xerces.xs.XSModel) JsonObjectBuilder(javax.json.JsonObjectBuilder) PipeLine(nl.nn.adapterframework.core.PipeLine) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit)

Example 10 with PipeLine

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());
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) CorePipeProcessor(nl.nn.adapterframework.processors.CorePipeProcessor) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) PipeLine(nl.nn.adapterframework.core.PipeLine) PutInSession(nl.nn.adapterframework.pipes.PutInSession) CorePipeLineProcessor(nl.nn.adapterframework.processors.CorePipeLineProcessor) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit) Test(org.junit.Test)

Aggregations

PipeLine (nl.nn.adapterframework.core.PipeLine)43 Adapter (nl.nn.adapterframework.core.Adapter)19 Test (org.junit.Test)17 XmlValidatorTest (nl.nn.adapterframework.pipes.XmlValidatorTest)12 IPipe (nl.nn.adapterframework.core.IPipe)10 PipeLineExit (nl.nn.adapterframework.core.PipeLineExit)8 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)8 IOException (java.io.IOException)6 IValidator (nl.nn.adapterframework.core.IValidator)6 XmlValidator (nl.nn.adapterframework.pipes.XmlValidator)6 Configuration (nl.nn.adapterframework.configuration.Configuration)5 PipeForward (nl.nn.adapterframework.core.PipeForward)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)5 Message (nl.nn.adapterframework.stream.Message)5 AbstractXmlValidator (nl.nn.adapterframework.validation.AbstractXmlValidator)5 JavaxXmlValidator (nl.nn.adapterframework.validation.JavaxXmlValidator)5 XercesXmlValidator (nl.nn.adapterframework.validation.XercesXmlValidator)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4