Search in sources :

Example 1 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class APIDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    API api = APIFactory.createAPI(artifactConfig, properties);
    if (api != null) {
        api.setLogSetterValue();
    }
    if (log.isDebugEnabled()) {
        log.debug("API update from file : " + fileName + " has started");
    }
    try {
        if (api == null) {
            handleSynapseArtifactDeploymentError("API update failed. The artifact " + "defined in the file: " + fileName + " is not a valid API.");
            return null;
        }
        api.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("API: " + api.getName() + " has been built from the file: " + fileName);
        }
        api.init(getSynapseEnvironment());
        API existingAPI = getSynapseConfiguration().getAPI(existingArtifactName);
        if (existingArtifactName.equals(api.getName())) {
            getSynapseConfiguration().updateAPI(existingArtifactName, api);
        } else {
            // The user has changed the name of the API
            // We should add the updated API as a new API and remove the old one
            getSynapseConfiguration().addAPI(api.getName(), api);
            getSynapseConfiguration().removeAPI(existingArtifactName);
            log.info("API: " + existingArtifactName + " has been undeployed");
        }
        log.info("API: " + api.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        existingAPI.destroy();
        return api.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the API from the " + "file: " + fileName);
    }
    return null;
}
Also used : API(org.apache.synapse.rest.API) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 2 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException 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)

Example 3 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class LibraryArtifactDeployer method deploy.

public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    String libFilePath = FilenameUtils.normalize(deploymentFileData.getAbsolutePath());
    if (log.isDebugEnabled()) {
        log.debug("Deployment of the synapse library artifact from file : " + libFilePath + " : STARTED");
    }
    // }
    try {
        SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration().getArtifactDeploymentStore();
        Library lib = LibDeployerUtils.createSynapseLibrary(libFilePath);
        String libArtifactName = lib.getQName().toString();
        if (this.getSynapseConfiguration().getSynapseLibraries().get(lib.getQName().toString()) != null) {
            log.warn("Hot deployment thread picked up an already deployed synapse library - Ignoring");
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Created the Synapse Library : " + libArtifactName + "  from : " + libFilePath);
            }
            if (deploymentStore.isUpdatingArtifact(libFilePath)) {
                if (log.isDebugEnabled()) {
                    log.debug("Updating Library artifact detected with filename : " + libFilePath);
                }
                // this is an hot-update case
                String existingArtifactName = deploymentStore.getUpdatingArtifactWithFileName(libFilePath);
                deploymentStore.removeUpdatingArtifact(libFilePath);
                undeploySynapseArtifact(existingArtifactName);
                // deploy from beginning
                // add the library to synapse Config
                completeDeployment(lib, libArtifactName);
            } else {
                // new artifact hot-deployment case
                try {
                    // add the library to synapse Config
                    completeDeployment(lib, libArtifactName);
                } catch (SynapseArtifactDeploymentException sade) {
                    log.error("Deployment of the Synapse Artifact from file : " + libFilePath + " : Failed!", sade);
                /*
		     * log.info("The file has been backed up into : " +
		     * backupFile(deploymentFileData.getFile()));
		     */
                }
            }
            if (libArtifactName != null) {
                deploymentStore.addArtifact(libFilePath, libArtifactName);
            }
            log.info("Synapse Library named '" + lib.toString() + "' has been deployed from file : " + libFilePath);
        }
    } catch (IOException ex) {
        handleDeploymentError("Deployment of synapse artifact failed. Error reading " + libFilePath + " : " + ex.getMessage(), ex);
    } catch (Exception ex) {
        handleDeploymentError("Deployment of synapse artifact failed for synapse libray at : " + libFilePath + " : " + ex.getMessage(), ex);
    }
    if (log.isDebugEnabled()) {
        log.debug("Deployment of the synapse artifact from file : " + libFilePath + " : COMPLETED");
    }
}
Also used : Library(org.apache.synapse.libraries.model.Library) IOException(java.io.IOException) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 4 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class MessageProcessorDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Message Processor update from file : " + fileName + " has started");
    }
    try {
        MessageProcessor mp = MessageProcessorFactory.createMessageProcessor(artifactConfig);
        if (mp == null) {
            handleSynapseArtifactDeploymentError("Message Processor update failed. The artifact " + "defined in the file: " + fileName + " is not valid");
            return null;
        }
        mp.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("MessageProcessor: " + mp.getName() + " has been built from the file: " + fileName);
        }
        MessageProcessor existingMp = getSynapseConfiguration().getMessageProcessors().get(existingArtifactName);
        if (existingMp instanceof AbstractMessageProcessor) {
            ((AbstractMessageProcessor) existingMp).destroy(true);
        } else {
            existingMp.destroy();
        }
        // We should add the updated MessageProcessor as a new MessageProcessor
        // and remove the old one
        mp.init(getSynapseEnvironment());
        getSynapseConfiguration().removeMessageProcessor(existingArtifactName);
        log.info("MessageProcessor: " + existingArtifactName + " has been undeployed");
        getSynapseConfiguration().addMessageProcessor(mp.getName(), mp);
        log.info("MessageProcessor: " + mp.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        return mp.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the MessageProcessor from the " + "file: " + fileName);
    }
    return null;
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 5 with DeploymentException

use of org.apache.axis2.deployment.DeploymentException in project wso2-synapse by wso2.

the class MessageStoreDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Message Store update from file : " + fileName + " has started");
    }
    try {
        MessageStore ms = MessageStoreFactory.createMessageStore(artifactConfig, properties);
        if (ms == null) {
            handleSynapseArtifactDeploymentError("Message Store update failed. The artifact " + "defined in the file: " + fileName + " is not valid");
            return null;
        }
        ms.setFileName(new File(fileName).getName());
        if (log.isDebugEnabled()) {
            log.debug("MessageStore: " + ms.getName() + " has been built from the file: " + fileName);
        }
        ms.init(getSynapseEnvironment());
        MessageStore existingMs = getSynapseConfiguration().getMessageStore(existingArtifactName);
        // We should add the updated MessageStore as a new MessageStore and remove the old one
        getSynapseConfiguration().removeMessageStore(existingArtifactName);
        getSynapseConfiguration().addMessageStore(ms.getName(), ms);
        log.info("MessageStore: " + existingArtifactName + " has been undeployed");
        log.info("MessageStore: " + ms.getName() + " has been updated from the file: " + fileName);
        waitForCompletion();
        existingMs.destroy();
        return ms.getName();
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the MessageStore from the " + "file: " + fileName);
    }
    return null;
}
Also used : MessageStore(org.apache.synapse.message.store.MessageStore) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Aggregations

DeploymentException (org.apache.axis2.deployment.DeploymentException)32 File (java.io.File)23 Deployer (org.apache.axis2.deployment.Deployer)6 Artifact (org.wso2.carbon.application.deployer.config.Artifact)6 CappFile (org.wso2.carbon.application.deployer.config.CappFile)6 IOException (java.io.IOException)4 AxisFault (org.apache.axis2.AxisFault)3 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)3 Library (org.apache.synapse.libraries.model.Library)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 QName (javax.xml.namespace.QName)2 OMElement (org.apache.axiom.om.OMElement)2 Mediator (org.apache.synapse.Mediator)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ZipInputStream (java.util.zip.ZipInputStream)1 XMLStreamException (javax.xml.stream.XMLStreamException)1