use of org.apache.synapse.endpoints.ClassEndpoint in project wso2-synapse by wso2.
the class ClassEndpointSerializationTest method testClassEndpointScenarioThree.
public void testClassEndpointScenarioThree() throws Exception {
String inputXML = "<endpoint name=\"testEndpoint\" xmlns=" + "\"http://ws.apache.org/ns/synapse\">" + "<class name=\"org.apache.synapse.config.xml.endpoints.CustomClassEndpoint\">" + "<parameter xmlns=" + "\"\" name=\"foo\">XYZ</parameter>" + "</class>" + "</endpoint>";
OMElement inputElement = createOMElement(inputXML);
ClassEndpoint endpoint = (ClassEndpoint) ClassEndpointFactory.getEndpointFromElement(inputElement, false, null);
OMElement serializedOut = ClassEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue(compare(serializedOut, inputElement));
}
use of org.apache.synapse.endpoints.ClassEndpoint in project wso2-synapse by wso2.
the class ClassEndpointFactory method createEndpoint.
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
ClassEndpoint clazzEndpoint = new ClassEndpoint();
OMAttribute endpointName = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (endpointName != null) {
clazzEndpoint.setName(endpointName.getAttributeValue());
}
OMElement classElement = epConfig.getFirstChildWithName(CLASS_QNAME);
if (classElement == null) {
return null;
}
String nameAttr = classElement.getAttributeValue(NAME_QNAME);
if (nameAttr == null) {
return null;
}
Endpoint endpoint = null;
try {
Class clazz = Class.forName(nameAttr);
endpoint = (Endpoint) clazz.newInstance();
for (Iterator iter = classElement.getChildrenWithName(PARAMETER_QNAME); iter.hasNext(); ) {
OMElement paramEle = (OMElement) iter.next();
setParameter(endpoint, paramEle, clazzEndpoint);
}
} catch (Exception e) {
handleException("Cannot create class endpoint", e);
}
clazzEndpoint.setClassEndpoint(endpoint);
return clazzEndpoint;
}
use of org.apache.synapse.endpoints.ClassEndpoint in project wso2-synapse by wso2.
the class ClassEndpointSerializer method serializeEndpoint.
@Override
protected OMElement serializeEndpoint(Endpoint endpoint) {
if (!(endpoint instanceof ClassEndpoint)) {
handleException("Invalid endpoint :" + endpoint.getName());
}
fac = OMAbstractFactory.getOMFactory();
ClassEndpoint classEndpoint = (ClassEndpoint) endpoint;
OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
serializeCommonAttributes(classEndpoint, endpointElement);
OMElement clazzElement = fac.createOMElement("class", SynapseConstants.SYNAPSE_OMNAMESPACE);
if (classEndpoint.getClassEndpoint() != null && classEndpoint.getClassEndpoint().getClass().getName() != null) {
clazzElement.addAttribute(fac.createOMAttribute("name", SynapseConstants.NULL_NAMESPACE, classEndpoint.getClassEndpoint().getClass().getName()));
} else {
handleException("Invalid class endpoint. Class name is required");
}
serializeParameters(classEndpoint, clazzElement);
endpointElement.addChild(clazzElement);
return endpointElement;
}
use of org.apache.synapse.endpoints.ClassEndpoint in project wso2-synapse by wso2.
the class ClassEndpointSerializationTest method testClassEndpointScenarioTwo.
public void testClassEndpointScenarioTwo() throws Exception {
String inputXML = "<endpoint name=\"testEndpoint\" xmlns=" + "\"http://ws.apache.org/ns/synapse\">" + "<class name=\"org.apache.synapse.config.xml.endpoints.CustomClassEndpoint\"/>" + "</endpoint>";
OMElement inputElement = createOMElement(inputXML);
ClassEndpoint endpoint = (ClassEndpoint) ClassEndpointFactory.getEndpointFromElement(inputElement, false, null);
OMElement serializedOut = ClassEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue(compare(serializedOut, inputElement));
}
use of org.apache.synapse.endpoints.ClassEndpoint in project wso2-synapse by wso2.
the class ClassEndpointSerializationTest method testClassEndpointScenarioOne.
public void testClassEndpointScenarioOne() throws Exception {
String inputXML = "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" + "<class name=\"org.apache.synapse.config.xml.endpoints.CustomClassEndpoint\"/>" + "</endpoint>";
OMElement inputElement = createOMElement(inputXML);
ClassEndpoint endpoint = (ClassEndpoint) ClassEndpointFactory.getEndpointFromElement(inputElement, true, null);
OMElement serializedOut = ClassEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue(compare(serializedOut, inputElement));
}
Aggregations