1 18 19 package org.apache.jmeter.protocol.http.config; 20 21 import java.io.Serializable ; 22 23 import org.apache.jmeter.config.Arguments; 24 import org.apache.jmeter.protocol.http.util.HTTPArgument; 25 import org.apache.jorphan.util.JOrphanUtils; 26 27 31 public class MultipartUrlConfig implements Serializable 32 { 33 34 public static final String MULTIPART_FORM = "multipart/form-data"; 35 private String boundary, filename, fileField, mimetype; 36 private Arguments args; 37 38 public MultipartUrlConfig() 39 { 40 args = new Arguments(); 41 } 42 43 public MultipartUrlConfig(String boundary) 44 { 45 this(); 46 this.boundary = boundary; 47 } 48 49 public void setBoundary(String boundary) 50 { 51 this.boundary = boundary; 52 } 53 54 public String getBoundary() 55 { 56 return boundary; 57 } 58 59 public void setFilename(String filename) 60 { 61 this.filename = filename; 62 } 63 64 public String getFilename() 65 { 66 return filename; 67 } 68 69 public Arguments getArguments() 70 { 71 return args; 72 } 73 74 public void setFileFieldName(String name) 75 { 76 this.fileField = name; 77 } 78 79 public String getFileFieldName() 80 { 81 return fileField; 82 } 83 84 public void setMimeType(String type) 85 { 86 mimetype = type; 87 } 88 89 public String getMimeType() 90 { 91 return mimetype; 92 } 93 94 public void addArgument(String name, String value) 95 { 96 Arguments args = this.getArguments(); 97 args.addArgument(new HTTPArgument(name, value)); 98 } 99 100 public void addArgument(String name, String value, String metadata) 101 { 102 Arguments args = this.getArguments(); 103 args.addArgument(new HTTPArgument(name, value, metadata)); 104 } 105 106 public void addEncodedArgument(String name, String value) 107 { 108 Arguments args = getArguments(); 109 HTTPArgument arg = new HTTPArgument(name, value, true); 110 if (arg.getName().equals(arg.getEncodedName()) 111 && arg.getValue().equals(arg.getEncodedValue())) 112 { 113 arg.setAlwaysEncoded(false); 114 } 115 args.addArgument(arg); 116 } 117 118 123 public void parseArguments(String queryString) 124 { 125 String [] parts = JOrphanUtils.split(queryString, "--" + getBoundary()); 126 for (int i = 0; i < parts.length; i++) 127 { 128 if (parts[i].indexOf("filename=") > -1) 129 { 130 int index = parts[i].indexOf("name=\"") + 6; 131 String name = 132 parts[i].substring(index, parts[i].indexOf("\"", index)); 133 index = parts[i].indexOf("filename=\"") + 10; 134 String filename = 135 parts[i].substring(index, parts[i].indexOf("\"", index)); 136 index = parts[i].indexOf("\n", index); 137 index = parts[i].indexOf(":", index) + 1; 138 String mimetype = 139 parts[i] 140 .substring(index, parts[i].indexOf("\n", index)) 141 .trim(); 142 this.setFileFieldName(name); 143 this.setFilename(filename); 144 this.setMimeType(mimetype); 145 } 146 else if (parts[i].indexOf("name=") > -1) 147 { 148 int index = parts[i].indexOf("name=\"") + 6; 149 String name = 150 parts[i].substring(index, parts[i].indexOf("\"", index)); 151 index = parts[i].indexOf("\n", index) + 2; 152 String value = parts[i].substring(index).trim(); 153 this.addEncodedArgument(name, value); 154 } 155 } 156 } 157 } 158
| Popular Tags
|