Search in sources :

Example 1 with Dir2Xml

use of nl.nn.adapterframework.util.Dir2Xml in project iaf by ibissource.

the class ShowLogging method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    // Retrieve logging directory for browsing
    String path = request.getParameter("directory");
    if (StringUtils.isEmpty(path)) {
        path = AppConstants.getInstance().getResolvedProperty("logging.path");
    }
    boolean sizeFormat = true;
    String sizeFormatString = request.getParameter("sizeFormat");
    if (StringUtils.isNotEmpty(sizeFormatString)) {
        sizeFormat = Boolean.parseBoolean(sizeFormatString);
    }
    Dir2Xml dx = new Dir2Xml();
    dx.setPath(path);
    String listresult;
    if (!FileUtils.readAllowed(FileViewerServlet.permissionRules, request, path)) {
        error("access to path (" + path + ") not allowed", null);
        listresult = "<directory/>";
    } else {
        String wildcard = request.getParameter("wildcard");
        if (StringUtils.isEmpty(wildcard)) {
            wildcard = AppConstants.getInstance().getProperty("logging.wildcard");
        }
        if (wildcard != null)
            dx.setWildCard(wildcard);
        try {
            listresult = dx.getDirList(showDirectories, maxItems);
            if (listresult != null) {
                Element root = XmlUtils.buildDomDocument(listresult).getDocumentElement();
                root.setAttribute("sizeFormat", Boolean.toString(sizeFormat));
                listresult = XmlUtils.nodeToString(root);
                String countStr = root.getAttribute("count");
                if (countStr != null) {
                    int count = Integer.parseInt(countStr);
                    if (count > maxItems) {
                        error("total number of items (" + count + ") exceeded maximum number, only showing first " + maxItems + " items", null);
                    }
                }
            }
        } catch (Exception e) {
            error("error occured on getting directory list", e);
            log.warn("returning empty result for directory listing");
            listresult = "<directory/>";
        }
    }
    request.setAttribute("Dir2Xml", listresult);
    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : Dir2Xml(nl.nn.adapterframework.util.Dir2Xml) Element(org.w3c.dom.Element) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with Dir2Xml

use of nl.nn.adapterframework.util.Dir2Xml in project iaf by ibissource.

the class FileSender method getMessage.

public String getMessage() throws TimeOutException, SenderException {
    Dir2Xml dx = new Dir2Xml();
    dx.setPath(filename);
    return dx.getRecursiveDirList();
}
Also used : Dir2Xml(nl.nn.adapterframework.util.Dir2Xml)

Example 3 with Dir2Xml

use of nl.nn.adapterframework.util.Dir2Xml 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)

Aggregations

Dir2Xml (nl.nn.adapterframework.util.Dir2Xml)3 IOException (java.io.IOException)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ServletException (javax.servlet.ServletException)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 PipeLine (nl.nn.adapterframework.core.PipeLine)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 GenericReceiver (nl.nn.adapterframework.receivers.GenericReceiver)1 Wsdl (nl.nn.adapterframework.soap.Wsdl)1 Element (org.w3c.dom.Element)1