2017-05-28 52 views
1

如何在WSO2自定義中介程序中獲取HTTP_SC?在WSO2自定義處理程序中以語法方式獲取HTTP_SC

我嘗試下面的代碼:

@Override 
public boolean mediate(MessageContext context) 
{ 
    Log log = LogFactory.getLog(InfaAccessLogMediator.class); 

    Map<String,Object> axis2Properties = ((Axis2MessageContext)context).getAxis2MessageContext().getProperties(); 

    for (String prop : axis2Properties.keySet()) { 
     log.info(String.format("AXIS2 Property: %s", prop)); 
    } 

    return true; 
} 

下面是序列XML:

<sequence name="WSO2AM--Ext--Out" xmlns="http://ws.apache.org/ns/synapse"> 
<log level="custom"> 
    <property name="TRY_LOG_IT" expression="get-property('axis2','HTTP_SC')" /> 
</log> 
<class name="com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator"/> 

</sequence> 

以下是結果的日誌文件

INFO {org.apache.synapse.mediators.builtin.LogMediator} - TRY_LOG_IT = 200 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: addressing.validateAction 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: local_throttle_map 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: tomcatGenericWebappsDeplyer 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: servlet.context.parameters.list 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: throttle_info 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: carbon.webapps.holderlist 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: mediation.event.broker 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: CARBON_TASK_MANAGER 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: WORK_DIR 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: CARBON_TASK_SCHEDULER 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: CARBON_TASK_REPOSITORY 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: MediationStatisticsStore 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: last.accessed.time 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: RESPONSE_WRITTEN 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: CONFIGURATION_MANAGER 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: rampartOutPolicy 
INFO {com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator} - AXIS2 Property: rampartInPolicy 

正如你所看到的,日誌調解器從axis2上下文(來自日誌的第一行)記錄了HTTP_SC,但它沒有出現在m我的調解員內有一些屬性。

我找到了一種解決方法,通過使用屬性中介將MY_HTTP_SC設置爲axis2的值:HTTP_SC,並在我的介體中使用MY_HTTP_SC,但不知道爲什麼當我直接嘗試訪問HTTP_SC時不起作用。

<property name="MY_HTTP_SC" action="set" expression="get-property('axis2','HTTP_SC')" /> 
<class name="com.informatica.apimanager.wso2_plugins.InfaAccessLogMediator"/> 

回答

0

HTTP_SC位於axis2消息上下文中。所以你需要像下面這樣訪問Axis2消息上下文:

Map<String,Object> axis2Properties = ((Axis2MessageContext)context).getAxis2MessageContext().getProperties(); 
+0

這就是我所做的,HTTP_SC不包括在那裏。我將使用其他代碼和信息更新我的原始帖子。 –

+0

您可以按如下方式訪問HTTP_SC的值:'((Axis2MessageContext)context).getAxis2MessageContext()。getProperty(「HTTP_SC」)' – Chandana

相關問題