1

I am trying to implement a custom logger with Synapse handler, I can differentiate API and service but how can I get the API name from synapse handler code? Service name is __SynapseService for all APIs.

    public static boolean isProxyService(MessageContext messageContext,
            AxisService axisService) {

        if (axisService != null) {
            Parameter val = axisService.getParameter("serviceType");
            if (val != null && val.getValue().toString().equalsIgnoreCase("Proxy")) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Parameter Value Service Type: "
                            + val.getValue().toString());
                }
                return true;
            }
        }
        return false;
    }
    public static boolean isAPI(MessageContext messageContext,
            AxisService axisService) {

        if(!isProxyService(messageContext, axisService) && axisService.getAxisServiceGroup().getServiceGroupName().equals(SynapseConstants.SYNAPSE_SERVICE_NAME)){
            return true;
        }
        return false;
    }
    public static String getServiceName(MessageContext messageContext,  AxisService axisService) {
        org.apache.axis2.context.MessageContext msgContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext();       

        return msgContext.getServiceContext().getName();
    }
Community
  • 1
  • 1
iozeren
  • 11
  • 3

1 Answers1

0

Try this.

String apiName = (String) messageContext.getProperty("SYNAPSE_REST_API");
Bee
  • 12,251
  • 11
  • 46
  • 73
  • This is always null. – iozeren Feb 27 '17 at 07:20
  • That's strange. This is how WSO2 products read API name. eg. https://github.com/wso2/carbon-apimgt/blob/v6.0.4/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/APIAuthenticationHandler.java#L294 – Bee Feb 27 '17 at 10:25
  • I don't know if the ESB 5.0 has the same code base. I think this code is related to API manager. – iozeren Feb 27 '17 at 13:55
  • Both are synapse handlers. – Bee Feb 27 '17 at 17:02