use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class BeanMediatorFactoryTest method testCreateSpecificMediator3.
/**
* Getting the property of BeanMediator and asserting the action.
*
* @throws XMLStreamException - XMLStreamException.
*/
@Test
public void testCreateSpecificMediator3() throws XMLStreamException {
BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
String inputXML = "<bean action=\"GET_PROPERTY\" property=\"latitude\" value=\"{//latitude}\" var=\"loc\" " + "target=\"target\" xmlns:ns3=\"http://org.apache.synapse/xsd\" " + "xmlns:ns=\"http://org.apache.synapse/xsd\"></bean>\n";
OMElement element = AXIOMUtil.stringToOM(inputXML);
Mediator mediator = beanMediatorFactory.createSpecificMediator(element, null);
Assert.assertTrue("BeanMediator is not created successfully.", mediator instanceof BeanMediator);
BeanMediator beanMediator = (BeanMediator) mediator;
Assert.assertEquals("GET_PROPERTY action is not set", BeanMediator.Action.GET_PROPERTY, beanMediator.getAction());
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class AbstractListMediatorFactory method addChildren.
protected static void addChildren(OMElement el, ListMediator m, Properties properties) {
Iterator it = el.getChildren();
while (it.hasNext()) {
OMNode child = (OMNode) it.next();
if (child instanceof OMElement) {
if (!DESCRIPTION_Q.equals(((OMElement) child).getQName())) {
// neglect the description tag
Mediator med = MediatorFactoryFinder.getInstance().getMediator((OMElement) child, properties);
if (med != null) {
m.addChild(med);
} else {
String msg = "Unknown mediator : " + ((OMElement) child).getLocalName();
log.error(msg);
throw new SynapseException(msg);
}
}
} else if (child instanceof OMComment) {
CommentMediator commendMediator = new CommentMediator();
commendMediator.setCommentText(((OMComment) child).getValue());
m.addChild(commendMediator);
}
}
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class AbstractMediatorFactory method createMediator.
/**
* Creates the mediator by looking at the given XML element. This method handles
* extracting the common information from the respective element. It delegates the mediator
* specific building to the {@link #createSpecificMediator(org.apache.axiom.om.OMElement,
* java.util.Properties)} method, which has tobe implemented by the respective mediators</p>
*
* <p>This method has been marked as <code>final</code> to avoid mistakenly overwriting
* this method instead of the {@link #createSpecificMediator(org.apache.axiom.om.OMElement,
* java.util.Properties)} by the sub classes
*
* @param elem configuration element of the mediator to be built
* @return built mediator using the above element
*/
public final Mediator createMediator(OMElement elem, Properties properties) {
Mediator mediator = createSpecificMediator(elem, properties);
OMElement descElem = elem.getFirstChildWithName(DESCRIPTION_Q);
if (descElem != null) {
mediator.setDescription(descElem.getText());
}
OMAttribute attDescription = elem.getAttribute(ATT_DESCRIPTION);
if (attDescription != null) {
mediator.setShortDescription(attDescription.getAttributeValue());
}
return mediator;
}
use of org.apache.synapse.Mediator 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.Mediator in project wso2-synapse by wso2.
the class HandlerUtil method mediateInMessage.
public static boolean mediateInMessage(Log log, MessageContext messageContext, org.apache.synapse.MessageContext synCtx) throws AxisFault {
AxisService service = messageContext.getAxisService();
if (service != null) {
Parameter inMediationParam = service.getParameter(HandlerConstants.IN_SEQUENCE_PARAM_NAME);
if (inMediationParam != null && inMediationParam.getValue() != null) {
if (inMediationParam.getValue() instanceof Mediator) {
Mediator inMessageSequence = (Mediator) inMediationParam.getValue();
return inMessageSequence.mediate(synCtx);
} else if (inMediationParam.getValue() instanceof String) {
Mediator inMessageSequence = synCtx.getConfiguration().getSequence((String) inMediationParam.getValue());
return inMessageSequence.mediate(synCtx);
} else {
if (log.isDebugEnabled()) {
log.debug("The provided in message mediation " + "sequence is not a proper mediator");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Couldn't find the incoming mediation for the service " + service.getName());
}
}
} else {
String message = "Couldn't find the Service for the associated message with id " + messageContext.getMessageID();
log.error(message);
throw new AxisFault(message);
}
return true;
}
Aggregations