use of org.apache.synapse.mediators.bean.Target in project wso2-synapse by wso2.
the class BeanMediatorSerializerTest method testSerializeSpecificMediator3.
/**
* Test serializeSpecificMediator with GET_PROPERTY action and assert the action.
*/
@Test
public void testSerializeSpecificMediator3() {
BeanMediatorSerializer beanMediatorSerializer = new BeanMediatorSerializer();
BeanMediator mediator = new BeanMediator();
mediator.setAction(BeanMediator.Action.GET_PROPERTY);
mediator.setVarName("loc");
mediator.setPropertyName("testProperty");
Target target = new Target("attr", TestUtils.createOMElement("<target attr=\"testTarget\">"));
mediator.setTarget(target);
OMElement element = beanMediatorSerializer.serializeSpecificMediator(mediator);
Assert.assertEquals("GET_PROPERTY action is not performed", "GET_PROPERTY", element.getAttributeValue(new QName(BeanConstants.ACTION)));
}
use of org.apache.synapse.mediators.bean.Target in project wso2-synapse by wso2.
the class BeanMediatorFactory method populateGetPropertyCase.
private void populateGetPropertyCase(BeanMediator mediator, OMElement elem) {
mediator.setAction(BeanMediator.Action.GET_PROPERTY);
populatePropertyName(mediator, elem);
if (elem.getAttributeValue(new QName(BeanConstants.TARGET)) != null) {
mediator.setTarget(new Target(BeanConstants.TARGET, elem));
} else {
handleException("'target' attribute of Bean mediator is required when 'GET_PROPERTY' " + "action is set.");
}
}
use of org.apache.synapse.mediators.bean.Target in project wso2-synapse by wso2.
the class EJBMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
EJBMediator mediator = new EJBMediator();
processAuditStatus(mediator, elem);
String attributeValue;
attributeValue = elem.getAttributeValue(new QName(EJBConstants.BEANSTALK));
if (attributeValue != null) {
mediator.setBeanstalkName(attributeValue.trim());
} else {
handleException("'beanstalk' attribute of callEjb mediator is required");
}
attributeValue = elem.getAttributeValue(new QName(BeanConstants.CLASS));
if (attributeValue != null) {
mediator.setClassName(attributeValue.trim());
} else {
handleException("'class' attribute of callEjb mediator is required");
}
attributeValue = elem.getAttributeValue(new QName(EJBConstants.STATEFUL));
if (Boolean.valueOf(attributeValue)) {
attributeValue = elem.getAttributeValue(new QName(EJBConstants.BEAN_ID));
if (attributeValue != null) {
mediator.setBeanId(new ValueFactory().createValue(EJBConstants.BEAN_ID, elem));
} else {
handleException("'id' attribute is required for stateful session bean " + "invocations.");
}
}
boolean remove;
attributeValue = elem.getAttributeValue(new QName(EJBConstants.REMOVE));
remove = Boolean.valueOf(attributeValue);
if (remove) {
mediator.setRemove(true);
}
if (elem.getAttributeValue(new QName(BeanConstants.TARGET)) != null) {
mediator.setTarget(new Target(BeanConstants.TARGET, elem));
}
attributeValue = elem.getAttributeValue(new QName(EJBConstants.JNDI_NAME));
if (attributeValue != null) {
mediator.setJndiName(attributeValue);
}
OMElement argumentsElem = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, EJBConstants.ARGS));
if (argumentsElem != null) {
Iterator itr = argumentsElem.getChildrenWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, EJBConstants.ARG));
while (itr.hasNext()) {
OMElement argElem = (OMElement) itr.next();
if (argElem.getAttributeValue(ATT_VALUE) != null) {
mediator.addArgument(new ValueFactory().createValue(BeanConstants.VALUE, argElem));
} else {
handleException("'value' attribute of 'arg' element is required.");
}
}
}
attributeValue = elem.getAttributeValue(new QName(EJBConstants.METHOD));
if (attributeValue != null) {
Method method = null;
try {
method = BeanUtils.resolveMethod(Class.forName(mediator.getClassName()), attributeValue, mediator.getArgumentList().size());
} catch (ClassNotFoundException e) {
handleException("Could not load '" + mediator.getClassName() + "' class.", e);
}
mediator.setMethod(method);
} else if (!remove) {
handleException("'method' attribute of EJB mediator is optional only when it's a " + "bean removal.");
}
return mediator;
}
Aggregations