use of org.apache.synapse.endpoints.Endpoint 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.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class LoadbalanceEndpointSerializer method serializeEndpoint.
protected OMElement serializeEndpoint(Endpoint endpoint) {
if (!(endpoint instanceof LoadbalanceEndpoint)) {
handleException("Invalid endpoint type.");
}
fac = OMAbstractFactory.getOMFactory();
OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) endpoint;
serializeCommonAttributes(endpoint, endpointElement);
OMElement loadbalanceElement = fac.createOMElement("loadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
endpointElement.addChild(loadbalanceElement);
loadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM, loadbalanceEndpoint.getAlgorithm().getClass().getName(), null);
// set if failover is turned off in the endpoint
if (!loadbalanceEndpoint.isFailover()) {
loadbalanceElement.addAttribute("failover", "false", null);
}
if (loadbalanceEndpoint.isBuildMessageAtt()) {
loadbalanceElement.addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(loadbalanceEndpoint.isBuildMessageAtt()), null);
}
// Serialize endpoint elements which are children of the loadbalance element
if (loadbalanceEndpoint.getChildren() != null) {
for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) {
loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
}
} else {
for (Member member : loadbalanceEndpoint.getMembers()) {
OMElement memberEle = fac.createOMElement("member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
memberEle.addAttribute(fac.createOMAttribute("hostName", null, member.getHostName()));
memberEle.addAttribute(fac.createOMAttribute("httpPort", null, String.valueOf(member.getHttpPort())));
memberEle.addAttribute(fac.createOMAttribute("httpsPort", null, String.valueOf(member.getHttpsPort())));
loadbalanceElement.addChild(memberEle);
}
}
// serialize the parameters
serializeProperties(loadbalanceEndpoint, endpointElement);
return endpointElement;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class MultiXMLConfigurationSerializer method serializeLocalEntry.
public OMElement serializeLocalEntry(Object o, SynapseConfiguration synapseConfig, OMElement parent) throws Exception {
if (o instanceof TemplateMediator) {
return serializeTemplate((TemplateMediator) o, synapseConfig, parent);
} else if (o instanceof SequenceMediator) {
return serializeSequence((SequenceMediator) o, synapseConfig, parent);
} else if (o instanceof Template) {
return serializeTemplate((Template) o, synapseConfig, parent);
} else if (o instanceof Endpoint) {
return serializeEndpoint((Endpoint) o, synapseConfig, parent);
} else if (o instanceof Entry) {
Entry entry = (Entry) o;
if ((SynapseConstants.SERVER_HOST.equals(entry.getKey()) || SynapseConstants.SERVER_IP.equals(entry.getKey())) || entry.getType() == Entry.REMOTE_ENTRY) {
return null;
}
File entriesDir = createDirectory(currentDirectory, MultiXMLConfigurationBuilder.LOCAL_ENTRY_DIR);
OMElement entryElem = EntrySerializer.serializeEntry(entry, null);
String fileName = entry.getFileName();
if (fileName != null) {
if (currentDirectory == rootDirectory) {
handleDeployment(entriesDir, fileName, entry.getKey(), synapseConfig.getArtifactDeploymentStore());
}
File entryFile = new File(entriesDir, fileName);
writeToFile(entryElem, entryFile);
} else if (parent != null) {
parent.addChild(entryElem);
}
return entryElem;
}
return null;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class SendMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
SendMediator sm = new SendMediator();
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(sm, elem);
OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
if (epElement != null) {
// create the endpoint and set it in the send mediator
Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
if (endpoint != null) {
sm.setEndpoint(endpoint);
}
}
String receivingSequence = elem.getAttributeValue(RECEIVING_SEQUENCE);
if (receivingSequence != null) {
ValueFactory valueFactory = new ValueFactory();
Value value = valueFactory.createValue(XMLConfigConstants.RECEIVE, elem);
sm.setReceivingSequence(value);
}
String buildMessage = elem.getAttributeValue(BUILD_MESSAGE);
if ("true".equals(buildMessage)) {
sm.setBuildMessage(true);
}
return sm;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class CallMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
CallMediator callMediator = new CallMediator();
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(callMediator, elem);
OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
if (epElement != null) {
// create the endpoint and set it in the call mediator
Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
if (endpoint != null) {
callMediator.setEndpoint(endpoint);
}
}
OMAttribute blockingAtt = elem.getAttribute(BLOCKING_Q);
if (blockingAtt != null) {
callMediator.setBlocking(Boolean.parseBoolean(blockingAtt.getAttributeValue()));
if (callMediator.isBlocking()) {
OMAttribute initAxis2ClientOptions = elem.getAttribute(ATT_INIT_AXIS2_CLIENT_OPTIONS);
OMAttribute axis2xmlAttr = elem.getAttribute(ATT_AXIS2XML);
OMAttribute repoAttr = elem.getAttribute(ATT_REPOSITORY);
if (initAxis2ClientOptions != null) {
callMediator.setInitClientOptions(Boolean.parseBoolean(initAxis2ClientOptions.getAttributeValue()));
}
if (axis2xmlAttr != null && axis2xmlAttr.getAttributeValue() != null) {
File axis2xml = new File(axis2xmlAttr.getAttributeValue());
if (axis2xml.exists() && axis2xml.isFile()) {
callMediator.setAxis2xml(axis2xmlAttr.getAttributeValue());
} else {
handleException("Invalid axis2.xml path: " + axis2xmlAttr.getAttributeValue());
}
}
if (repoAttr != null && repoAttr.getAttributeValue() != null) {
File repo = new File(repoAttr.getAttributeValue());
if (repo.exists() && repo.isDirectory()) {
callMediator.setClientRepository(repoAttr.getAttributeValue());
} else {
handleException("Invalid repository path: " + repoAttr.getAttributeValue());
}
}
}
}
return callMediator;
}
Aggregations