在WSO2自定义处理程序中以语法方式获取HTTP_SC

时间:2017-05-28 17:38:39

标签: wso2 wso2esb

如何在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,但它没有出现在我的介体内的属性映射中。

我找到的解决方法是使用属性介体将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"/>

1 个答案:

答案 0 :(得分:0)

HTTP_SC位于axis2消息上下文中。因此,您需要访问Axis2消息上下文,如下所示:

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