Repository: wso2/micro-integrator
Issue: [Management API] Cannot retrieve the list of available endpoints using management api

**Description:**
The following exception occurs when trying to retrieve the list of available endpoints using management api by invoking [1].

```
[2020-02-21 15:18:31,254] ERROR {org.wso2.carbon.inbound.endpoint.protocol.http.InboundHttpServerWorker} - Exception occurred when running org.wso2.carbon.inbound.endpoint.protocol.http.InboundHttpServerWorker java.lang.NullPointerException
        at org.wso2.micro.integrator.management.apis.EndpointResource.populateEndpointList(EndpointResource.java:95)
        at org.wso2.micro.integrator.management.apis.EndpointResource.invoke(EndpointResource.java:66)
        at org.wso2.carbon.inbound.endpoint.internal.http.api.InternalAPIDispatcher.dispatch(InternalAPIDispatcher.java:86)
        at org.wso2.carbon.inbound.endpoint.protocol.http.InboundHttpServerWorker.run(InboundHttpServerWorker.java:109)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
```

[1] - `curl -X GET "https://localhost:9164/management/endpoints" -H "accept: application/json" -H "Authorization: Bearer TOKEN" -k -i`

Changed files:
components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/EndpointResource.java

diff --git a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/EndpointResource.java b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/EndpointResource.java
index d6b28b175..54ae8399b 100644
--- a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/EndpointResource.java
+++ b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/EndpointResource.java
@@ -28,6 +28,7 @@ import org.apache.synapse.endpoints.Endpoint;
 import org.json.JSONObject;
 import org.wso2.carbon.inbound.endpoint.internal.http.api.APIResource;
 
+import javax.xml.namespace.QName;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
@@ -91,8 +92,13 @@ public class EndpointResource extends APIResource {
 
             OMElement element = EndpointSerializer.getElementFromEndpoint(ep);
             OMElement firstElement = element.getFirstElement();
-
-            String type = firstElement.getLocalName();
+            String type;
+            // For template endpoints the endpoint type can not be retrieved from firstElement
+            if (firstElement == null) {
+                type = element.getAttribute(new QName("template")).getLocalName();
+            } else {
+                type = firstElement.getLocalName();
+            }
             endpointObject.put(Constants.TYPE, type);
 
             jsonBody.getJSONArray(Constants.LIST).put(endpointObject);