W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2009

2006/unicorn/src/org/w3c/unicorn/request DirectRequestPOST.java,1.5,1.6

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 22 Sep 2009 12:37:59 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Mq4d5-0005IJ-HU@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/request
In directory hutz:/tmp/cvs-serv20335/src/org/w3c/unicorn/request

Modified Files:
	DirectRequestPOST.java 
Log Message:
uses ClientHttpRequest 

Index: DirectRequestPOST.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestPOST.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- DirectRequestPOST.java	21 Sep 2009 16:28:33 -0000	1.5
+++ DirectRequestPOST.java	22 Sep 2009 12:37:57 -0000	1.6
@@ -4,18 +4,14 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.request;
 
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.net.URLConnection;
 import java.util.Hashtable;
 import java.util.Map;
-import java.util.Random;
 
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.input.DirectInputModule;
 import org.w3c.unicorn.response.Response;
+import org.w3c.unicorn.util.ClientHttpRequest;
 
 /**
  * Class to make a request directly using POST method
@@ -25,11 +21,6 @@
 public class DirectRequestPOST extends Request {
 
 	/**
-	 * generate a random number
-	 */
-	private static Random aRandom = new Random();
-
-	/**
 	 * URL for the post direct request
 	 */
 	private String sURL = null;
@@ -40,33 +31,6 @@
 	private Map<String, String> mapOfParameter = null;
 
 	/**
-	 * Random string for hazardous purpose
-	 */
-	private String sBoundary = "---------------------------"
-			+ DirectRequestPOST.randomString()
-			+ DirectRequestPOST.randomString()
-			+ DirectRequestPOST.randomString();
-
-	/**
-	 * URL to connect
-	 */
-	private URLConnection aURLConnection = null;
-
-	/**
-	 * Output stream for the post
-	 */
-	private OutputStream aOutputStream = null;
-
-	/**
-	 * Generate random strings
-	 * 
-	 * @return a random string
-	 */
-	private static String randomString() {
-		return Long.toString(DirectRequestPOST.aRandom.nextLong(), 36);
-	}
-
-	/**
 	 * Constructor for a direct request using post method
 	 * 
 	 * @param sURL
@@ -106,60 +70,12 @@
 	@Override
 	public Response doRequest() throws Exception {
 		logger.trace("doRequest");
-		final URL aURL = new URL(sURL);
-		this.aURLConnection = aURL.openConnection();
-		this.aURLConnection.setDoOutput(true);
-		this.aURLConnection.setRequestProperty("Content-Type",
-				"multipart/form-data; boundary=" + sBoundary);
-		this.aURLConnection.setRequestProperty("Accept-Language", this.sLang);
-
-		if (null == this.aOutputStream) {
-			this.aOutputStream = this.aURLConnection.getOutputStream();
-		}
-		for (final String sName : this.mapOfParameter.keySet()) {
-			final String sValue = this.mapOfParameter.get(sName);
-			logger.trace("addParameter");
-			logger.debug("Name :" + sName + ".");
-			logger.debug("Value :" + sValue + ".");
-			logger.debug("--");
-			logger.debug(this.sBoundary);
-			logger.debug("\r\n");
-			logger.debug("Content-Disposition: form-data; name=\"");
-			logger.debug(sName);
-			logger.debug('"');
-			logger.debug("\r\n");
-			logger.debug("\r\n");
-			logger.debug(sValue);
-			logger.debug("\r\n");
-			// boundary
-			this.aOutputStream.write("--".getBytes());
-			this.aOutputStream.write(this.sBoundary.getBytes());
-			// writeName
-			this.aOutputStream.write("\r\n".getBytes());
-			this.aOutputStream.write("Content-Disposition: form-data; name=\""
-					.getBytes());
-			this.aOutputStream.write(sName.getBytes());
-			this.aOutputStream.write('"');
-			// newline
-			this.aOutputStream.write("\r\n".getBytes());
-			// newline
-			this.aOutputStream.write("\r\n".getBytes());
-			// writeln
-			this.aOutputStream.write(sValue.getBytes());
-			this.aOutputStream.write("\r\n".getBytes());
-		}
-		logger.debug("--");
-		logger.debug(this.sBoundary);
-		logger.debug("--");
-		logger.debug("\r\n");
-		this.aOutputStream.write("--".getBytes());
-		this.aOutputStream.write(this.sBoundary.getBytes());
-		this.aOutputStream.write("--".getBytes());
-		this.aOutputStream.write("\r\n".getBytes());
-		this.aOutputStream.close();
-
-		InputStream is = aURLConnection.getInputStream();
+		
+		ClientHttpRequest request = new ClientHttpRequest(sURL);
+		request.setLang(sLang);
+		request.setParameters(mapOfParameter);
 
+		InputStream is = request.post();
 		return streamToResponse(is);
 	}
 
Received on Tuesday, 22 September 2009 12:38:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:14 GMT