use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class RecipientListEndpointSerializer method serializeEndpoint.
@Override
protected OMElement serializeEndpoint(Endpoint endpoint) {
if (!(endpoint instanceof RecipientListEndpoint)) {
handleException("Invalid endpoint type.");
}
fac = OMAbstractFactory.getOMFactory();
OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
RecipientListEndpoint recipientListEndpoint = (RecipientListEndpoint) endpoint;
// serialize the parameters
serializeProperties(recipientListEndpoint, endpointElement);
serializeCommonAttributes(endpoint, endpointElement);
OMElement recipientListElement = fac.createOMElement("recipientlist", SynapseConstants.SYNAPSE_OMNAMESPACE);
endpointElement.addChild(recipientListElement);
// element
if (recipientListEndpoint.getChildren() != null) {
for (Endpoint childEndpoint : recipientListEndpoint.getChildren()) {
recipientListElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
}
} else if (recipientListEndpoint.getMembers() != null) {
for (Member member : recipientListEndpoint.getMembers()) {
OMElement memberEle = fac.createOMElement("member", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement);
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())));
recipientListElement.addChild(memberEle);
}
} else {
OMElement dynamicEpEle = fac.createOMElement("endpoints", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement);
new ValueSerializer().serializeValue(recipientListEndpoint.getDynamicEnpointSet(), "value", dynamicEpEle);
dynamicEpEle.addAttribute(fac.createOMAttribute("max-cache", null, String.valueOf(recipientListEndpoint.getCurrentPoolSize())));
recipientListElement.addChild(dynamicEpEle);
}
return endpointElement;
}
use of org.apache.synapse.endpoints.Endpoint 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.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class EndpointFactory method getEndpoints.
/**
* Helper method to construct children endpoints
*
* @param listEndpointElement OMElement representing the children endpoints
* @param parent Parent endpoint
* @param properties bag of properties to pass in any information to the factory
* @return List of children endpoints
*/
protected ArrayList<Endpoint> getEndpoints(OMElement listEndpointElement, Endpoint parent, Properties properties) {
ArrayList<Endpoint> endpoints = new ArrayList<Endpoint>();
ArrayList<String> keys = new ArrayList<String>();
Iterator iter = listEndpointElement.getChildrenWithName(XMLConfigConstants.ENDPOINT_ELT);
while (iter.hasNext()) {
OMElement endptElem = (OMElement) iter.next();
Endpoint endpoint = EndpointFactory.getEndpointFromElement(endptElem, true, properties);
if (endpoint instanceof IndirectEndpoint) {
String key = ((IndirectEndpoint) endpoint).getKey();
if (!keys.contains(key)) {
keys.add(key);
} else {
handleException("Same endpoint definition cannot be used with in the siblings");
}
}
endpoint.setParentEndpoint(parent);
endpoints.add(endpoint);
}
return endpoints;
}
use of org.apache.synapse.endpoints.Endpoint 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.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class FailoverEndpointFactory method createEndpoint.
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
OMElement failoverElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "failover"));
if (failoverElement != null) {
FailoverEndpoint failoverEndpoint = new FailoverEndpoint();
// set endpoint name
String name = epConfig.getAttributeValue(new QName("name"));
if (name != null) {
failoverEndpoint.setName(name);
}
List<Endpoint> childEndpoints = getEndpoints(failoverElement, failoverEndpoint, properties);
if (childEndpoints == null || childEndpoints.size() == 0) {
String msg = "Invalid Synapse configuration.\n" + "A FailOver must have child elements, but the FailOver " + "'" + failoverEndpoint.getName() + "' does not have any child elements.";
log.error(msg);
throw new SynapseException(msg);
}
// set endpoints and return
failoverEndpoint.setChildren(getEndpoints(failoverElement, failoverEndpoint, properties));
String dynamicFO = failoverElement.getAttributeValue(new QName("dynamic"));
if (dynamicFO != null && JavaUtils.isFalseExplicitly(dynamicFO)) {
failoverEndpoint.setDynamic(false);
}
// set buildMassage property
String buildMessageAtt = failoverElement.getAttributeValue(new QName(XMLConfigConstants.BUILD_MESSAGE));
if (buildMessageAtt != null) {
failoverEndpoint.setBuildMessageAttAvailable(true);
if (JavaUtils.isTrueExplicitly(buildMessageAtt)) {
failoverEndpoint.setBuildMessageAtt(true);
}
}
// process the parameters
processProperties(failoverEndpoint, epConfig);
return failoverEndpoint;
}
return null;
}
Aggregations