alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

// $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/modifier/ParamModifier.java,v 1.13 2004/02/22 19:23:15 sebb Exp $
/*
 * Copyright 2002-2004 The Apache Software Foundation.
 *
 * 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 org.apache.jmeter.protocol.http.modifier;

import java.io.Serializable;

import org.apache.jmeter.config.Argument;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.processor.PreProcessor;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.testelement.property.PropertyIterator;
import org.apache.jmeter.testelement.property.TestElementProperty;

/**
 * This modifier will replace any single http sampler's url parameter value
 * with a value from a given range - thereby "masking" the value set in the
 * http sampler. The parameter names must match exactly, and the parameter
 * value must be preset to "*" to diferentiate between duplicate parameter
 * names.
 * 

* For example, if you set up the modifier with a lower bound of 1, an upper * bound of 10, and an increment of 2, and run the loop 12 times, the parameter * will have the following values (one per loop): 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, * 1, 3 *

* The {@link ParamMask} object contains most of the logic for stepping through * this loop. You can make large modifications to this modifier's behaviour by * changing one or two method implementations there. * * @author David La France * @see ParamMask * @version $Revision: 1.13 $ updated on $Date: 2004/02/22 19:23:15 $ */ public class ParamModifier extends AbstractTestElement implements TestListener, PreProcessor, Serializable { /* * ------------------------------------------------------------------------ * Fields * ------------------------------------------------------------------------ */ /** * The key used to find the ParamMask object in the HashMap. */ private final static String MASK = "ParamModifier.mask"; /* * ------------------------------------------------------------------------ * Constructors * ------------------------------------------------------------------------ */ /** * Default constructor. */ public ParamModifier() { setProperty(new TestElementProperty(MASK, new ParamMask())); } public ParamMask getMask() { return (ParamMask) getProperty(MASK).getObjectValue(); } public void testStarted() { getMask().resetValue(); } public void testStarted(String host) { getMask().resetValue(); } public void testEnded() { } public void testEnded(String host) { } /* * ------------------------------------------------------------------------ * Methods implemented from interface org.apache.jmeter.config.Modifier * ------------------------------------------------------------------------ */ /** * Modifies an entry object to replace the value of any url parameter that * matches a defined mask. * */ public void process() { Sampler sam = getThreadContext().getCurrentSampler(); HTTPSampler sampler = null; if (!(sam instanceof HTTPSampler)) { return; } else { sampler = (HTTPSampler) sam; } boolean modified = false; PropertyIterator iter = sampler.getArguments().iterator(); while (iter.hasNext()) { Argument arg = (Argument) iter.next().getObjectValue(); modified = modifyArgument(arg); if (modified) { break; } } } /* * ------------------------------------------------------------------------ * Methods * ------------------------------------------------------------------------ */ /** * Helper method for {@link #modifyEntry} Replaces a parameter's value if * the parameter name matches the mask name and the value is a '*'. * * @param arg an {@link Argument} representing a http parameter * @return trueif the value was replaced */ private boolean modifyArgument(Argument arg) { // if a mask for this argument exists if (arg.getName().equals(getMask().getFieldName())) { // values to be masked must be set in the WebApp to "*" if ("*".equals(arg.getValue())) { arg.setValue(getMask().getNextValue()); return true; } } return false; } /** * @see TestListener#testIterationStart(LoopIterationEvent) */ public void testIterationStart(LoopIterationEvent event) { } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.