From 4e86371e1a8ed3ef780ab1749586dbc3f7cddf16 Mon Sep 17 00:00:00 2001 From: Lahiru Madushanka Date: Wed, 20 Dec 2023 15:25:23 +0530 Subject: [PATCH] Fix NPE in management API for endpoints Add checks to handle endpoints without a definition. Ex: load balanced EP, failover EP Fixes wso2/micro-integrator/issues/3061 --- .../management/apis/EndpointResource.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) 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 abcff1af57..52f1798666 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 @@ -133,12 +133,17 @@ private void handleTracing(String performedBy, JsonObject payload, MessageContex SynapseConfiguration configuration = msgCtx.getConfiguration(); Endpoint endpoint = configuration.getEndpoint(endpointName); if (endpoint != null) { - AspectConfiguration aspectConfiguration = ((AbstractEndpoint) endpoint).getDefinition().getAspectConfiguration(); - JSONObject info = new JSONObject(); - info.put(ENDPOINT_NAME, endpointName); - response = Utils.handleTracing(performedBy, Constants.AUDIT_LOG_TYPE_ENDPOINT_TRACE, - Constants.ENDPOINTS, info, aspectConfiguration, endpointName, - axisMsgCtx); + if (((AbstractEndpoint) endpoint).getDefinition() != null) { + AspectConfiguration aspectConfiguration = ((AbstractEndpoint) endpoint).getDefinition() + .getAspectConfiguration(); + JSONObject info = new JSONObject(); + info.put(ENDPOINT_NAME, endpointName); + response = Utils.handleTracing(performedBy, Constants.AUDIT_LOG_TYPE_ENDPOINT_TRACE, + Constants.ENDPOINTS, info, aspectConfiguration, endpointName, axisMsgCtx); + } else { + response = Utils.createJsonError("Tracing is not supported for this endpoint", axisMsgCtx, + Constants.BAD_REQUEST); + } } else { response = Utils.createJsonError("Specified endpoint ('" + endpointName + "') not found", axisMsgCtx, Constants.BAD_REQUEST); @@ -223,9 +228,13 @@ private JSONObject getEndpointAsJson(Endpoint endpoint) { OMElement synapseConfiguration = EndpointSerializer.getElementFromEndpoint(endpoint); endpointObject.put(Constants.SYNAPSE_CONFIGURATION, synapseConfiguration); endpointObject.put(IS_ACTIVE, isEndpointActive(endpoint)); - String tracingState = ((AbstractEndpoint) endpoint).getDefinition().getAspectConfiguration().isTracingEnabled() ? Constants.ENABLED : Constants.DISABLED; - endpointObject.put(TRACING, tracingState); - + if (((AbstractEndpoint) endpoint).getDefinition() != null) { + String tracingState = ((AbstractEndpoint) endpoint).getDefinition().getAspectConfiguration() + .isTracingEnabled() ? Constants.ENABLED : Constants.DISABLED; + endpointObject.put(TRACING, tracingState); + } else { + endpointObject.put(TRACING, Constants.DISABLED); + } return endpointObject; }