use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator5.
/**
* Test SerializeSpecificMediator method with PathArgument with expression added for payloadFactory mediator
* and assert that expression is added.
*/
@Test
public void testSerializeSpecificMediator5() throws JaxenException {
PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
Argument argument = new Argument();
argument.setExpression(new SynapseXPath("//name"));
payloadFactoryMediator.addPathArgument(argument);
payloadFactoryMediator.setFormat(format);
OMElement element = serializer.serializeSpecificMediator(payloadFactoryMediator);
MediatorFactory mediatorFactory = new PayloadFactoryMediatorFactory();
Mediator mediator = mediatorFactory.createMediator(element, null);
Assert.assertNotNull(element);
Assert.assertEquals("Expression added for path argument is not serialized", "//name", ((PayloadFactoryMediator) mediator).getPathArgumentList().get(0).getExpression().toString());
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class AbstractDBMediatorFactory method buildDataSource.
/**
* Reads the data source configuration for all mediators based on the <code>AbstractDBMediator</code>
* and stores the configuration in the mediator for datasource initialization and de-serialization.
*
* @param elem the configuration element of the mediator
* @param mediator the mediator on which the configuration shall be stored
*/
protected void buildDataSource(OMElement elem, AbstractDBMediator mediator) {
OMElement pool;
try {
// get the 'pool' element and determine if we need to create a DataSource or
// lookup using JNDI
SynapseXPath xpath = new SynapseXPath("self::node()/syn:connection/syn:pool");
xpath.addNamespace("syn", XMLConfigConstants.SYNAPSE_NAMESPACE);
pool = (OMElement) xpath.selectSingleNode(elem);
if (pool.getFirstChildWithName(DSNAME_Q) != null) {
readLookupConfig(mediator, pool);
} else if (pool.getFirstChildWithName(DRIVER_Q) != null) {
readCustomDataSourceConfig(pool, mediator);
} else {
handleException("The DataSource connection information must be specified for " + "using a custom DataSource connection pool or for a JNDI lookup");
}
} catch (JaxenException e) {
handleException("Error looking up DataSource connection information", e);
}
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class Target method insert.
/**
* Inserts the given object into the target specified by the current Target object.
* @param synCtx Message Context to be enriched with the object.
* @param object Object to be inserted.
*/
public void insert(MessageContext synCtx, Object object) {
if (value.getExpression() != null && value.getExpression() instanceof SynapseXPath) {
SynapseXPath expression = (SynapseXPath) value.getExpression();
Object targetObj = null;
try {
targetObj = expression.selectSingleNode(synCtx);
} catch (JaxenException e) {
handleException("Failed to select the target.", e);
}
if (targetObj instanceof OMText) {
Object targetParent = ((OMText) targetObj).getParent();
if (targetParent != null && targetParent instanceof OMElement) {
((OMElement) targetParent).setText(object == null ? "" : object.toString());
} else {
handleException("Invalid target is specified by the expression: " + expression);
}
} else {
handleException("Invalid target is specified by the expression: " + expression);
}
} else if (value.getKeyValue() != null) {
synCtx.setProperty(value.getKeyValue(), object);
} else {
handleException("Invalid target description. " + value);
}
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class DefaultInMemorySubscriptionManager method init.
public void init() {
try {
// TODO: pick values from the constants
topicHeaderName = getPropertyValue("topicHeaderName");
if (topicHeaderName == null) {
handleException("Unable to create topic header topic header name is null");
}
topicHeaderNS = getPropertyValue("topicHeaderNS");
if (topicHeaderNS == null) {
handleException("Unable to create topic header topic header namespace is null");
}
topicXPath = new SynapseXPath("s11:Header/ns:" + topicHeaderName + " | s12:Header/ns:" + topicHeaderName);
topicXPath.addNamespace("s11", "http://schemas.xmlsoap.org/soap/envelope/");
topicXPath.addNamespace("s12", "http://www.w3.org/2003/05/soap-envelope");
topicXPath.addNamespace("ns", topicHeaderNS);
} catch (JaxenException e) {
handleException("Unable to create the topic header XPath", e);
}
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class InboundEndpoint method resolveSecureVaultExpressions.
private void resolveSecureVaultExpressions(Properties props) {
Pattern vaultLookupPattern = Pattern.compile(secureVaultRegex);
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String value = (String) entry.getValue();
Matcher lookupMatcher = vaultLookupPattern.matcher(value);
// setting value initially
String newParamValue = value;
while (lookupMatcher.find()) {
Value expression = null;
// getting the expression with out curly brackets
String expressionStr = lookupMatcher.group(0).substring(1, lookupMatcher.group(0).length() - 1);
try {
expression = new Value(new SynapseXPath(expressionStr));
} catch (JaxenException e) {
log.error("Error while building the expression : " + expressionStr);
}
if (expression != null) {
String resolvedValue = expression.evaluateValue(synapseEnvironment.createMessageContext());
if (resolvedValue == null || resolvedValue.isEmpty()) {
log.warn("Found Empty value for expression : " + expression.getExpression());
resolvedValue = "";
}
// replacing the expression with resolved value
newParamValue = newParamValue.replaceFirst(secureVaultRegex, resolvedValue);
props.put(entry.getKey(), newParamValue);
}
}
}
}
Aggregations