use of org.apache.synapse.endpoints.RecipientListEndpoint in project wso2-synapse by wso2.
the class RecipientListEndpointFactory method createEndpoint.
@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
OMElement recipientListElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "recipientlist"));
if (recipientListElement != null) {
// create endpoint
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
recipientListEndpoint.setName(name.getAttributeValue());
}
// set endpoints or members
if (recipientListElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
if (recipientListElement.getChildrenWithName((MEMBER)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Endpoint> endpoints = getEndpoints(recipientListElement, recipientListEndpoint, properties);
recipientListEndpoint.setChildren(endpoints);
} else if (recipientListElement.getFirstChildWithName(MEMBER) != null) {
if (recipientListElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "recipientListElement element cannot have both member & endpoint " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Member> members = getMembers(recipientListElement);
recipientListEndpoint.setMembers(members);
} else if (recipientListElement.getFirstChildWithName(DYNAMIC_SET) != null) {
OMElement dynamicSetElement = recipientListElement.getFirstChildWithName(DYNAMIC_SET);
Value dynamicEndpointSet = new ValueFactory().createValue("value", dynamicSetElement);
String maxStr = dynamicSetElement.getAttributeValue(new QName("max-cache"));
int maxCache = -1;
try {
maxCache = Integer.parseInt(maxStr);
} catch (NumberFormatException e) {
}
recipientListEndpoint = new RecipientListEndpoint(maxCache < 0 ? RecipientListEndpoint.DEFAULT_MAX_POOL : maxCache);
if (name != null) {
recipientListEndpoint.setName(name.getAttributeValue());
}
recipientListEndpoint.setDynamicEnpointSet(dynamicEndpointSet);
}
if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEnpointSet() == null) {
String msg = "Invalid Synapse configuration.\n" + "A RecipientListEndpoint must have child/member elements, but the RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' does not have any child/member/dynamic endpoint elements.";
log.error(msg);
throw new SynapseException(msg);
}
// process the parameters
processProperties(recipientListEndpoint, epConfig);
return recipientListEndpoint;
}
return null;
}
use of org.apache.synapse.endpoints.RecipientListEndpoint 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.RecipientListEndpoint in project wso2-synapse by wso2.
the class RecipientListEndpointTest method test.
public void test() throws Exception {
String inputXml = "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" + "<recipientlist>" + "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" + "<http uri-template=\"URI Template\" method=\"GET\" />" + "</endpoint>" + "</recipientlist>" + "</endpoint>";
OMElement inputElement = createOMElement(inputXml);
RecipientListEndpoint endpoint = (RecipientListEndpoint) RecipientListEndpointFactory.getEndpointFromElement(inputElement, true, null);
OMElement serializedResponse = RecipientListEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue("Endpoint not serialized!", compare(serializedResponse, inputElement));
}
Aggregations