Search in sources :

Example 1 with StartupFactory

use of org.apache.synapse.config.xml.StartupFactory in project wso2-synapse by wso2.

the class ExtensionDeployer method deploy.

/**
 * This will be called when there is a change in the specified deployment
 * folder (in the axis2.xml) and this will load the relevant classes to the system and
 * register them with the MediatorFactoryFinder
 *
 * @param deploymentFileData - describes the updated file
 * @throws DeploymentException - in case an error on the deployment
 */
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    log.info("Loading extensions from: " + deploymentFileData.getAbsolutePath());
    // get the context class loader for the later restore of the context class loader
    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
    try {
        boolean isDirectory = deploymentFileData.getFile().isDirectory();
        deploymentFileData.setClassLoader(isDirectory, getClass().getClassLoader(), (File) cfgCtx.getAxisConfiguration().getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR), cfgCtx.getAxisConfiguration().isChildFirstClassLoading());
        DeploymentClassLoader urlCl = (DeploymentClassLoader) deploymentFileData.getClassLoader();
        Thread.currentThread().setContextClassLoader(urlCl);
        // StartupFactory registration
        for (StartupFactory factory : getProviders(StartupFactory.class, urlCl)) {
            QName tagQName = factory.getTagQName();
            Class<? extends StartupFactory> clazz = factory.getClass();
            StartupFinder finder = StartupFinder.getInstance();
            finder.getFactoryMap().put(tagQName, clazz);
            finder.getSerializerMap().put(tagQName, factory.getSerializerClass());
            log.info("Registered startup factory and serializer for " + tagQName);
        }
        // MediatorFactory registration
        for (MediatorFactory factory : getProviders(MediatorFactory.class, urlCl)) {
            QName tagQName = factory.getTagQName();
            Class<? extends MediatorFactory> clazz = factory.getClass();
            MediatorFactoryFinder.getInstance().getFactoryMap().put(tagQName, clazz);
            log.info("Registered mediator factory " + clazz.getName() + " for " + tagQName);
        }
        // MediatorSerializer registration
        for (MediatorSerializer serializer : getProviders(MediatorSerializer.class, urlCl)) {
            String mediatorClassName = serializer.getMediatorClassName();
            MediatorSerializerFinder.getInstance().getSerializerMap().put(mediatorClassName, serializer);
            log.info("Registered mediator serializer " + serializer.getClass().getName() + " for " + mediatorClassName);
        }
    } catch (IOException e) {
        handleException("I/O error in reading the mediator jar file", e);
    } catch (Exception e) {
        handleException("Error occurred while trying to deploy mediator jar file", e);
    } catch (Throwable t) {
        handleException("Error occurred while trying to deploy the mediator jar file", t);
    } finally {
        // restore the class loader back
        if (log.isDebugEnabled()) {
            log.debug("Restoring the context class loader to the original");
        }
        Thread.currentThread().setContextClassLoader(prevCl);
    }
}
Also used : QName(javax.xml.namespace.QName) StartupFinder(org.apache.synapse.config.xml.StartupFinder) IOException(java.io.IOException) StartupFactory(org.apache.synapse.config.xml.StartupFactory) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException) DeploymentClassLoader(org.apache.axis2.deployment.DeploymentClassLoader) MediatorSerializer(org.apache.synapse.config.xml.MediatorSerializer) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) DeploymentClassLoader(org.apache.axis2.deployment.DeploymentClassLoader) URLClassLoader(java.net.URLClassLoader)

Aggregations

IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 QName (javax.xml.namespace.QName)1 DeploymentClassLoader (org.apache.axis2.deployment.DeploymentClassLoader)1 DeploymentException (org.apache.axis2.deployment.DeploymentException)1 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)1 MediatorSerializer (org.apache.synapse.config.xml.MediatorSerializer)1 StartupFactory (org.apache.synapse.config.xml.StartupFactory)1 StartupFinder (org.apache.synapse.config.xml.StartupFinder)1