use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class SALoadbalanceEndpointFactory method createEndpoint.
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
// create the endpoint, manager and the algorithms
SALoadbalanceEndpoint loadbalanceEndpoint = new SALoadbalanceEndpoint();
// get the session for this endpoint
OMElement sessionElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "session"));
if (sessionElement != null) {
OMElement sessionTimeout = sessionElement.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sessionTimeout"));
if (sessionTimeout != null) {
try {
loadbalanceEndpoint.setSessionTimeout(Long.parseLong(sessionTimeout.getText().trim()));
} catch (NumberFormatException nfe) {
handleException("Invalid session timeout value : " + sessionTimeout.getText());
}
}
String type = sessionElement.getAttributeValue(new QName("type"));
if (type.equalsIgnoreCase("soap")) {
Dispatcher soapDispatcher = new SoapSessionDispatcher();
loadbalanceEndpoint.setDispatcher(soapDispatcher);
} else if (type.equalsIgnoreCase("http")) {
Dispatcher httpDispatcher = new HttpSessionDispatcher();
loadbalanceEndpoint.setDispatcher(httpDispatcher);
} else if (type.equalsIgnoreCase("simpleClientSession")) {
Dispatcher csDispatcher = new SimpleClientSessionDispatcher();
loadbalanceEndpoint.setDispatcher(csDispatcher);
}
} else {
handleException("Session affinity endpoints should " + "have a session element in the configuration.");
}
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
loadbalanceEndpoint.setName(name.getAttributeValue());
}
OMElement loadbalanceElement;
loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));
if (loadbalanceElement != null) {
// set endpoints
List<Endpoint> endpoints = getEndpoints(loadbalanceElement, loadbalanceEndpoint, properties);
loadbalanceEndpoint.setChildren(endpoints);
// set load balance algorithm
LoadbalanceAlgorithm algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
loadbalanceEndpoint.setAlgorithm(algorithm);
// set buildMessage attribute
String buildMessageAtt = loadbalanceElement.getAttributeValue(new QName(XMLConfigConstants.BUILD_MESSAGE));
if (buildMessageAtt != null) {
loadbalanceEndpoint.setBuildMessageAttAvailable(true);
if (JavaUtils.isTrueExplicitly(buildMessageAtt)) {
loadbalanceEndpoint.setBuildMessageAtt(true);
}
}
// process the parameters
processProperties(loadbalanceEndpoint, epConfig);
return loadbalanceEndpoint;
}
return null;
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class EndpointFactory method createEndpointWithName.
/**
* Make sure that the endpoints created by the factory has a name
*
* @param epConfig OMElement containing the endpoint configuration.
* @param anonymousEndpoint false if the endpoint has a name. true otherwise.
* @param properties bag of properties to pass in any information to the factory
* @return Endpoint implementation for the given configuration.
*/
private Endpoint createEndpointWithName(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
Endpoint ep = createEndpoint(epConfig, anonymousEndpoint, properties);
OMElement descriptionElem = epConfig.getFirstChildWithName(DESCRIPTION_Q);
if (descriptionElem != null) {
ep.setDescription(descriptionElem.getText());
}
// if the endpoint doesn't have a name we will generate a unique name.
if (anonymousEndpoint && ep.getName() == null) {
// ep.setName(ENDPOINT_NAME_PREFIX + uuid);
if (ep instanceof AbstractEndpoint) {
((AbstractEndpoint) ep).setAnonymous(true);
}
}
OMAttribute onFaultAtt = epConfig.getAttribute(ON_FAULT_Q);
if (onFaultAtt != null) {
ep.setErrorHandler(onFaultAtt.getAttributeValue());
}
return ep;
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class LoadbalanceEndpointFactory method createEndpoint.
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
// create the endpoint, manager and the algorithms
OMElement loadbalanceElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadbalance"));
if (loadbalanceElement != null) {
LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
loadbalanceEndpoint.setName(name.getAttributeValue());
}
LoadbalanceAlgorithm algorithm = null;
// set endpoints or members
if (loadbalanceElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
if (loadbalanceElement.getChildrenWithName((MEMBER)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Endpoint> endpoints = getEndpoints(loadbalanceElement, loadbalanceEndpoint, properties);
loadbalanceEndpoint.setChildren(endpoints);
algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm(loadbalanceElement, endpoints);
algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
} else if (loadbalanceElement.getFirstChildWithName(MEMBER) != null) {
if (loadbalanceElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "loadbalanceEndpoint element cannot have both member & endpoint " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Member> members = getMembers(loadbalanceElement);
loadbalanceEndpoint.setMembers(members);
algorithm = LoadbalanceAlgorithmFactory.createLoadbalanceAlgorithm2(loadbalanceElement, members);
loadbalanceEndpoint.startApplicationMembershipTimer();
}
if (loadbalanceEndpoint.getChildren() == null && loadbalanceEndpoint.getMembers() == null) {
String msg = "Invalid Synapse configuration.\n" + "A LoadbalanceEndpoint must have child elements, but the LoadbalanceEndpoint " + "'" + loadbalanceEndpoint.getName() + "' does not have any child elements.";
log.error(msg);
throw new SynapseException(msg);
}
// set load balance algorithm
loadbalanceEndpoint.setAlgorithm(algorithm);
// set if failover is turned off
String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
if (failover != null && failover.equalsIgnoreCase("false")) {
loadbalanceEndpoint.setFailover(false);
}
// set buildMessage attribute
String buildMessageAtt = loadbalanceElement.getAttributeValue(new QName(XMLConfigConstants.BUILD_MESSAGE));
if (buildMessageAtt != null) {
loadbalanceEndpoint.setBuildMessageAttAvailable(true);
if (JavaUtils.isTrueExplicitly(buildMessageAtt)) {
loadbalanceEndpoint.setBuildMessageAtt(true);
}
}
// process the parameters
processProperties(loadbalanceEndpoint, epConfig);
return loadbalanceEndpoint;
}
// ToDo
return null;
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class ResourceFactory method configureURLMappings.
private static void configureURLMappings(Resource resource, OMElement resourceElt) {
OMAttribute urlMappingAtt = resourceElt.getAttribute(new QName("url-mapping"));
OMAttribute uriTemplateAtt = resourceElt.getAttribute(new QName("uri-template"));
if (urlMappingAtt != null && !"".equals(urlMappingAtt.getAttributeValue())) {
resource.setDispatcherHelper(new URLMappingHelper(urlMappingAtt.getAttributeValue()));
} else if (uriTemplateAtt != null && !"".equals(uriTemplateAtt.getAttributeValue())) {
resource.setDispatcherHelper(new URITemplateHelper(uriTemplateAtt.getAttributeValue()));
}
}
use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.
the class ResourceFactory method configureFilters.
private static void configureFilters(Resource resource, OMElement resourceElt) {
OMAttribute protocolAtt = resourceElt.getAttribute(new QName("protocol"));
if (protocolAtt != null && !"".equals(protocolAtt.getAttributeValue())) {
if (Constants.TRANSPORT_HTTP.equals(protocolAtt.getAttributeValue())) {
resource.setProtocol(RESTConstants.PROTOCOL_HTTP_ONLY);
} else if (Constants.TRANSPORT_HTTPS.equals(protocolAtt.getAttributeValue())) {
resource.setProtocol(RESTConstants.PROTOCOL_HTTPS_ONLY);
} else {
handleException("Invalid protocol name: " + protocolAtt.getAttributeValue());
}
}
OMAttribute contentTypeAtt = resourceElt.getAttribute(new QName("content-type"));
if (contentTypeAtt != null && !"".equals(contentTypeAtt.getAttributeValue())) {
resource.setContentType(contentTypeAtt.getAttributeValue());
}
OMAttribute userAgentAtt = resourceElt.getAttribute(new QName("user-agent"));
if (userAgentAtt != null && !"".equals(userAgentAtt.getAttributeValue())) {
resource.setUserAgent(userAgentAtt.getAttributeValue());
}
OMAttribute methodsAtt = resourceElt.getAttribute(new QName("methods"));
if (methodsAtt != null && !"".equals(methodsAtt.getAttributeValue())) {
String[] methods = methodsAtt.getAttributeValue().trim().split(" ");
for (String method : methods) {
boolean added = resource.addMethod(method);
if (!added) {
handleException("Invalid or duplicate method definition for resource");
}
}
}
}
Aggregations