Search in sources :

Example 11 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class ShowConfigurationStatusTest method testSingleConfig.

@Test
public void testSingleConfig() throws ConfigurationException, PipeRunException, DomBuilderException, SAXException, IOException, TransformerException {
    ShowConfigurationStatus showConfigurationStatus = new ShowConfigurationStatus();
    PipeLine pipeLine = new PipeLine();
    Adapter adapter = (Adapter) ibisContext.getIbisManager().getRegisteredAdapter("WebControlShowConfigurationStatus");
    pipeLine.setAdapter(adapter);
    showConfigurationStatus.registerForward(createPipeSuccessForward());
    showConfigurationStatus.configure(pipeLine);
    session.put("configuration", "Ibis4Example");
    MockHttpServletRequest request = new MockHttpServletRequest();
    session.put(IPipeLineSession.HTTP_REQUEST_KEY, request);
    PipeRunResult pipeRunResult = showConfigurationStatus.doPipe(null, session);
    compareXML("webcontrol/singleConfig.xml", (String) pipeRunResult.getResult());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) Test(org.junit.Test)

Example 12 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class WsdlTest method mockPipeLine.

protected PipeLine mockPipeLine(IPipe inputValidator, IPipe outputValidator, String targetNamespace, String adapterName) {
    PipeLine simple = mock(PipeLine.class);
    when(simple.getInputValidator()).thenReturn(inputValidator);
    when(simple.getOutputValidator()).thenReturn(outputValidator);
    Adapter adp = mock(Adapter.class);
    when(simple.getAdapter()).thenReturn(adp);
    Configuration cfg = mock(Configuration.class);
    when(simple.getAdapter().getConfiguration()).thenReturn(cfg);
    final ReceiverBase receiverBase = mock(ReceiverBase.class);
    WebServiceListener listener = new WebServiceListener();
    listener.setServiceNamespaceURI(targetNamespace);
    when(receiverBase.getListener()).thenReturn(listener);
    when(adp.getReceiverIterator()).thenAnswer(new Answer<Iterator>() {

        public Iterator answer(InvocationOnMock invocation) throws Throwable {
            return Arrays.asList(receiverBase).iterator();
        }
    });
    when(adp.getName()).thenReturn(adapterName);
    return simple;
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Iterator(java.util.Iterator) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener)

Example 13 with Adapter

use of nl.nn.adapterframework.core.Adapter 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 14 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class JobDef method recoverAdapters.

private void recoverAdapters(IbisManager ibisManager) {
    int countAdapter = 0;
    int countAdapterStateStarted = 0;
    int countReceiver = 0;
    int countReceiverStateStarted = 0;
    for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
        countAdapter++;
        if (iAdapter instanceof Adapter) {
            Adapter adapter = (Adapter) iAdapter;
            RunStateEnum adapterRunState = adapter.getRunState();
            if (adapterRunState.equals(RunStateEnum.ERROR)) {
                log.debug("trying to recover adapter [" + adapter.getName() + "]");
                try {
                    adapter.setRecover(true);
                    adapter.configure();
                } catch (ConfigurationException e) {
                    // do nothing
                    log.warn("error during recovering adapter [" + adapter.getName() + "]: " + e.getMessage());
                } finally {
                    adapter.setRecover(false);
                }
                if (adapter.configurationSucceeded()) {
                    adapter.stopRunning();
                    int count = 10;
                    while (count-- >= 0 && !adapter.getRunState().equals(RunStateEnum.STOPPED)) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                        // do nothing
                        }
                    }
                }
                // check for start is in method startRunning in Adapter self
                if (adapter.isAutoStart()) {
                    adapter.startRunning();
                }
                log.debug("finished recovering adapter [" + adapter.getName() + "]");
            }
            String message = "adapter [" + adapter.getName() + "] has state [" + adapterRunState + "]";
            adapterRunState = adapter.getRunState();
            if (adapterRunState.equals(RunStateEnum.STARTED)) {
                countAdapterStateStarted++;
                heartbeatLog.info(message);
            } else if (adapterRunState.equals(RunStateEnum.ERROR)) {
                heartbeatLog.error(message);
            } else {
                heartbeatLog.warn(message);
            }
            for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                countReceiver++;
                IReceiver iReceiver = (IReceiver) receiverIt.next();
                if (iReceiver instanceof ReceiverBase) {
                    ReceiverBase receiver = (ReceiverBase) iReceiver;
                    RunStateEnum receiverRunState = receiver.getRunState();
                    if (!adapterRunState.equals(RunStateEnum.ERROR) && receiverRunState.equals(RunStateEnum.ERROR)) {
                        log.debug("trying to recover receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
                        try {
                            if (receiver != null) {
                                receiver.setRecover(true);
                            }
                            adapter.configureReceiver(receiver);
                        } finally {
                            if (receiver != null) {
                                receiver.setRecover(false);
                            }
                        }
                        if (receiver != null) {
                            if (receiver.configurationSucceeded()) {
                                receiver.stopRunning();
                                int count = 10;
                                while (count-- >= 0 && !receiver.getRunState().equals(RunStateEnum.STOPPED)) {
                                    try {
                                        Thread.sleep(1000);
                                    } catch (InterruptedException e) {
                                        log.debug("Interrupted waiting for receiver to stop", e);
                                    }
                                }
                            }
                            // check for start is in method startRunning in
                            // ReceiverBase self
                            receiver.startRunning();
                            log.debug("finished recovering receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "]");
                        }
                    }
                    receiverRunState = receiver.getRunState();
                    message = "receiver [" + receiver.getName() + "] of adapter [" + adapter.getName() + "] has state [" + receiverRunState + "]";
                    if (receiverRunState.equals(RunStateEnum.STARTED)) {
                        countReceiverStateStarted++;
                        heartbeatLog.info(message);
                    } else if (receiverRunState.equals(RunStateEnum.ERROR)) {
                        heartbeatLog.error(message);
                    } else {
                        heartbeatLog.warn(message);
                    }
                } else {
                    log.warn("will not try to recover receiver [" + iReceiver.getName() + "] of adapter [" + adapter.getName() + "], is not of type Receiver but [" + iAdapter.getClass().getName() + "]");
                }
            }
        } else {
            log.warn("will not try to recover adapter [" + iAdapter.getName() + "], is not of type Adapter but [" + iAdapter.getClass().getName() + "]");
        }
    }
    heartbeatLog.info("[" + countAdapterStateStarted + "/" + countAdapter + "] adapters and [" + countReceiverStateStarted + "/" + countReceiver + "] receivers have state [" + RunStateEnum.STARTED + "]");
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Iterator(java.util.Iterator) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 15 with Adapter

use of nl.nn.adapterframework.core.Adapter in project iaf by ibissource.

the class IbisSoapServlet method wsdl.

private void wsdl(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    String servlet = HttpUtils.getRequestURL(req).toString();
    try {
        Wsdl wsdl;
        Adapter a = getAdapter(ibisManager, req.getPathInfo());
        if (a == null) {
            res.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        wsdl = new Wsdl(a.getPipeLine());
        if (req.getParameter("indent") != null) {
            wsdl.setIndent("true".equals(req.getParameter("indent")));
        }
        if (req.getParameter("useIncludes") != null) {
            wsdl.setUseIncludes("true".equals(req.getParameter("useIncludes")));
        }
        setDocumentation(wsdl, req);
        wsdl.init();
        res.setHeader("Content-Disposition", "inline;filename=\"" + wsdl.getFilename() + ".wsdl\"");
        wsdl.wsdl(res.getOutputStream(), servlet);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

Adapter (nl.nn.adapterframework.core.Adapter)31 IAdapter (nl.nn.adapterframework.core.IAdapter)24 Iterator (java.util.Iterator)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)10 RolesAllowed (javax.annotation.security.RolesAllowed)9 IReceiver (nl.nn.adapterframework.core.IReceiver)9 GET (javax.ws.rs.GET)8 PipeLine (nl.nn.adapterframework.core.PipeLine)8 ArrayList (java.util.ArrayList)7 Configuration (nl.nn.adapterframework.configuration.Configuration)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)5 IListener (nl.nn.adapterframework.core.IListener)5 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)5 ServletException (javax.servlet.ServletException)4 Response (javax.ws.rs.core.Response)4 IPipe (nl.nn.adapterframework.core.IPipe)4