in modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathVariableContext.java [131:254]
public Object getVariableValue(String namespaceURI, String prefix, String localName)
throws UnresolvableException {
if (namespaceURI == null) {
if (env != null) {
if (SynapseXPathConstants.SOAP_BODY_VARIABLE.equals(localName)) {
return env.getBody();
} else if (SynapseXPathConstants.SOAP_HEADER_VARIABLE.equals(localName)) {
return env.getHeader();
}
}
if (prefix != null && !"".equals(prefix) && synCtx != null) {
if (SynapseXPathConstants.MESSAGE_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
return synCtx.getProperty(localName);
} else if (SynapseXPathConstants.AXIS2_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
return ((Axis2MessageContext)
synCtx).getAxis2MessageContext().getProperty(localName);
} else if (SynapseXPathConstants.FUNC_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
TemplateContext topCtxt = functionStack.peek();
if (topCtxt != null) {
Object result = topCtxt.getParameterValue(localName);
if (result != null && result instanceof SynapseXPath && env != null) {
SynapseXPath expression = (SynapseXPath) topCtxt.getParameterValue(localName);
try {
return expression.evaluate(env);
} catch (JaxenException e) {
return null;
}
} else {
return result;
}
}
} else if (SynapseXPathConstants.TRANSPORT_VARIABLE_PREFIX.equals(prefix)) {
org.apache.axis2.context.MessageContext axis2MessageContext =
((Axis2MessageContext) synCtx).getAxis2MessageContext();
Object headers = axis2MessageContext.getProperty(
org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
return headersMap.get(localName);
} else {
return null;
}
} else if (SynapseXPathConstants.URL_VARIABLE_PREFIX.equals(prefix)) {
EndpointReference toEPR = synCtx.getTo();
if (toEPR != null) {
String completeURL = toEPR.getAddress();
AxisBindingOperation axisBindingOperation = (AxisBindingOperation)
((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(
Constants.AXIS_BINDING_OPERATION);
String queryParameterSeparator = null;
if (axisBindingOperation != null) {
queryParameterSeparator = (String) axisBindingOperation.getProperty(
WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
}
if (queryParameterSeparator == null) {
queryParameterSeparator = WSDL20DefaultValueHolder.
ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR_DEFAULT;
}
int i = completeURL.indexOf("?");
if (i > -1) {
String queryString = completeURL.substring(i + 1);
if (queryString != null && !queryString.equals("")) {
String params[] = queryString.split(queryParameterSeparator);
if (params == null || params.length == 0) {
return "";
}
for (String param : params) {
String temp[] = param.split("=");
if (temp != null && temp.length >= 1) {
if (temp[0].equalsIgnoreCase(localName)) {
try {
return temp.length > 1 ?
URIEncoderDecoder.decode(temp[1]) : "";
} catch (UnsupportedEncodingException e) {
String msg = "Couldn't decode the URL parameter " +
"value " + temp[1] +
" with name " + localName;
log.error(msg, e);
throw new UnresolvableException(
msg + e.getMessage());
}
}
}
}
}
}
}
return "";
} else {
Object o = synCtx.getProperty(prefix);
if (o instanceof Map) {
Object valueObject = ((Map) o).get(localName);
if (valueObject != null) {
return valueObject.toString();
}
}
}
}
}
//try resolving using available custom extensions
Object obj = XpathExtensionUtil.resolveVariableContext(
synCtx,namespaceURI,prefix,localName);
if (obj != null) {
return obj;
}
return parent.getVariableValue(namespaceURI, prefix, localName);
}