in modules/core/src/main/java/org/apache/synapse/config/xml/HeaderMediatorFactory.java [54:139]
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
HeaderMediator headerMediator = new HeaderMediator();
OMAttribute name = elem.getAttribute(ATT_NAME);
OMAttribute value = elem.getAttribute(ATT_VALUE);
OMAttribute exprn = elem.getAttribute(ATT_EXPRN);
OMAttribute action = elem.getAttribute(ATT_ACTION);
OMAttribute scope = elem.getAttribute(ATT_SCOPE);
// Setting Header Name
if (name == null || name.getAttributeValue() == null) {
// Name is required unless otherwise we are setting an embedded XML
if (!isEmbeddedXML(elem)) {
handleException("A valid name attribute is required for the header mediator");
}
} else {
if (scope == null) {
String nameAtt = name.getAttributeValue();
// Known Headers
if (SynapseConstants.HEADER_TO.equals(nameAtt) ||
SynapseConstants.HEADER_FROM.equals(nameAtt) ||
SynapseConstants.HEADER_ACTION.equals(nameAtt) ||
SynapseConstants.HEADER_FAULT.equals(nameAtt) ||
SynapseConstants.HEADER_REPLY_TO.equals(nameAtt) ||
SynapseConstants.HEADER_RELATES_TO.equals(nameAtt)) {
headerMediator.setQName(new QName(nameAtt));
} else {
// SOAP Headers
setSOAPHeader(headerMediator, elem, name);
}
} else {
String scopeAttValue = scope.getAttributeValue();
if (XMLConfigConstants.HEADER_SCOPE_SOAP.equalsIgnoreCase(scopeAttValue)) {
setSOAPHeader(headerMediator, elem, name);
} else if (XMLConfigConstants.HEADER_SCOPE_TRANSPORT.equalsIgnoreCase(scopeAttValue)) {
headerMediator.setQName(new QName(name.getAttributeValue()));
} else {
handleException("Unsupported Scope : " + scopeAttValue + " . Only " + XMLConfigConstants.HEADER_SCOPE_SOAP
+ " and " + XMLConfigConstants.HEADER_SCOPE_TRANSPORT + " allowed");
}
headerMediator.setScope(scopeAttValue);
}
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(headerMediator,elem);
// The action attribute is optional, if provided and equals to 'remove' the
// header mediator will act as a header remove mediator
if (action != null && "remove".equals(action.getAttributeValue())) {
headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
}
if (headerMediator.getAction() == HeaderMediator.ACTION_SET &&
value == null && exprn == null && !headerMediator.isImplicit()) {
handleException("A 'value' or 'expression' attribute is required for a [set] " +
"header mediator");
}
if (value != null && value.getAttributeValue() != null) {
headerMediator.setValue(value.getAttributeValue());
} else if (exprn != null && exprn.getAttributeValue() != null) {
try {
headerMediator.setExpression(SynapseXPathFactory.getSynapseXPath(elem, ATT_EXPRN));
} catch (JaxenException je) {
handleException("Invalid XPath expression : " + exprn.getAttributeValue());
}
} else if (headerMediator.isImplicit()) { // we have an implicit, non standard header
Iterator i = elem.getChildElements();
if (i == null) {
handleException("A non standard header with both value and expression null must " +
"contain an embedded XML definition.");
return null;
}
while (i.hasNext()) {
headerMediator.addEmbeddedXml((OMElement) i.next());
}
}
return headerMediator;
}