Accessing Package Key EAVs in the Custom Processor
This version of the SDK includes an example custom processor that can access package EAVs (Extended Attribute Values).
For example, this sample processor looks for "user_defined_key" EAVs for a package key:
package com.mashery.processor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.mashery.trafficmanager.event.listener.TrafficEventListener; import com.mashery.trafficmanager.event.listener.Authenticator; import com.mashery.trafficmanager.event.model.TrafficEvent; import com.mashery.trafficmanager.event.processor.model.PostProcessEvent; import com.mashery.trafficmanager.event.processor.model.PreProcessEvent; import com.mashery.trafficmanager.model.core.ExtendedAttributes; import com.mashery.trafficmanager.processor.ProcessorBean; import com.mashery.trafficmanager.processor.ProcessorException; @ProcessorBean(enabled = true, name = "PrePostProcessing", immediate = true) public class PrePostProcessing implements TrafficEventListener,Authenticator { private final Logger log = LoggerFactory.getLogger(PrePostProcessing.class); @Override public void handleEvent(TrafficEvent event) { try { if (event instanceof PreProcessEvent) { preProcess((PreProcessEvent) event); } else if (event instanceof PostProcessEvent) { postProcess((PostProcessEvent) event); } else if (event instanceof AuthenticationEvent) { authenticate((AuthenticationEvent) event) } } catch (ProcessorException e) { log.error("Exception occurred when handling processor event"); } } //In the below snippet we are extracting the package key and checking its value. private void preProcess(PreProcessEvent event) throws ProcessorException { ExtendedAttributes attrs = (event).getKey().getExtendedAttributes(); String strAllowed = attrs.getValue("user_defined_key"); } private void postProcess(PostProcessEvent event) throws ProcessorException { ExtendedAttributes attrs = (event).getKey().getExtendedAttributes(); String strAllowed = attrs.getValue("user_defined_key"); } private void authenticate(AuthenticationEvent event) throws ProcessorException { ExtendedAttributes attrs = (event).getKey().getExtendedAttributes(); String strAllowed = attrs.getValue("user_defined_key"); } }
Copyright © Cloud Software Group, Inc. All rights reserved.