Source Code Cross Referenced for HTTPSampleResult.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » http » sampler » 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.sampler 
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.sampler;
020:
021:        import java.net.URL;
022:
023:        import org.apache.jmeter.protocol.http.util.HTTPConstants;
024:        import org.apache.jmeter.samplers.SampleResult;
025:
026:        /**
027:         * This is a specialisation of the SampleResult class for the HTTP protocol.
028:         * 
029:         * author <a href="mailto:jsalvata@apache.org">Jordi Salvat i Alabart</a>
030:         */
031:        public class HTTPSampleResult extends SampleResult {
032:
033:            private String cookies = ""; // never null
034:
035:            private String method;
036:
037:            private String redirectLocation;
038:
039:            private String queryString = ""; // never null
040:
041:            public HTTPSampleResult() {
042:                super ();
043:                setDataEncoding(DEFAULT_HTTP_ENCODING); // default if encoding not provided be the page
044:            }
045:
046:            public HTTPSampleResult(long elapsed) {
047:                super (elapsed, true);
048:            }
049:
050:            /**
051:             * Construct a 'parent' result for an already-existing result, essentially
052:             * cloning it
053:             * 
054:             * @param res
055:             *            existing sample result
056:             */
057:            public HTTPSampleResult(HTTPSampleResult res) {
058:                super (res);
059:                method = res.method;
060:                cookies = res.cookies;
061:                queryString = res.queryString;
062:                redirectLocation = res.redirectLocation;
063:            }
064:
065:            public void setHTTPMethod(String method) {
066:                this .method = method;
067:            }
068:
069:            public String getHTTPMethod() {
070:                return method;
071:            }
072:
073:            public void setRedirectLocation(String redirectLocation) {
074:                this .redirectLocation = redirectLocation;
075:            }
076:
077:            public String getRedirectLocation() {
078:                return redirectLocation;
079:            }
080:
081:            /**
082:             * Determine whether this result is a redirect.
083:             * 
084:             * @return true iif res is an HTTP redirect response
085:             */
086:            public boolean isRedirect() {
087:                final String[] REDIRECT_CODES = { "301", "302", "303" }; // NOT 304!
088:                String code = getResponseCode();
089:                for (int i = 0; i < REDIRECT_CODES.length; i++) {
090:                    if (REDIRECT_CODES[i].equals(code))
091:                        return true;
092:                }
093:                return false;
094:            }
095:
096:            /*
097:             * (non-Javadoc)
098:             * Overrides version in Sampler data to provide more details
099:             * 
100:             * @see org.apache.jmeter.samplers.SampleResult#getSamplerData()
101:             */
102:            public String getSamplerData() {
103:                StringBuffer sb = new StringBuffer();
104:                sb.append(method);
105:                URL u = super .getURL();
106:                if (u != null) {
107:                    sb.append(' ');
108:                    sb.append(u.toString());
109:                    sb.append("\n");
110:                    // Include request body if it is a post or put
111:                    if (HTTPConstants.POST.equals(method)
112:                            || HTTPConstants.PUT.equals(method)) {
113:                        sb.append("\nPOST data:\n");
114:                        sb.append(queryString);
115:                        sb.append("\n");
116:                    }
117:                    if (cookies.length() > 0) {
118:                        sb.append("\nCookie Data:\n");
119:                        sb.append(cookies);
120:                    } else {
121:                        sb.append("\n[no cookies]");
122:                    }
123:                    sb.append("\n");
124:                }
125:                return sb.toString();
126:            }
127:
128:            /**
129:             * @return cookies as a string
130:             */
131:            public String getCookies() {
132:                return cookies;
133:            }
134:
135:            /**
136:             * @param string
137:             *            representing the cookies
138:             */
139:            public void setCookies(String string) {
140:                if (string == null) {
141:                    cookies = "";// $NON-NLS-1$
142:                } else {
143:                    cookies = string;
144:                }
145:            }
146:
147:            /**
148:             * Fetch the query string
149:             * 
150:             * @return the query string
151:             */
152:            public String getQueryString() {
153:                return queryString;
154:            }
155:
156:            /**
157:             * Save the query string
158:             * 
159:             * @param string
160:             *            the query string
161:             */
162:            public void setQueryString(String string) {
163:                if (string == null) {
164:                    queryString = "";// $NON-NLS-1$
165:                } else {
166:                    queryString = string;
167:                }
168:            }
169:
170:            /**
171:             * Overrides the method from SampleResult - so the encoding can be extracted from
172:             * the Meta content-type if necessary.
173:             * 
174:             * Updates the dataEncoding field if the content-type is found.
175:             * 
176:             * @return the dataEncoding value as a String
177:             */
178:            public String getDataEncodingWithDefault() {
179:                if (getDataEncodingNoDefault() == null
180:                        && getContentType().startsWith("text/html")) { // $NON-NLS-1$
181:                    byte[] bytes = getResponseData();
182:                    // get the start of the file
183:                    String prefix = new String(bytes, 0, Math.min(bytes.length,
184:                            1000)).toLowerCase();
185:                    // Extract the content-type if present
186:                    final String METATAG = "<meta http-equiv=\"content-type\" content=\""; // $NON-NLS-1$
187:                    int tagstart = prefix.indexOf(METATAG);
188:                    if (tagstart != -1) {
189:                        tagstart += METATAG.length();
190:                        int tagend = prefix.indexOf("\"", tagstart); // $NON-NLS-1$
191:                        if (tagend != -1) {
192:                            final String ct = new String(bytes, tagstart,
193:                                    tagend - tagstart);
194:                            setEncodingAndType(ct);// Update the dataEncoding
195:                        }
196:                    }
197:                }
198:                return super.getDataEncodingWithDefault();
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.