Search in sources :

Example 1 with GenericReceiver

use of nl.nn.adapterframework.receivers.GenericReceiver 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 2 with GenericReceiver

use of nl.nn.adapterframework.receivers.GenericReceiver in project iaf by ibissource.

the class AbstractListenerConnectingEJB method retrieveListener.

protected IListener retrieveListener(String receiverName, String adapterName) {
    IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
    GenericReceiver receiver = (GenericReceiver) adapter.getReceiverByName(receiverName);
    return receiver.getListener();
}
Also used : GenericReceiver(nl.nn.adapterframework.receivers.GenericReceiver) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 3 with GenericReceiver

use of nl.nn.adapterframework.receivers.GenericReceiver in project iaf by ibissource.

the class ListenerPortPoller method toggleConfiguratorState.

/**
 * Toggle the state of the EjbListenerPortConnector instance by starting/stopping
 * the receiver it is attached to (via the JmsListener).
 * This method changes the state of the Receiver to match the state of the
 * WebSphere ListenerPort.
 *
 * @param elpc ListenerPortConnector for which state is to be changed.
 *
 * @throws nl.nn.adapterframework.configuration.ConfigurationException
 */
public void toggleConfiguratorState(IListenerConnector elpc) throws ConfigurationException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    GenericReceiver receiver = (GenericReceiver) getListener(elpc).getReceiver();
    if (isListenerPortClosed(elpc)) {
        if (receiver.isInRunState(RunStateEnum.STARTED)) {
            log.info("Stopping Receiver [" + receiver.getName() + "] because the WebSphere Listener-Port is in state 'stopped' but the JmsConnector in state 'open' and the receiver is in state 'started'");
            receiver.stopRunning();
        } else {
            log.info(// elpc.getListenerPortName(getListener(elpc))
            "ListenerPort [" + "] is in closed state, Listener is not in closed state, but Receiver is in state [" + receiver.getRunState().getName() + "] so the state of Receiver will not be changed.");
        }
    } else {
        // Only start the receiver for adapters which are running.
        if (receiver.getAdapter().getRunState().equals(RunStateEnum.STARTED)) {
            if (!receiver.isInRunState(RunStateEnum.STARTING)) {
                log.info("Starting Receiver [" + receiver.getName() + "] because the WebSphere Listener-Port is in state 'started' but the JmsConnector in state 'closed'");
                receiver.startRunning();
            } else {
                log.info("Receiver [" + receiver.getName() + "] still starting, so not changing anything now");
            }
        } else {
            try {
                log.warn("JmsConnector is closed, Adapter is not in state '" + RunStateEnum.STARTED + "', but WebSphere Jms Listener Port is in state 'started'. Stopping the listener port.");
                elpc.stop();
            } catch (ListenerException ex) {
                log.error(ex, ex);
            }
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) GenericReceiver(nl.nn.adapterframework.receivers.GenericReceiver)

Aggregations

GenericReceiver (nl.nn.adapterframework.receivers.GenericReceiver)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 DirectoryClassLoader (nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader)1 Adapter (nl.nn.adapterframework.core.Adapter)1 IAdapter (nl.nn.adapterframework.core.IAdapter)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 PipeLine (nl.nn.adapterframework.core.PipeLine)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 Wsdl (nl.nn.adapterframework.soap.Wsdl)1 Dir2Xml (nl.nn.adapterframework.util.Dir2Xml)1