2017-02-24 7 views
1

Synapseハンドラでカスタムロガーを実装しようとしていますが、APIとサービスを区別できますが、どのようにしてシナプスハンドラコードからAPI名を取得できますか?すべてのAPIのサービス名は__SynapseServiceです。SynapseハンドラからAPI名を取得する

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(); 
    } 

答えて

0

これを試してください。

String apiName = (String) messageContext.getProperty("SYNAPSE_REST_API"); 
+0

これは常にnullです。 – iozeren

+0

それは変です。これは、WSO2製品がAPI名を読み取る方法です。例えば。 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/ハンドラ/セキュリティ/ APIAuthenticationHandler.java#L294 – Bee

+0

ESB 5.0のコードベースが同じかどうかはわかりません。私はこのコードがAPIマネージャーに関係していると思います。 – iozeren

関連する問題