use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class JmsStore method resolveSecureVaultExpressions.
/**
* Use secure vault to secure password in JMS Message Store.
*
* @param value Value of password from JMS Message Store
* @return the actual password from the Secure Vault Password Management.
*/
private String resolveSecureVaultExpressions(String value) {
// Password can be null, it is optional
if (value == null) {
return null;
}
Matcher lookupMatcher = vaultLookupPattern.matcher(value);
String resolvedValue = value;
if (lookupMatcher.find()) {
Value expression = null;
// getting the expression with out curly brackets
String expressionStr = lookupMatcher.group(1);
try {
expression = new Value(new SynapseXPath(expressionStr));
} catch (JaxenException e) {
throw new SynapseException("Error while building the expression : " + expressionStr, e);
}
resolvedValue = expression.evaluateValue(synapseEnvironment.createMessageContext());
if (StringUtils.isEmpty(resolvedValue)) {
log.warn("Found Empty value for expression : " + expression.getExpression());
resolvedValue = "";
}
}
return resolvedValue;
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class XSLTMediatorTest method testMultipleKeys.
/**
* Test with multiple keys including static and dynamic keys
*
* @param num number from 0 to 2
* @throws Exception Exception in case of an error in tests
*/
private void testMultipleKeys(int num) throws Exception {
String xsltKeyValue = null;
String path;
SynapseXPath xpath;
Value xsltKey;
XSLTMediator transformMediator = new XSLTMediator();
// default source, xsltFile, and state of key (dynamic or static)
String source = "";
String xsltFile = "";
boolean isDynamicKey = true;
// based on source, different XSLTFiles can be used
if (num == 0) {
source = SOURCE_STATIC_KEY;
xsltFile = "static_key.xslt";
xsltKeyValue = "StaticXsltKey";
isDynamicKey = false;
} else if (num == 1) {
source = SOURCE_DYNAMIC_KEY1;
xsltFile = "dynamic_key_1.xslt";
xsltKeyValue = "DynamicXsltKey1";
isDynamicKey = true;
} else if (num == 2) {
source = SOURCE_DYNAMIC_KEY2;
xsltFile = "dynamic_key_2.xslt";
xsltKeyValue = "DynamicXsltKey2";
isDynamicKey = true;
}
if (isDynamicKey) {
path = "//m0:CheckPriceRequest/m0:" + xsltKeyValue;
xpath = new SynapseXPath(path);
xpath.addNamespace("m0", "http://services.samples/xsd");
// Create key from dynamic key (xpath)
xsltKey = new Value(xpath);
// set XSLT transformation URL (Xpath)
transformMediator.setXsltKey(xsltKey);
} else {
// static key
path = xsltKeyValue;
// set XSLT transformation URL (static)
setXsltTransformationURL(transformMediator, path);
}
// Mediate twice for synCtx
MessageContext synCtx = new TestMessageContextBuilder().addEntry(xsltKeyValue, getClass().getResource(xsltFile)).setBodyFromString(source).addTextAroundBody().build();
transformMediator.mediate(synCtx);
synCtx = new TestMessageContextBuilder().addEntry(xsltKeyValue, getClass().getResource(xsltFile)).setBodyFromString(source).addTextAroundBody().build();
transformMediator.mediate(synCtx);
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class ValidateMediatorTest method createKeyListFromMoreKeys.
/**
* Create a Value list with given set of static keys
*
* @param keyNames Set of static keys to create list
* @return Key list
*/
private List<Value> createKeyListFromMoreKeys(String... keyNames) {
List<Value> keyList = new ArrayList<Value>();
for (String keyName : keyNames) {
// create static key using given string key name
Value xsdKey = new Value(keyName);
keyList.add(xsdKey);
}
return keyList;
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator3.
/**
* Test SerializeSpecificMediator method with Dynamic format added for payloadFactory mediator
* and assert that dynamic format is set.
*/
@Test
public void testSerializeSpecificMediator3() {
PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
payloadFactoryMediator.setFormat(format);
payloadFactoryMediator.setFormatDynamic(true);
payloadFactoryMediator.setFormatKey(new Value("testKey"));
OMElement element = serializer.serializeSpecificMediator(payloadFactoryMediator);
Assert.assertNotNull(element);
MediatorFactory mediatorFactory = new PayloadFactoryMediatorFactory();
Mediator mediator = mediatorFactory.createMediator(element, null);
Assert.assertTrue("Dynamic Format set for Mediator is not serialized", ((PayloadFactoryMediator) mediator).isFormatDynamic());
}
use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class EJBMediatorTest method testInitAndMediate.
/**
* Initializing EJBMediator and Mediating a messageContext
*/
@Test
public void testInitAndMediate() throws Exception {
SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
ServerConfigurationInformation configurationInformation = new ServerConfigurationInformation();
ServerContextInformation contextInformation = new ServerContextInformation(configurationInformation);
Mockito.when(synapseEnvironment.getServerContextInformation()).thenReturn(contextInformation);
try {
ejbMediator.init(synapseEnvironment);
Assert.fail("executed successfully when exception is expected");
} catch (Exception ex) {
Assert.assertEquals("assert exception class", SynapseException.class, ex.getClass());
Assert.assertEquals("assert exception message", "Initialization failed. BeanstalkManager not found.", ex.getMessage());
}
ejbMediator.setBeanstalkName(BEANSTALK_NAME);
EnterpriseBeanstalkManager beanstalkManager = Mockito.mock(EnterpriseBeanstalkManager.class);
contextInformation.addProperty(EnterpriseBeanstalkConstants.BEANSTALK_MANAGER_PROP_NAME, beanstalkManager);
try {
ejbMediator.init(synapseEnvironment);
Assert.fail("executed successfully when exception is expected");
} catch (Exception ex) {
Assert.assertEquals("assert exception class", SynapseException.class, ex.getClass());
Assert.assertEquals("assert exception message", "Initialization failed. '" + BEANSTALK_NAME + "' " + "beanstalk not found.", ex.getMessage());
}
beanstalk = PowerMockito.mock(EnterpriseBeanstalk.class);
Value beanId = new Value(VALUE);
ejbMediator.setBeanId(beanId);
Object obj = new Object();
PowerMockito.when(beanstalk.getEnterpriseBean(any(String.class), any(String.class), any(String.class))).thenReturn(obj);
PowerMockito.when(beanstalkManager.getBeanstalk(BEANSTALK_NAME)).thenReturn(beanstalk);
PowerMockito.mockStatic(BeanUtils.class);
PowerMockito.when(BeanUtils.invokeInstanceMethod(any(Object.class), any(Method.class), any(Object[].class))).thenReturn(new Object());
ejbMediator.init(synapseEnvironment);
String samplePayload = "<test>value</test>";
Map<String, Entry> properties = new HashMap<>();
Axis2MessageContext messageContext = TestUtils.getAxis2MessageContext(samplePayload, properties);
ejbMediator.setClassName(CLASS_NAME);
ejbMediator.setJndiName(JNDI_NAME);
Assert.assertTrue("mediation must be successful", ejbMediator.mediate(messageContext));
}
Aggregations