2006/unicorn/src/org/w3c/unicorn/request UploadRequest.java,1.2,1.3 DirectRequestGET.java,1.3,1.4 Request.java,1.2,1.3 URIRequest.java,1.2,1.3 DirectRequestPOST.java,1.2,1.3

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/request
In directory hutz:/tmp/cvs-serv8804/src/org/w3c/unicorn/request

Modified Files:
	UploadRequest.java DirectRequestGET.java Request.java 
	URIRequest.java DirectRequestPOST.java 
Log Message:
Restored ClientHttpRequest as Apache's HttpClient was making the markup validator fail on file upload (in streaming mode) for not much added benefit.
Same goes for EscapeXMLEntities. Not much benefit from using Apache's classes which need several dependencies

Index: DirectRequestPOST.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestPOST.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- DirectRequestPOST.java	28 Aug 2009 12:39:48 -0000	1.2
+++ DirectRequestPOST.java	3 Sep 2009 16:43:19 -0000	1.3
@@ -114,7 +114,7 @@
 	}
 
 	@Override
-	public Response doRequest() throws IOException {
+	public Response doRequest() throws Exception {
 		Request.logger.trace("doRequest");
 		final URL aURL = new URL(sURL);
 		this.aURLConnection = aURL.openConnection();

Index: DirectRequestGET.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestGET.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- DirectRequestGET.java	2 Sep 2009 12:41:28 -0000	1.3
+++ DirectRequestGET.java	3 Sep 2009 16:43:19 -0000	1.4
@@ -86,7 +86,7 @@
 	}
 
 	@Override
-	public Response doRequest() throws IOException {
+	public Response doRequest() throws Exception {
 		Request.logger.trace("doRequest");
 		final URL aURL;
 		if (null == this.sParameter) {

Index: UploadRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/UploadRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- UploadRequest.java	28 Aug 2009 12:39:48 -0000	1.2
+++ UploadRequest.java	3 Sep 2009 16:43:19 -0000	1.3
@@ -5,20 +5,16 @@
 package org.w3c.unicorn.request;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.mime.MultipartEntity;
-import org.apache.http.entity.mime.content.InputStreamBody;
-import org.apache.http.entity.mime.content.StringBody;
-import org.apache.http.impl.client.DefaultHttpClient;
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.input.InputModule;
 import org.w3c.unicorn.input.UploadInputModule;
 import org.w3c.unicorn.response.Response;
+import org.w3c.unicorn.util.ClientHttpRequest;
 
 /**
  * Class to deal with the upload request
@@ -38,6 +34,11 @@
 	private String sInputParameterName = null;
 
 	/**
+	 * A http client for the request in upload
+	 */
+	private ClientHttpRequest aClientHttpRequest = null;
+
+	/**
 	 * An input module with upload
 	 */
 	private UploadInputModule aUploadInputModule = null;
@@ -98,14 +99,14 @@
 	}
 
 	@Override
-	public Response doRequest() throws IOException {
+	public Response doRequest() throws Exception {
 		Request.logger.trace("doRequest");
-		DefaultHttpClient httpclient = new DefaultHttpClient();
-		 
-		HttpPost method = new HttpPost(sURL);
-		method.setHeader("Accept-Language", sLang);
-		MultipartEntity entity = new MultipartEntity();
-
+		this.aClientHttpRequest = new ClientHttpRequest(sURL);
+		Request.logger.debug("Lang : " + this.sLang + ".");
+		this.aClientHttpRequest.setLang(sLang);
+		this.aClientHttpRequest.setParameter(this.sInputParameterName,
+				this.aUploadInputModule.getFileName(), this.aUploadInputModule
+						.getInputStream());
 		for (final String sName : this.mapOfParameter.keySet()) {
 			final String sValue = this.mapOfParameter.get(sName);
 			Request.logger.trace("addParameter");
@@ -113,33 +114,26 @@
 				Request.logger.debug("Name :" + sName + ".");
 				Request.logger.debug("Value :" + sValue + ".");
 			}
-			entity.addPart(sName, new StringBody(sValue));
-			//entity.addPart(sName, new StringBody(sValue, Charset.forName("UTF-8")));
+			this.aClientHttpRequest.setParameter(sName, sValue);
 		}
+		InputStream is = this.aClientHttpRequest.post();
 
-		InputStreamBody file = new InputStreamBody(this.aUploadInputModule.getInputStream(), 
-				this.aUploadInputModule.getMimeType().toString(), 
-				this.aUploadInputModule.getFileName());
-		entity.addPart(this.sInputParameterName, file);
-		method.setEntity(entity);
-		 
-		HttpResponse response = httpclient.execute(method);
-		return streamToResponse(response.getEntity().getContent());
+		return streamToResponse(is);
 	}
-	
+
 	@Override
 	public EnumInputMethod getInputMethod() {
 		Request.logger.trace("getInputMethod");
 		return EnumInputMethod.UPLOAD;
 	}
 
-	/*@Override
+	@Override
 	public String toString() {
 		final int iStringBufferSize = 1000;
 		final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);
 		aStringBuffer.append("ClientHttpRequest:").append(
 				this.aClientHttpRequest);
-		return aStringBuffer.toString();
-	}*/
+		return "lolmdr: " + aStringBuffer.toString();
+	}
 
 }

Index: Request.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/Request.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Request.java	28 Aug 2009 12:39:48 -0000	1.2
+++ Request.java	3 Sep 2009 16:43:19 -0000	1.3
@@ -4,16 +4,24 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.request;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.event.EventCartridge;
+import org.apache.velocity.app.event.implement.EscapeXmlReference;
+import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.input.InputModule;
 import org.w3c.unicorn.response.Response;
 import org.w3c.unicorn.response.parser.ResponseParserFactory;
+import org.w3c.unicorn.util.Templates;
 
 /**
  * 
@@ -67,9 +75,10 @@
 	 * @return the response of the observer
 	 * @throws IOException
 	 *             odd error occured
+	 * @throws Exception 
 	 */
 	public abstract org.w3c.unicorn.response.Response doRequest()
-			throws IOException;
+			throws IOException, Exception;
 
 	public abstract EnumInputMethod getInputMethod();
 
@@ -135,18 +144,21 @@
 		this.responseType = responseType;
 	}
 
-	protected Response streamToResponse(InputStream is) throws IOException {
+	protected Response streamToResponse(InputStream is) throws Exception {
 		StringBuilder builder = new StringBuilder();
 		InputStreamReader isr = new InputStreamReader(is, "UTF-8");
 		char[] chararray = new char[8192];
 		int readLength = 0;
+		Response res;
+		
 		while ((readLength = isr.read(chararray, 0, 8192)) > -1) {
 			builder.append(chararray, 0, readLength);
 		}
-
-		Response res = ResponseParserFactory.parse(builder.toString(), this
-				.getResponseType());
-		res.setXml(builder);
+		Request.logger.debug(builder);
+		res = ResponseParserFactory.parse(builder.toString(), this.getResponseType());
+		if(res != null) {
+			res.setXml(builder);
+		}
 
 		return res;
 	}

Index: URIRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/URIRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- URIRequest.java	28 Aug 2009 12:39:48 -0000	1.2
+++ URIRequest.java	3 Sep 2009 16:43:19 -0000	1.3
@@ -95,12 +95,10 @@
 
 	/**
 	 * Do the request to the observer
-	 * 
-	 * @throws IOException
-	 *             odd error occured
+	 * @throws Exception 
 	 */
 	@Override
-	public Response doRequest() throws IOException {
+	public Response doRequest() throws Exception {
 		Request.logger.trace("doRequest");
 		if (Request.logger.isDebugEnabled()) {
 			Request.logger.debug("URL : " + this.sURL + " .");

Received on Thursday, 3 September 2009 16:43:32 UTC