Source Code Cross Referenced for HTTPArgument.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » http » util » 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.util 
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.util;
020:
021:        import java.io.Serializable;
022:        import java.io.UnsupportedEncodingException;
023:        import java.net.URLDecoder;
024:        import java.util.LinkedList;
025:        import java.util.List;
026:
027:        import org.apache.jmeter.config.Argument;
028:        import org.apache.jmeter.config.Arguments;
029:        import org.apache.jmeter.testelement.property.BooleanProperty;
030:        import org.apache.jmeter.testelement.property.PropertyIterator;
031:        import org.apache.jorphan.logging.LoggingManager;
032:        import org.apache.log.Logger;
033:
034:        //For unit tests, @see TestHTTPArgument
035:
036:        /*
037:         * 
038:         * @version $Revision: 552959 $ $Date: 2007-07-03 20:39:51 +0100 (Tue, 03 Jul 2007) $
039:         */
040:        public class HTTPArgument extends Argument implements  Serializable {
041:            private static final Logger log = LoggingManager
042:                    .getLoggerForClass();
043:
044:            private static final String ALWAYS_ENCODE = "HTTPArgument.always_encode";
045:
046:            private static final String USE_EQUALS = "HTTPArgument.use_equals";
047:
048:            private static EncoderCache cache = new EncoderCache(1000);
049:
050:            /**
051:             * Constructor for the Argument object.
052:             */
053:            public HTTPArgument(String name, String value, String metadata) {
054:                this (name, value, false);
055:                this .setMetaData(metadata);
056:            }
057:
058:            public void setUseEquals(boolean ue) {
059:                if (ue) {
060:                    setMetaData("=");
061:                } else {
062:                    setMetaData("");
063:                }
064:                setProperty(new BooleanProperty(USE_EQUALS, ue));
065:            }
066:
067:            public boolean isUseEquals() {
068:                boolean eq = getPropertyAsBoolean(USE_EQUALS);
069:                if (getMetaData().equals("=")
070:                        || (getValue() != null && getValue().length() > 0)) {
071:                    setUseEquals(true);
072:                    return true;
073:                }
074:                return eq;
075:
076:            }
077:
078:            public void setAlwaysEncoded(boolean ae) {
079:                setProperty(new BooleanProperty(ALWAYS_ENCODE, ae));
080:            }
081:
082:            public boolean isAlwaysEncoded() {
083:                return getPropertyAsBoolean(ALWAYS_ENCODE);
084:            }
085:
086:            /**
087:             * Constructor for the Argument object.
088:             */
089:            public HTTPArgument(String name, String value) {
090:                this (name, value, false);
091:            }
092:
093:            public HTTPArgument(String name, String value,
094:                    boolean alreadyEncoded) {
095:                // We assume the argument value is encoded according to the HTTP spec, i.e. UTF-8
096:                this (name, value, alreadyEncoded,
097:                        EncoderCache.URL_ARGUMENT_ENCODING);
098:            }
099:
100:            /**
101:             * Construct a new HTTPArgument instance
102:             * 
103:             * @param name the name of the parameter
104:             * @param value the value of the parameter
105:             * @param alreadyEncoded true if the name and value is already encoded
106:             * @param contentEncoding the encoding used for the parameter value
107:             */
108:            public HTTPArgument(String name, String value,
109:                    boolean alreadyEncoded, String contentEncoding) {
110:                setAlwaysEncoded(true);
111:                if (alreadyEncoded) {
112:                    try {
113:                        // We assume the name is always encoded according to spec
114:                        name = URLDecoder.decode(name,
115:                                EncoderCache.URL_ARGUMENT_ENCODING);
116:                        // The value is encoded in the specified encoding
117:                        value = URLDecoder.decode(value, contentEncoding);
118:                    } catch (UnsupportedEncodingException e) {
119:                        log.error(contentEncoding + " encoding not supported!");
120:                        throw new Error(e.toString());
121:                    }
122:                }
123:                setName(name);
124:                setValue(value);
125:                setMetaData("=");
126:            }
127:
128:            public HTTPArgument(String name, String value, String metaData,
129:                    boolean alreadyEncoded) {
130:                // We assume the argument value is encoded according to the HTTP spec, i.e. UTF-8
131:                this (name, value, metaData, alreadyEncoded,
132:                        EncoderCache.URL_ARGUMENT_ENCODING);
133:            }
134:
135:            /**
136:             * Construct a new HTTPArgument instance
137:             * 
138:             * @param name the name of the parameter
139:             * @param value the value of the parameter
140:             * @param metaData the separator to use between name and value
141:             * @param alreadyEncoded true if the name and value is already encoded
142:             * @param contentEncoding the encoding used for the parameter value
143:             */
144:            public HTTPArgument(String name, String value, String metaData,
145:                    boolean alreadyEncoded, String contentEncoding) {
146:                this (name, value, alreadyEncoded, contentEncoding);
147:                setMetaData(metaData);
148:            }
149:
150:            public HTTPArgument(Argument arg) {
151:                this (arg.getName(), arg.getValue(), arg.getMetaData());
152:            }
153:
154:            /**
155:             * Constructor for the Argument object
156:             */
157:            public HTTPArgument() {
158:            }
159:
160:            /**
161:             * Sets the Name attribute of the Argument object.
162:             * 
163:             * @param newName
164:             *            the new Name value
165:             */
166:            public void setName(String newName) {
167:                if (newName == null || !newName.equals(getName())) {
168:                    super .setName(newName);
169:                }
170:            }
171:
172:            /**
173:             * Get the argument value encoded using UTF-8
174:             * 
175:             * @return the argument value encoded in UTF-8
176:             */
177:            public String getEncodedValue() {
178:                // Encode according to the HTTP spec, i.e. UTF-8
179:                try {
180:                    return getEncodedValue(EncoderCache.URL_ARGUMENT_ENCODING);
181:                } catch (UnsupportedEncodingException e) {
182:                    // This can't happen (how should utf8 not be supported!?!),
183:                    // so just throw an Error:
184:                    throw new Error("Should not happen: " + e.toString());
185:                }
186:            }
187:
188:            /**
189:             * Get the argument value encoded in the specified encoding
190:             * 
191:             * @param contentEncoding the encoding to use when encoding the argument value
192:             * @return the argument value encoded in the specified encoding
193:             * @throws UnsupportedEncodingException
194:             */
195:            public String getEncodedValue(String contentEncoding)
196:                    throws UnsupportedEncodingException {
197:                if (isAlwaysEncoded()) {
198:                    return cache.getEncoded(getValue(), contentEncoding);
199:                } else {
200:                    return getValue();
201:                }
202:            }
203:
204:            public String getEncodedName() {
205:                if (isAlwaysEncoded()) {
206:                    return cache.getEncoded(getName());
207:                } else {
208:                    return getName();
209:                }
210:
211:            }
212:
213:            public static void convertArgumentsToHTTP(Arguments args) {
214:                List newArguments = new LinkedList();
215:                PropertyIterator iter = args.getArguments().iterator();
216:                while (iter.hasNext()) {
217:                    Argument arg = (Argument) iter.next().getObjectValue();
218:                    if (!(arg instanceof  HTTPArgument)) {
219:                        newArguments.add(new HTTPArgument(arg));
220:                    } else {
221:                        newArguments.add(arg);
222:                    }
223:                }
224:                args.removeAllArguments();
225:                args.setArguments(newArguments);
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.