use of org.apache.synapse.mediators.ext.ClassMediator in project wso2-synapse by wso2.
the class ClassMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
ClassMediator classMediator = new ClassMediator();
OMAttribute name = elem.getAttribute(ATT_NAME);
if (name == null) {
String msg = "The name of the actual mediator class is a required attribute";
log.error(msg);
throw new SynapseException(msg);
}
Class clazz = null;
Mediator mediator;
if (properties != null) {
// load from synapse libs or dynamic class mediators
ClassLoader libLoader = (ClassLoader) properties.get(SynapseConstants.SYNAPSE_LIB_LOADER);
if (libLoader != null) {
// load from synapse lib
try {
clazz = libLoader.loadClass(name.getAttributeValue());
} catch (ClassNotFoundException e) {
String msg = "Error loading class : " + name.getAttributeValue() + " from Synapse library";
log.error(msg, e);
throw new SynapseException(msg, e);
}
} else {
// load from dynamic class mediators
Map<String, ClassLoader> dynamicClassMediatorLoaderMap = (Map<String, ClassLoader>) properties.get(SynapseConstants.CLASS_MEDIATOR_LOADERS);
if (dynamicClassMediatorLoaderMap != null) {
// Has registered dynamic class mediator loaders in the deployment store.
// Try to load class from them.
Iterator<ClassLoader> dynamicClassMediatorLoaders = dynamicClassMediatorLoaderMap.values().iterator();
while (dynamicClassMediatorLoaders.hasNext()) {
try {
clazz = dynamicClassMediatorLoaders.next().loadClass(name.getAttributeValue());
break;
} catch (Exception ignore) {
}
}
}
}
}
if (clazz == null) {
try {
clazz = getClass().getClassLoader().loadClass(name.getAttributeValue());
} catch (ClassNotFoundException e) {
String msg = "Error loading class : " + name.getAttributeValue() + " - Class not found";
log.error(msg, e);
throw new SynapseException(msg, e);
}
}
try {
mediator = (Mediator) clazz.newInstance();
} catch (Throwable e) {
String msg = "Error in instantiating class : " + name.getAttributeValue();
log.error(msg, e);
throw new SynapseException(msg, e);
}
classMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
// after successfully creating the mediator
// set its common attributes such as tracing etc
classMediator.setMediator(mediator);
processAuditStatus(classMediator, elem);
return classMediator;
}
use of org.apache.synapse.mediators.ext.ClassMediator in project wso2-synapse by wso2.
the class ClassMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof ClassMediator)) {
handleException("Unsupported mediator passed in for serialization : " + m.getType());
}
ClassMediator mediator = (ClassMediator) m;
OMElement clazz = fac.createOMElement("class", synNS);
saveTracingState(clazz, mediator);
if (mediator.getMediator() != null && mediator.getMediator().getClass().getName() != null) {
clazz.addAttribute(fac.createOMAttribute("name", nullNS, mediator.getMediator().getClass().getName()));
} else {
handleException("Invalid class mediator. The class name is required");
}
super.serializeProperties(clazz, mediator.getProperties());
return clazz;
}
Aggregations