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);
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations