Search in sources :

Example 1 with MediatorFactory

use of org.apache.synapse.config.xml.MediatorFactory 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 2 with MediatorFactory

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

the class ForEachMediatorTest method testForEachXpathNodeRelativePath.

/**
 * Testing when the xpath returns only one element
 *
 * @throws Exception
 */
public void testForEachXpathNodeRelativePath() throws Exception {
    // Clear envelope
    if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
        testCtx.getEnvelope().getBody().getFirstElement().detach();
    }
    testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr id=\"one\">test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
    MediatorFactory fac = new ForEachMediatorFactory();
    Mediator foreach = fac.createMediator(createOMElement("<foreach " + "expression=\"//itr[@id='one']\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(1, helperMediator.getMsgCount());
    assertEquals("<itr id=\"one\">test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 3 with MediatorFactory

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

the class ForEachMediatorTest method testForEachXpathList.

/**
 * Testing when the xpath returns a list of elements
 *
 * @throws Exception
 */
public void testForEachXpathList() throws Exception {
    // Clear envelope
    if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
        testCtx.getEnvelope().getBody().getFirstElement().detach();
    }
    testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr>test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
    MediatorFactory fac = new ForEachMediatorFactory();
    Mediator foreach = fac.createMediator(createOMElement("<foreach expression=\"//original/itr\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(2, helperMediator.getMsgCount());
    assertEquals("<itr>test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
    assertEquals("<itr>test-split-context-itr2-body</itr>", helperMediator.getMediatedContext(1).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 4 with MediatorFactory

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

the class ForEachMediatorTest method testForEachXpathNode.

/**
 * Testing when the xpath returns only one element
 *
 * @throws Exception
 */
public void testForEachXpathNode() throws Exception {
    // Clear envelope
    if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
        testCtx.getEnvelope().getBody().getFirstElement().detach();
    }
    testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr id=\"one\">test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
    MediatorFactory fac = new ForEachMediatorFactory();
    Mediator foreach = fac.createMediator(createOMElement("<foreach " + "expression=\"//original/itr[@id='one']\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(1, helperMediator.getMsgCount());
    assertEquals("<itr id=\"one\">test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Example 5 with MediatorFactory

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

the class ForEachMediatorTest method testForEachXpathListRelativePath.

/**
 * Testing when the relative xpath returns a list of elements
 *
 * @throws Exception
 */
public void testForEachXpathListRelativePath() throws Exception {
    // Clear envelope
    if (testCtx.getEnvelope().getBody().getFirstElement() != null) {
        testCtx.getEnvelope().getBody().getFirstElement().detach();
    }
    testCtx.getEnvelope().getBody().addChild(createOMElement("<original>" + "<itr>test-split-context-itr1-body</itr>" + "<itr>test-split-context-itr2-body</itr>" + "</original>"));
    MediatorFactory fac = new ForEachMediatorFactory();
    Mediator foreach = fac.createMediator(createOMElement("<foreach " + "expression=\"//itr\" sequence=\"seqRef\" />"), new Properties());
    helperMediator.clearMediatedContexts();
    foreach.mediate(testCtx);
    assertEquals(2, helperMediator.getMsgCount());
    assertEquals("<itr>test-split-context-itr1-body</itr>", helperMediator.getMediatedContext(0).getEnvelope().getBody().getFirstElement().toString());
    assertEquals("<itr>test-split-context-itr2-body</itr>", helperMediator.getMediatedContext(1).getEnvelope().getBody().getFirstElement().toString());
}
Also used : ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) ForEachMediatorFactory(org.apache.synapse.config.xml.ForEachMediatorFactory) MediatorFactory(org.apache.synapse.config.xml.MediatorFactory) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Properties(java.util.Properties)

Aggregations

MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)6 Properties (java.util.Properties)5 Mediator (org.apache.synapse.Mediator)5 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)5 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 SynapseException (org.apache.synapse.SynapseException)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