- From: Jean-Guilhem Rouel via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 27 Aug 2009 18:31:38 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/request In directory hutz:/tmp/cvs-serv12814/src/org/w3c/unicorn/request Modified Files: Tag: dev2 UploadRequest.java Log Message: Fixed a bug with file upload (mimetype was not set in UploadRequest.doRequest) Also use Apache escapers rather than custom one Index: UploadRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/Attic/UploadRequest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- UploadRequest.java 11 Aug 2009 16:05:43 -0000 1.1.2.1 +++ UploadRequest.java 27 Aug 2009 18:31:36 -0000 1.1.2.2 @@ -5,11 +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; @@ -101,12 +106,12 @@ @Override public Response doRequest() throws IOException { Request.logger.trace("doRequest"); - 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()); + DefaultHttpClient httpclient = new DefaultHttpClient(); + + HttpPost method = new HttpPost(sURL); + method.setHeader("Accept-Language", sLang); + MultipartEntity entity = new MultipartEntity(); + for (final String sName : this.mapOfParameter.keySet()) { final String sValue = this.mapOfParameter.get(sName); Request.logger.trace("addParameter"); @@ -114,13 +119,20 @@ Request.logger.debug("Name :" + sName + "."); Request.logger.debug("Value :" + sValue + "."); } - this.aClientHttpRequest.setParameter(sName, sValue); + entity.addPart(sName, new StringBody(sValue)); + //entity.addPart(sName, new StringBody(sValue, Charset.forName("UTF-8"))); } - InputStream is = this.aClientHttpRequest.post(); - return streamToResponse(is); + 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()); } - + @Override public EnumInputMethod getInputMethod() { Request.logger.trace("getInputMethod");
Received on Thursday, 27 August 2009 18:31:50 UTC