Search in sources :

Example 6 with ClassLoaderException

use of nl.nn.adapterframework.configuration.ClassLoaderException in project iaf by ibissource.

the class ServiceClassLoader method loadResources.

@Override
protected Map<String, byte[]> loadResources() throws ClassLoaderException {
    if (adapterName == null) {
        throw new ClassLoaderException("Name of adapter to provide configuration jar not specified");
    }
    IAdapter adapter = getIbisContext().getIbisManager().getRegisteredAdapter(adapterName);
    if (adapter != null) {
        try (PipeLineSession pipeLineSession = new PipeLineSession()) {
            adapter.processMessage(getCorrelationId(), new Message(getConfigurationName()), pipeLineSession);
            // TODO check result of pipeline
            Object object = pipeLineSession.get("configurationJar");
            if (object != null) {
                if (object instanceof byte[]) {
                    return readResources((byte[]) object);
                }
                throw new ClassLoaderException("SessionKey configurationJar not a byte array");
            }
            throw new ClassLoaderException("SessionKey configurationJar not found");
        }
    }
    throw new ClassLoaderException("Could not find adapter: " + adapterName);
}
Also used : Message(nl.nn.adapterframework.stream.Message) ClassLoaderException(nl.nn.adapterframework.configuration.ClassLoaderException) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 7 with ClassLoaderException

use of nl.nn.adapterframework.configuration.ClassLoaderException in project iaf by ibissource.

the class JarBytesClassLoader method readResources.

protected final Map<String, byte[]> readResources(InputStream stream) throws ClassLoaderException {
    try (JarInputStream jarInputStream = new JarInputStream(stream)) {
        Map<String, byte[]> resources = new HashMap<String, byte[]>();
        JarEntry jarEntry;
        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
            String fileName = jarEntry.getName();
            if (getBasePath() != null) {
                // if the name ends with a slash, assume it's a folder
                boolean isFolder = fileName.endsWith("/");
                if (isFolder || fileName.startsWith("META-INF/")) {
                    // Ignore all folders and files in META-INF
                    log.debug("ignoring {} [{}]", (isFolder ? "folder" : "file"), fileName);
                    continue;
                }
                if (fileName.startsWith(getBasePath())) {
                    // Remove BasePath from the filename
                    fileName = fileName.substring(getBasePath().length());
                } else {
                    // Found a file that's not in the BasePath folder
                    if (!fileName.endsWith(".class")) {
                        // Allow classes to be in the root path, but not resources
                        log.warn("invalid file [" + fileName + "] not in folder [" + getBasePath() + "]");
                        // Don't add the file to the resources lists
                        continue;
                    }
                }
            }
            resources.put(fileName, Misc.streamToBytes(StreamUtil.dontClose(jarInputStream)));
        }
        return resources;
    } catch (IOException e) {
        throw new ClassLoaderException("Could not read resources from jar input stream for configuration '" + getConfigurationName() + "'", e);
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) HashMap(java.util.HashMap) ClassLoaderException(nl.nn.adapterframework.configuration.ClassLoaderException) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry)

Aggregations

ClassLoaderException (nl.nn.adapterframework.configuration.ClassLoaderException)7 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)2 FileNotFoundException (java.io.FileNotFoundException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 ClassLoaderManager (nl.nn.adapterframework.configuration.ClassLoaderManager)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 DirectoryClassLoader (nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader)1 IAdapter (nl.nn.adapterframework.core.IAdapter)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 SenderException (nl.nn.adapterframework.core.SenderException)1 TimeoutException (nl.nn.adapterframework.core.TimeoutException)1