Skip to content

Commit

Permalink
Merge pull request #2279 from DedunuKarunarathne/master
Browse files Browse the repository at this point in the history
Initialize custom Xpath extensions in unit test synapse environment
  • Loading branch information
DedunuKarunarathne authored Jan 9, 2025
2 parents 583a722 + ca24627 commit f99206c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
import org.apache.synapse.eventing.SynapseEventSource;
import org.apache.synapse.task.*;
import org.wso2.securevault.secret.handler.SharedSecretCallbackHandlerCache;
import org.apache.synapse.util.xpath.ext.SynapseXpathFunctionContextProvider;
import org.apache.synapse.util.xpath.ext.SynapseXpathVariableResolver;
import org.apache.synapse.util.xpath.ext.XpathExtensionUtil;

import java.io.File;
Expand Down Expand Up @@ -396,7 +394,7 @@ public SynapseEnvironment createSynapseEnvironment() {
}

//we initialize xpath extensions here since synapse environment is available
initXpathExtensions(synapseEnvironment);
XpathExtensionUtil.initXpathExtensions(synapseEnvironment);

try {
deployMediationLibraryArtifacts();
Expand All @@ -417,34 +415,6 @@ public SynapseEnvironment createSynapseEnvironment() {
return synapseEnvironment;
}

/**
* This method initializes Xpath Extensions available through synapse.properties file.
* Xpath Extensions can be defined in Variable Context Extensions + Function Context Extensions
* synapse.xpath.var.extensions --> Variable Extensions
* synapse.xpath.func.extensions --> Function Extensions
*
* @param synapseEnvironment SynapseEnvironment
*/
private void initXpathExtensions(SynapseEnvironment synapseEnvironment) {
Axis2SynapseEnvironment axis2SynapseEnvironment = (Axis2SynapseEnvironment) synapseEnvironment;

/*Initialize Function Context extensions for xpath
*/
List<SynapseXpathFunctionContextProvider> functionExtensions =
XpathExtensionUtil.getRegisteredFunctionExtensions();
for (SynapseXpathFunctionContextProvider functionExtension : functionExtensions) {
axis2SynapseEnvironment.setXpathFunctionExtensions(functionExtension);
}

/*Initialize Variable Context extensions for xpath
*/
List<SynapseXpathVariableResolver> variableExtensions =
XpathExtensionUtil.getRegisteredVariableExtensions();
for (SynapseXpathVariableResolver variableExtension : variableExtensions) {
axis2SynapseEnvironment.setXpathVariableExtensions(variableExtension);
}
}

/**
* The mediation library deployer will handling the process of deploying the
* libararyArtifacts, this is required since the library specific artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.synapse.deployers.ProxyServiceDeployer;
import org.apache.synapse.deployers.SequenceDeployer;
import org.apache.synapse.deployers.TemplateDeployer;
import org.apache.synapse.util.xpath.ext.XpathExtensionUtil;

import java.util.AbstractMap;
import java.util.Map;
Expand Down Expand Up @@ -209,6 +210,7 @@ private ConfigurationContext createConfigurationContext(SynapseConfiguration syn
axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
configurationContext.setAxisConfiguration(axisConfiguration);
XpathExtensionUtil.initXpathExtensions(synapseEnvironment);

return configurationContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.synapse.SynapseException;
import org.apache.synapse.config.SynapsePropertiesLoader;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
import org.jaxen.Function;

import java.util.ArrayList;
Expand All @@ -50,6 +51,32 @@ public class XpathExtensionUtil {

private static final Log log = LogFactory.getLog(XpathExtensionUtil.class);

/**
* This method initializes Xpath Extensions available through synapse.properties file.
* Xpath Extensions can be defined in Variable Context Extensions + Function Context Extensions
* synapse.xpath.var.extensions --> Variable Extensions
* synapse.xpath.func.extensions --> Function Extensions
*
* @param synapseEnvironment SynapseEnvironment
*/
public static void initXpathExtensions(SynapseEnvironment synapseEnvironment) {
Axis2SynapseEnvironment axis2SynapseEnvironment = (Axis2SynapseEnvironment) synapseEnvironment;

/*Initialize Function Context extensions for xpath
*/
List<SynapseXpathFunctionContextProvider> functionExtensions = getRegisteredFunctionExtensions();
for (SynapseXpathFunctionContextProvider functionExtension : functionExtensions) {
axis2SynapseEnvironment.setXpathFunctionExtensions(functionExtension);
}

/*Initialize Variable Context extensions for xpath
*/
List<SynapseXpathVariableResolver> variableExtensions = getRegisteredVariableExtensions();
for (SynapseXpathVariableResolver variableExtension : variableExtensions) {
axis2SynapseEnvironment.setXpathVariableExtensions(variableExtension);
}
}

/**
* Get all registered variable context extensions. Synapse will look for synapse.properties
* property synapse.xpath.var.extensions
Expand Down

0 comments on commit f99206c

Please sign in to comment.