Search in sources :

Example 1 with ClassEndpoint

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));
}
Also used : OMElement(org.apache.axiom.om.OMElement) ClassEndpoint(org.apache.synapse.endpoints.ClassEndpoint)

Example 2 with ClassEndpoint

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;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) ClassEndpoint(org.apache.synapse.endpoints.ClassEndpoint) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) ClassEndpoint(org.apache.synapse.endpoints.ClassEndpoint) OMAttribute(org.apache.axiom.om.OMAttribute) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ClassEndpoint

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;
}
Also used : OMElement(org.apache.axiom.om.OMElement) ClassEndpoint(org.apache.synapse.endpoints.ClassEndpoint)

Example 4 with ClassEndpoint

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));
}
Also used : OMElement(org.apache.axiom.om.OMElement) ClassEndpoint(org.apache.synapse.endpoints.ClassEndpoint)

Example 5 with ClassEndpoint

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));
}
Also used : OMElement(org.apache.axiom.om.OMElement) ClassEndpoint(org.apache.synapse.endpoints.ClassEndpoint)

Aggregations

OMElement (org.apache.axiom.om.OMElement)5 ClassEndpoint (org.apache.synapse.endpoints.ClassEndpoint)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Iterator (java.util.Iterator)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1