Author: sebb
Date: Wed Nov 30 15:27:23 2005
New Revision: 350076

URL: http://svn.apache.org/viewcvs?rev=350076&view=rev
Log:
Fix up some strings; close PrintWriter stream

Modified:
    
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java

Modified: 
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
URL: 
http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java?rev=350076&r1=350075&r2=350076&view=diff
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
 Wed Nov 30 15:27:23 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,12 +34,15 @@
  */
 
 public class PostWriter {
-       protected final static String BOUNDARY = 
"---------------------------7d159c1302d0y0";
+    
+       private static final String DASH_DASH = "--";  // $NON-NLS-1$
+
+    protected final static String BOUNDARY = 
"---------------------------7d159c1302d0y0"; // $NON-NLS-1$
 
        private final static byte[] CRLF = { 0x0d, 0x0A };
 
        // protected static int fudge = -20;
-       protected static final String encoding = "iso-8859-1";
+       protected static final String encoding = "iso-8859-1"; // $NON-NLS-1$
 
        /**
         * Send POST data from Entry to the open connection.
@@ -51,16 +54,16 @@
                        OutputStream out = connection.getOutputStream();
                        // new FileOutputStream("c:\\data\\experiment.txt");
                        // new ByteArrayOutputStream();
-                       writeln(out, "--" + BOUNDARY);
+                       writeln(out, DASH_DASH + BOUNDARY);
                        PropertyIterator args = 
sampler.getArguments().iterator();
                        while (args.hasNext()) {
                                Argument arg = (Argument) 
args.next().getObjectValue();
                                writeFormMultipartStyle(out, arg.getName(), 
arg.getValue());
-                               writeln(out, "--" + BOUNDARY);
+                               writeln(out, DASH_DASH + BOUNDARY);
                        }
                        writeFileToURL(out, filename, sampler.getFileField(), 
getFileStream(filename), sampler.getMimetype());
 
-                       writeln(out, "--" + BOUNDARY + "--");
+                       writeln(out, DASH_DASH + BOUNDARY + DASH_DASH);
                        out.flush();
                        out.close();
                }
@@ -71,16 +74,18 @@
                        PrintWriter out = new 
PrintWriter(connection.getOutputStream());
                        out.print(postData);
                        out.flush();
+            out.close();
                }
        }
 
        public void setHeaders(URLConnection connection, HTTPSampler sampler) 
throws IOException {
-               ((HttpURLConnection) connection).setRequestMethod("POST");
+               ((HttpURLConnection) 
connection).setRequestMethod(HTTPSamplerBase.POST);
 
                // If filename was specified then send the post using multipart 
syntax
                String filename = sampler.getFilename();
                if ((filename != null) && (filename.trim().length() > 0)) {
-                       connection.setRequestProperty("Content-Type", 
"multipart/form-data; boundary=" + BOUNDARY);
+                       
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_TYPE, 
+                    "multipart/form-data; boundary=" + BOUNDARY); // 
$NON-NLS-1$
                        connection.setDoOutput(true);
                        connection.setDoInput(true);
                }
@@ -88,8 +93,8 @@
                // No filename specified, so send the post using normal syntax
                else {
                        String postData = sampler.getQueryString();
-                       connection.setRequestProperty("Content-Length", "" + 
postData.length());
-                       connection.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");
+                       
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_LENGTH, 
Integer.toString(postData.length()));
+                       
connection.setRequestProperty(HTTPSamplerBase.HEADER_CONTENT_TYPE, 
"application/x-www-form-urlencoded"); // $NON-NLS-1$
                        connection.setDoOutput(true);
                }
        }
@@ -118,9 +123,9 @@
         */
        private void writeFileToURL(OutputStream out, String filename, String 
fieldname, InputStream in, String mimetype)
                        throws IOException {
-               writeln(out, "Content-Disposition: form-data; name=\"" + 
encode(fieldname) + "\"; filename=\""
-                               + encode(filename) + "\"");
-               writeln(out, "Content-Type: " + mimetype);
+               writeln(out, "Content-Disposition: form-data; name=\"" + 
encode(fieldname) + "\"; filename=\"" // $NON-NLS-1$ // $NON-NLS-2$
+                               + encode(filename) + "\""); // $NON-NLS-1$
+               writeln(out, "Content-Type: " + mimetype); // $NON-NLS-1$
                out.write(CRLF);
 
                byte[] buf = new byte[1024];
@@ -140,17 +145,17 @@
         * Writes form data in multipart format.
         */
        private void writeFormMultipartStyle(OutputStream out, String name, 
String value) throws IOException {
-               writeln(out, "Content-Disposition: form-data; name=\"" + name + 
"\"");
+               writeln(out, "Content-Disposition: form-data; name=\"" + name + 
"\""); // $NON-NLS-1$ // $NON-NLS-2$
                out.write(CRLF);
                writeln(out, value);
        }
 
        private String encode(String value) {
-               StringBuffer newValue = new StringBuffer();
+               StringBuffer newValue = new StringBuffer(value.length());
                char[] chars = value.toCharArray();
                for (int i = 0; i < chars.length; i++) {
-                       if (chars[i] == '\\') {
-                               newValue.append("\\\\");
+                       if (chars[i] == '\\') { // $NON-NLS-1$
+                               newValue.append("\\\\"); // $NON-NLS-1$
                        } else {
                                newValue.append(chars[i]);
                        }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to