Java tutorial
/* * Copyright 2016 Brigham Young University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package edu.byu.wso2.apim.extensions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.synapse.ManagedLifecycle; import org.apache.synapse.MessageContext; import org.apache.synapse.SynapseLog; import org.apache.synapse.core.SynapseEnvironment; import org.apache.synapse.mediators.AbstractMediator; import java.util.Iterator; import java.util.Set; public class ContextPropertyDump extends AbstractMediator implements ManagedLifecycle { private static Log log = LogFactory.getLog(ContextPropertyDump.class); public void init(SynapseEnvironment synapseEnvironment) { if (log.isInfoEnabled()) { log.info("Initializing ContextPropertyDump Mediator"); } } public boolean mediate(MessageContext synapseContext) { SynapseLog synLog = getLog(synapseContext); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Start : ContextPropertyDump mediator"); if (synLog.isTraceTraceEnabled()) { synLog.traceTrace("Message : " + synapseContext.getEnvelope()); } } Set<String> propertyKeys = synapseContext.getPropertyKeySet(); //switch to foreach for (Iterator keys = propertyKeys.iterator(); keys.hasNext();) { String key = (String) keys.next(); Object value = synapseContext.getProperty(key); if (value != null) { synLog.traceOrDebug(key + " : " + value); } else { synLog.traceOrDebug(key + " : null"); } } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("End : ContextPropertyDump mediator"); } return true; } public void destroy() { if (log.isInfoEnabled()) { log.info("Destroying ContextPropertyDump Mediator"); } } }