Java Code Examples for org.apache.synapse.MessageContext#getPropertyKeySet()

The following examples show how to use org.apache.synapse.MessageContext#getPropertyKeySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> getCustomAnalyticsProperties(MessageContext messageContext,
        String propertyPathKey) {
    Set<String> keys = messageContext.getPropertyKeySet();
    String properties = (String) messageContext.getProperty(propertyPathKey);
    if (StringUtils.isBlank(properties)) {
        return Collections.emptyMap();
    }
    Map<String, String> propertyMap = new HashMap<>();
    String[] propertyKeys = properties.split(APIMgtGatewayConstants.CUSTOM_ANALYTICS_PROPERTY_SEPARATOR);
    for (String propertyKey : propertyKeys) {
        if (keys.contains(propertyKey.trim())) {
            propertyMap.put(propertyKey, (String) messageContext.getProperty(propertyKey.trim()));
        }
    }
    return propertyMap;
}
 
Example 2
Source File: TenantAwareLoadBalanceEndpoint.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
@Override
public void onFault(MessageContext synCtx) {
    if (log.isWarnEnabled()) {
        log.warn(String.format("A fault detected in message sent to: %s ", (to != null) ? to.getAddress() : "address not found"));
    }

    // Decrement in-flight request count
    decrementInFlightRequestCount(synCtx);

    if (isFailover()) {
        if (log.isDebugEnabled()) {
            log.debug("Fail-over enabled, trying to send the message to the next available member");
        }

        // Cleanup endpoint if exists
        if (currentEp != null) {
            currentEp.destroy();
        }
        if (currentMember == null) {
            if (log.isErrorEnabled()) {
                log.error("Current member is null, could not fail-over");
            }
            return;
        }

        // Add current member to faulty members
        faultyMemberIds.put(currentMember.getProperties().getProperty(LoadBalancerConstants.MEMBER_ID), true);

        currentMember = findNextMember(synCtx);
        if (currentMember == null) {
            String msg = String.format("No members available to serve the request %s", (to != null) ? to.getAddress() : "address not found");
            if (log.isErrorEnabled()) {
                log.error(msg);
            }
            throwSynapseException(synCtx, 404, msg);
        }
        if (faultyMemberIds.containsKey(currentMember.getProperties().getProperty(LoadBalancerConstants.MEMBER_ID))) {
            // This member has been identified as faulty previously. It implies that
            // this request could not be served by any of the members in the cluster.
            throwSynapseException(synCtx, 404, String.format("Requested resource could not be found"));
        }

        synCtx.setTo(to);
        if (isSessionAffinityBasedLB()) {
            //We are sending the this message on a new session,
            // hence we need to remove previous session information
            Set<?> pros = synCtx.getPropertyKeySet();
            if (pros != null) {
                pros.remove(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
            }
        }
        sendToApplicationMember(synCtx, currentMember, this, true);
    }
}