in core/src/main/java/flex/messaging/config/ServerConfigurationParser.java [378:484]
private void channelDefinition(Node channel) {
// Validation
requiredAttributesOrElements(channel, CHANNEL_DEFINITION_REQ_CHILDREN);
allowedAttributesOrElements(channel, CHANNEL_DEFINITION_CHILDREN);
String id = getAttributeOrChildElement(channel, ID_ATTR);
if (isValidID(id)) {
// Don't allow multiple channels with the same id
if (config.getChannelSettings(id) != null) {
// Cannot have multiple channels with the same id ''{0}''.
ConfigurationException e = new ConfigurationException();
e.setMessage(DUPLICATE_CHANNEL_ERROR, new Object[]{id});
throw e;
}
ChannelSettings channelSettings = new ChannelSettings(id);
channelSettings.setSourceFile(getSourceFileOf(channel));
// Note whether the channel-definition was for a remote endpoint
String remote = getAttributeOrChildElement(channel, REMOTE_ATTR);
channelSettings.setRemote(Boolean.valueOf(remote));
// Endpoint
Node endpoint = selectSingleNode(channel, ENDPOINT_ELEMENT);
if (endpoint != null) {
// Endpoint Validation
allowedAttributesOrElements(endpoint, ENDPOINT_CHILDREN);
String type = getAttributeOrChildElement(endpoint, CLASS_ATTR);
channelSettings.setEndpointType(type);
// The url attribute may also be specified by the deprecated uri attribute
String uri = getAttributeOrChildElement(endpoint, URL_ATTR);
if (uri == null || EMPTY_STRING.equals(uri))
uri = getAttributeOrChildElement(endpoint, URI_ATTR);
channelSettings.setUri(uri);
config.addChannelSettings(id, channelSettings);
}
channelServerOnlyAttribute(channel, channelSettings);
// Server reference
Node server = selectSingleNode(channel, SERVER_ELEMENT);
if (server != null) {
requiredAttributesOrElements(server, CHANNEL_DEFINITION_SERVER_REQ_CHILDREN);
String serverId = getAttributeOrChildElement(server, REF_ATTR);
channelSettings.setServerId(serverId);
}
// Channel Properties
NodeList properties = selectNodeList(channel, PROPERTIES_ELEMENT + "/*");
if (properties.getLength() > 0) {
ConfigMap map = properties(properties, getSourceFileOf(channel));
channelSettings.addProperties(map);
// Sniff for adaptive-frequency under flex-client-queue-processor hich requires advanced messaging support.
if (!verifyAdvancedMessagingSupport) {
ConfigMap outboundQueueProcessor = map.getPropertyAsMap(FLEX_CLIENT_OUTBOUND_QUEUE_PROCESSOR_ELEMENT, null);
if (outboundQueueProcessor != null) {
// Flex client queue processor properties
ConfigMap queueProcessorProperties = outboundQueueProcessor.getPropertyAsMap(PROPERTIES_ELEMENT, null);
if (queueProcessorProperties != null) {
// Sniff for adaptive-frequency which requires advanced messaging support.
boolean adaptiveFrequency = queueProcessorProperties.getPropertyAsBoolean(ADAPTIVE_FREQUENCY, false);
if (adaptiveFrequency)
verifyAdvancedMessagingSupport = true;
}
}
}
}
// Channel Security
// Security-constraint short-cut attribute
String ref = evaluateExpression(channel, "@" + SECURITY_CONSTRAINT_ATTR).toString().trim();
if (ref.length() > 0) {
SecurityConstraint sc = ((MessagingConfiguration) config).getSecuritySettings().getConstraint(ref);
if (sc != null) {
channelSettings.setConstraint(sc);
} else {
// {SECURITY_CONSTRAINT_ELEMENT} not found for reference '{ref}' in channel '{id}'.
ConfigurationException ex = new ConfigurationException();
ex.setMessage(REF_NOT_FOUND_IN_CHANNEL, new Object[]{SECURITY_CONSTRAINT_ATTR, ref, id});
throw ex;
}
} else {
// Inline security element
Node security = selectSingleNode(channel, SECURITY_ELEMENT);
if (security != null) {
allowedChildElements(security, EMBEDDED_SECURITY_CHILDREN);
Node constraint = selectSingleNode(security, SECURITY_CONSTRAINT_ELEMENT);
if (constraint != null) {
SecurityConstraint sc = securityConstraint(constraint, true);
channelSettings.setConstraint(sc);
}
}
}
} else {
// Invalid {CHANNEL_DEFINITION_ELEMENT} id '{id}'.
ConfigurationException ex = new ConfigurationException();
ex.setMessage(INVALID_ID, new Object[]{CHANNEL_DEFINITION_ELEMENT, id});
ex.setDetails(INVALID_ID);
throw ex;
}
}