use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.
the class BeanMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
BeanMediator mediator = new BeanMediator();
processAuditStatus(mediator, elem);
String attributeValue;
attributeValue = elem.getAttributeValue(new QName(BeanConstants.VAR));
if (attributeValue != null) {
mediator.setVarName(attributeValue);
} else {
handleException("'var' attribute of Bean mediator is required.");
}
attributeValue = elem.getAttributeValue(new QName(BeanConstants.ACTION));
if (attributeValue != null) {
try {
switch(BeanMediator.Action.valueOf(attributeValue.toUpperCase())) {
case CREATE:
populateCreateBeanCase(mediator, elem);
break;
case REMOVE:
mediator.setAction(BeanMediator.Action.REMOVE);
break;
case SET_PROPERTY:
populateSetPropertyCase(mediator, elem);
break;
case GET_PROPERTY:
populateGetPropertyCase(mediator, elem);
break;
default:
assert false;
}
} catch (IllegalArgumentException e) {
handleException("'action' attribute of bean mediator must be set to 'CREATE', " + "'REMOVE', 'SET_PROPERTY' or 'GET_PROPERTY'.");
}
} else {
handleException("'action' attribute of Bean mediator is required.");
}
return mediator;
}
use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.
the class BeanMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof BeanMediator)) {
handleException("Unsupported mediator was passed in for serialization: " + m.getType());
return null;
}
BeanMediator mediator = (BeanMediator) m;
OMElement mediatorElem = fac.createOMElement(BEAN, synNS);
saveTracingState(mediatorElem, mediator);
if (mediator.getAction() != null) {
mediatorElem.addAttribute(fac.createOMAttribute(BeanConstants.ACTION, nullNS, mediator.getAction().toString()));
} else {
handleException();
}
if (mediator.getVarName() != null) {
mediatorElem.addAttribute(fac.createOMAttribute(BeanConstants.VAR, nullNS, mediator.getVarName()));
} else {
handleException();
}
switch(mediator.getAction()) {
case CREATE:
serializeCreateBeanCase(mediatorElem, mediator);
break;
case SET_PROPERTY:
serializeSetPropertyCase(mediatorElem, mediator);
break;
case GET_PROPERTY:
serializeGetPropertyCase(mediatorElem, mediator);
break;
default:
assert false;
}
return mediatorElem;
}
use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.
the class BeanMediatorFactoryTest method testCreateSpecificMediator.
/**
* Creating a bean mediator and asserting it is created successfully.
*
* @throws XMLStreamException - XMLStreamException.
*/
@Test
public void testCreateSpecificMediator() throws XMLStreamException {
BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
String inputXML = "<bean action=\"CREATE\" class=\"org.apache.synapse.util.TestTask\" " + "var=\"loc\"></bean>";
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("CREATE action is not set", BeanMediator.Action.CREATE, beanMediator.getAction());
}
use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.
the class BeanMediatorFactoryTest method testCreateSpecificMediator4.
/**
* Removing the property of BeanMediator and asserting the action.
*
* @throws XMLStreamException - XMLStreamException.
*/
@Test
public void testCreateSpecificMediator4() throws XMLStreamException {
BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
String inputXML = "<bean action=\"REMOVE\" property=\"latitude\" value=\"{//latitude}\" var=\"loc\" " + "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("REMOVE action is not set", BeanMediator.Action.REMOVE, beanMediator.getAction());
}
use of org.apache.synapse.mediators.bean.BeanMediator in project wso2-synapse by wso2.
the class BeanMediatorSerializerTest method testSerializeSpecificMediator2.
/**
* Test serializeSpecificMediator with SET_PROPERTY action and assert the action.
*/
@Test
public void testSerializeSpecificMediator2() {
BeanMediatorSerializer beanMediatorSerializer = new BeanMediatorSerializer();
BeanMediator mediator = new BeanMediator();
mediator.setAction(BeanMediator.Action.SET_PROPERTY);
mediator.setVarName("loc");
mediator.setPropertyName("testProperty");
mediator.setValue(new Value("testValue"));
OMElement element = beanMediatorSerializer.serializeSpecificMediator(mediator);
Assert.assertEquals("SET_PROPERTY action is not performed", "SET_PROPERTY", element.getAttributeValue(new QName(BeanConstants.ACTION)));
}
Aggregations