Source Code Cross Referenced for MultipartUrlConfig.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » http » config » 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.config 
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.config;
020:
021:        import java.io.Serializable;
022:
023:        import org.apache.jmeter.config.Arguments;
024:        import org.apache.jmeter.protocol.http.util.HTTPArgument;
025:        import org.apache.jmeter.util.JMeterUtils;
026:        import org.apache.jorphan.util.JOrphanUtils;
027:        import org.apache.oro.text.regex.Pattern;
028:        import org.apache.oro.text.regex.Perl5Compiler;
029:        import org.apache.oro.text.regex.Perl5Matcher;
030:
031:        /**
032:         * @author Michael Stover
033:         */
034:        public class MultipartUrlConfig implements  Serializable {
035:
036:            private String boundary, filename, fileField, mimetype;
037:
038:            private Arguments args;
039:
040:            public MultipartUrlConfig() {
041:                args = new Arguments();
042:            }
043:
044:            public MultipartUrlConfig(String boundary) {
045:                this ();
046:                this .boundary = boundary;
047:            }
048:
049:            public void setBoundary(String boundary) {
050:                this .boundary = boundary;
051:            }
052:
053:            public String getBoundary() {
054:                return boundary;
055:            }
056:
057:            public void setFilename(String filename) {
058:                this .filename = filename;
059:            }
060:
061:            public String getFilename() {
062:                return filename;
063:            }
064:
065:            public Arguments getArguments() {
066:                return args;
067:            }
068:
069:            public void setFileFieldName(String name) {
070:                this .fileField = name;
071:            }
072:
073:            public String getFileFieldName() {
074:                return fileField;
075:            }
076:
077:            public void setMimeType(String type) {
078:                mimetype = type;
079:            }
080:
081:            public String getMimeType() {
082:                return mimetype;
083:            }
084:
085:            public void addArgument(String name, String value) {
086:                Arguments myArgs = this .getArguments();
087:                myArgs.addArgument(new HTTPArgument(name, value));
088:            }
089:
090:            public void addArgument(String name, String value, String metadata) {
091:                Arguments myArgs = this .getArguments();
092:                myArgs.addArgument(new HTTPArgument(name, value, metadata));
093:            }
094:
095:            // NOT USED	
096:            //    /**
097:            //     * @deprecated values in a multipart/form-data are not urlencoded,
098:            //     * so it does not make sense to add a value as a encoded value
099:            //     */
100:            //	public void addEncodedArgument(String name, String value) {
101:            //		Arguments myArgs = getArguments();
102:            //		HTTPArgument arg = new HTTPArgument(name, value, true);
103:            //		if (arg.getName().equals(arg.getEncodedName()) && arg.getValue().equals(arg.getEncodedValue())) {
104:            //			arg.setAlwaysEncoded(false);
105:            //		}
106:            //		myArgs.addArgument(arg);
107:            //	}
108:
109:            /**
110:             * Add a value that is not URL encoded, and make sure it
111:             * appears in the GUI that it will not be encoded when
112:             * the request is sent.
113:             * 
114:             * @param name
115:             * @param value
116:             */
117:            private void addNonEncodedArgument(String name, String value) {
118:                Arguments myArgs = getArguments();
119:                // The value is not encoded
120:                HTTPArgument arg = new HTTPArgument(name, value, false);
121:                // Let the GUI show that it will not be encoded
122:                arg.setAlwaysEncoded(false);
123:                myArgs.addArgument(arg);
124:            }
125:
126:            /**
127:             * This method allows a proxy server to send over the raw text from a
128:             * browser's output stream to be parsed and stored correctly into the
129:             * UrlConfig object.
130:             */
131:            public void parseArguments(String queryString) {
132:                String[] parts = JOrphanUtils.split(queryString, "--"
133:                        + getBoundary());
134:                for (int i = 0; i < parts.length; i++) {
135:                    String contentDisposition = getHeaderValue(
136:                            "Content-disposition", parts[i]);
137:                    String contentType = getHeaderValue("Content-type",
138:                            parts[i]);
139:                    // Check if it is form data
140:                    if (contentDisposition != null
141:                            && contentDisposition.indexOf("form-data") > -1) {
142:                        // Get the form field name
143:                        int index = contentDisposition.indexOf("name=\"") + 6;
144:                        String name = contentDisposition.substring(index,
145:                                contentDisposition.indexOf("\"", index));
146:
147:                        // Check if it is a file being uploaded
148:                        if (contentDisposition.indexOf("filename=") > -1) {
149:                            // Get the filename
150:                            index = contentDisposition.indexOf("filename=\"") + 10;
151:                            String fn = contentDisposition.substring(index,
152:                                    contentDisposition.indexOf("\"", index));
153:                            if (fn != null && fn.length() > 0) {
154:                                // Set the values retrieves for the file upload
155:                                this .setFileFieldName(name);
156:                                this .setFilename(fn);
157:                                this .setMimeType(contentType);
158:                            }
159:                        } else {
160:                            // Find the first empty line of the multipart, it signals end of headers for multipart
161:                            int indexEmptyLfCrLfLinePos = parts[i]
162:                                    .indexOf("\n\r\n");
163:                            int indexEmptyLfLfLinePos = parts[i]
164:                                    .indexOf("\n\n");
165:                            String value = null;
166:                            if (indexEmptyLfCrLfLinePos > -1) {
167:                                value = parts[i].substring(
168:                                        indexEmptyLfCrLfLinePos).trim();
169:                            } else if (indexEmptyLfLfLinePos > -1) {
170:                                value = parts[i].substring(
171:                                        indexEmptyLfLfLinePos).trim();
172:                            }
173:                            this .addNonEncodedArgument(name, value);
174:                        }
175:                    }
176:                }
177:            }
178:
179:            private String getHeaderValue(String headerName, String multiPart) {
180:                String regularExpression = headerName + "\\s*:\\s*(.*)$";
181:                Perl5Matcher localMatcher = JMeterUtils.getMatcher();
182:                Pattern pattern = JMeterUtils.getPattern(regularExpression,
183:                        Perl5Compiler.READ_ONLY_MASK
184:                                | Perl5Compiler.CASE_INSENSITIVE_MASK
185:                                | Perl5Compiler.MULTILINE_MASK);
186:                if (localMatcher.contains(multiPart, pattern)) {
187:                    return localMatcher.getMatch().group(1).trim();
188:                } else {
189:                    return null;
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.