Source Code Cross Referenced for UserParameterModifier.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » http » modifier » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.protocol.http.modifier 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.protocol.http.modifier;
020:
021:        import java.io.Serializable;
022:        import java.util.LinkedList;
023:        import java.util.List;
024:        import java.util.Map;
025:
026:        import org.apache.jmeter.config.Argument;
027:        import org.apache.jmeter.config.ConfigTestElement;
028:        import org.apache.jmeter.engine.event.LoopIterationEvent;
029:        import org.apache.jmeter.processor.PreProcessor;
030:        import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
031:        import org.apache.jmeter.samplers.Sampler;
032:        import org.apache.jmeter.testelement.TestListener;
033:        import org.apache.jmeter.testelement.property.PropertyIterator;
034:        import org.apache.jorphan.logging.LoggingManager;
035:        import org.apache.log.Logger;
036:
037:        /**
038:         * This modifier will replace any http sampler's url parameter values with
039:         * parameter values defined in a XML file for each simulated user.
040:         * <P>
041:         * For example if userid and password are defined in the XML parameter file for
042:         * each user (ie thread), then simulated multiple user activity can occur.
043:         * 
044:         * @author Mark Walsh
045:         * @version $Revision: 493789 $
046:         */
047:        public class UserParameterModifier extends ConfigTestElement implements 
048:                PreProcessor, Serializable, TestListener {
049:            transient private static Logger log = LoggingManager
050:                    .getLoggerForClass();
051:
052:            private static final String XMLURI = "UserParameterModifier.xmluri";
053:
054:            private UserSequence allAvailableUsers;
055:
056:            /**
057:             * Default constructor.
058:             */
059:            public UserParameterModifier() {
060:            } // end constructor
061:
062:            /**
063:             * Runs before the start of every test. Reload the Sequencer with the latest
064:             * parameter data for each user
065:             */
066:            public void testStarted() {
067:                // try to populate allUsers, if fail, leave as any empty set
068:                List allUsers = new LinkedList();
069:                try {
070:                    UserParameterXMLParser readXMLParameters = new UserParameterXMLParser();
071:                    allUsers = readXMLParameters.getXMLParameters(getXmlUri());
072:                } catch (Exception e) {
073:                    // do nothing, now object allUsers contains an empty set
074:                    log.error("Unable to read parameters from xml file "
075:                            + getXmlUri());
076:                    log.error(
077:                            "No unique values for http requests will be substituted for "
078:                                    + "each thread", e);
079:                }
080:                allAvailableUsers = new UserSequence(allUsers);
081:            }
082:
083:            public void testEnded() {
084:            }
085:
086:            public void testStarted(String host) {
087:                testStarted();
088:            }
089:
090:            public void testEnded(String host) {
091:            }
092:
093:            /*
094:             * ------------------------------------------------------------------------
095:             * Methods implemented from interface org.apache.jmeter.config.Modifier
096:             * ------------------------------------------------------------------------
097:             */
098:
099:            /**
100:             * Modifies an entry object to replace the value of any url parameter that
101:             * matches a parameter name in the XML file.
102:             * 
103:             */
104:            public void process() {
105:                Sampler entry = getThreadContext().getCurrentSampler();
106:                if (!(entry instanceof  HTTPSamplerBase)) {
107:                    return;
108:                }
109:                HTTPSamplerBase config = (HTTPSamplerBase) entry;
110:                Map currentUser = allAvailableUsers.getNextUserMods();
111:                PropertyIterator iter = config.getArguments().iterator();
112:                while (iter.hasNext()) {
113:                    Argument arg = (Argument) iter.next().getObjectValue();
114:                    // if parameter name exists in http request
115:                    // then change its value
116:                    // (Note: each jmeter thread (ie user) gets to have unique values)
117:                    if (currentUser.containsKey(arg.getName())) {
118:                        arg.setValue((String) currentUser.get(arg.getName()));
119:                    }
120:                }
121:            }
122:
123:            /*
124:             * ------------------------------------------------------------------------
125:             * Methods (used by UserParameterModifierGui to get/set the name of XML
126:             * parameter file)
127:             * ------------------------------------------------------------------------
128:             */
129:
130:            /**
131:             * Return the current XML file name to be read to obtain the parameter data
132:             * for all users
133:             * 
134:             * @return the name of the XML file containing parameter data for each user
135:             */
136:            public String getXmlUri() {
137:                return this .getPropertyAsString(XMLURI);
138:            }
139:
140:            /**
141:             * From the GUI screen, set file name of XML to read
142:             * 
143:             * @param xmlURI
144:             *            the name of the XML file containing the HTTP name value pair
145:             *            parameters per user
146:             */
147:            public void setXmlUri(String xmlURI) {
148:                setProperty(XMLURI, xmlURI);
149:            }
150:
151:            /*
152:             * (non-Javadoc)
153:             * 
154:             * @see TestListener#testIterationStart(LoopIterationEvent)
155:             */
156:            public void testIterationStart(LoopIterationEvent event) {
157:            }
158:
159:            /*
160:             * (non-Javadoc)
161:             * 
162:             * @see java.lang.Object#clone()
163:             */
164:            public Object clone() {
165:                UserParameterModifier clone = (UserParameterModifier) super
166:                        .clone();
167:                clone.allAvailableUsers = allAvailableUsers;
168:                return clone;
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.