简体   繁体   中英

Get HTTP_SC grammatically in WSO2 custom handler

How can I get HTTP_SC inside WSO2 custom mediator?

I was trying the following code:

@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;
}

Below is the sequence 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>

Following is the result in the log file

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

As you can see, the log mediator logged the HTTP_SC from the axis2 context (first line from the log) but it did not appear in the map of properties inside my mediator.

A workaround that I found would by to use property mediator to set MY_HTTP_SC to the value of axis2:HTTP_SC and in my mediator use MY_HTTP_SC, but not sure why this would not work when I directly attempt to access HTTP_SC.

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

HTTP_SC is in axis2 message context. So you need to access the Axis2 Message Context like below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM