private static final QName HEADER_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "header");
private static final QName ATT_ACTION = new QName("action");
protected 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);
if (name == null || name.getAttributeValue() == null) {
String msg = "A valid name attribute is required for the header mediator";
log.error(msg);
throw new SynapseException(msg);
} else {
String nameAtt = name.getAttributeValue();
int colonPos = nameAtt.indexOf(":");
if (colonPos != -1) {
// has a NS prefix.. find it and the NS it maps into
String prefix = nameAtt.substring(0, colonPos);
String namespaceURI = OMElementUtils.getNameSpaceWithPrefix(prefix, elem);
if (namespaceURI == null) {
handleException("Invalid namespace prefix '" + prefix + "' in name attribute");
} else {
headerMediator.setQName(new QName(namespaceURI, nameAtt.substring(colonPos+1),
prefix));
}
} else {
// no prefix
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 {
handleException("Invalid SOAP header: " + nameAtt + " specified at the " +
"header mediator. All SOAP headers must be namespace qualified.");
}
}
}
// 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) {
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());
}
}