From: <asa...@us...> - 2013-09-14 21:19:23
|
Revision: 8482 http://sourceforge.net/p/htmlunit/code/8482 Author: asashour Date: 2013-09-14 21:19:01 +0000 (Sat, 14 Sep 2013) Log Message: ----------- KeyDataPair: deprecate getContentType(), as it should be named 'getMimeType()', initial part for migration to HttpClient 4.3 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-09-14 09:41:02 UTC (rev 8481) +++ trunk/htmlunit/src/changes/changes.xml 2013-09-14 21:19:01 UTC (rev 8482) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="update" dev="asashour"> + KeyDataPair: deprecate getContentType(). + </action> <action type="update" dev="rbri"> CSS: cssparser updated to 0.9.10. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-09-14 09:41:02 UTC (rev 8481) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-09-14 21:19:01 UTC (rev 8482) @@ -417,9 +417,9 @@ } ContentBody buildFilePart(final KeyDataPair pairWithFile) { - String contentType = pairWithFile.getContentType(); - if (contentType == null) { - contentType = "application/octet-stream"; + String mimeType = pairWithFile.getMimeType(); + if (mimeType == null) { + mimeType = "application/octet-stream"; } final File file = pairWithFile.getFile(); @@ -427,20 +427,20 @@ if (pairWithFile.getData() != null) { if (file == null) { return new InputStreamBody( - new ByteArrayInputStream(pairWithFile.getData()), contentType, pairWithFile.getValue()); + new ByteArrayInputStream(pairWithFile.getData()), mimeType, pairWithFile.getValue()); } if (webClient_.getBrowserVersion().hasFeature(HEADER_CONTENT_DISPOSITION_ABSOLUTE_PATH)) { return new InputStreamBody( - new ByteArrayInputStream(pairWithFile.getData()), contentType, file.getAbsolutePath()); + new ByteArrayInputStream(pairWithFile.getData()), mimeType, file.getAbsolutePath()); } return new InputStreamBody( - new ByteArrayInputStream(pairWithFile.getData()), contentType, file.getName()); + new ByteArrayInputStream(pairWithFile.getData()), mimeType, file.getName()); } if (file == null) { - return new InputStreamBody(new ByteArrayInputStream(new byte[0]), contentType, pairWithFile.getValue()) { + return new InputStreamBody(new ByteArrayInputStream(new byte[0]), mimeType, pairWithFile.getValue()) { // Overridden in order not to have a chunked response. @Override public long getContentLength() { @@ -449,7 +449,7 @@ }; } - return new FileBody(pairWithFile.getFile(), contentType) { + return new FileBody(pairWithFile.getFile(), mimeType) { @Override public String getFilename() { if (getFile() == null) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java 2013-09-14 09:41:02 UTC (rev 8481) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/KeyDataPair.java 2013-09-14 21:19:01 UTC (rev 8482) @@ -23,11 +23,12 @@ * @author Brad Clarke * @author David D. Kilzer * @author Mike Bowler + * @author Ahmed Ashour */ public class KeyDataPair extends NameValuePair { private final File fileObject_; - private final String contentType_; + private final String mimeType_; private final String charset_; private byte[] data_; @@ -36,10 +37,10 @@ * * @param key the key * @param file the file - * @param contentType the content type + * @param mimeType the MIME type * @param charset the charset encoding */ - public KeyDataPair(final String key, final File file, final String contentType, + public KeyDataPair(final String key, final File file, final String mimeType, final String charset) { super(key, file.getName()); @@ -51,7 +52,7 @@ fileObject_ = null; } - contentType_ = contentType; + mimeType_ = mimeType; charset_ = charset; } @@ -95,12 +96,22 @@ /** * Gets the content type for this file upload. * @return the content type + * @deprecated as of 2.13, please use {@link #getMimeType()} */ + @Deprecated public String getContentType() { - return contentType_; + return getMimeType(); } /** + * Gets the MIME type for this file upload. + * @return the MIME type + */ + public String getMimeType() { + return mimeType_; + } + + /** * Gets in-memory data assigned to file value. * @return <code>null</code> if the file content should be used. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2013-09-14 09:41:02 UTC (rev 8481) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2013-09-14 21:19:01 UTC (rev 8482) @@ -19,7 +19,6 @@ import java.io.InputStream; import java.io.Writer; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -106,7 +105,6 @@ * {@inheritDoc} */ @Override - @SuppressWarnings("unchecked") protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); @@ -115,7 +113,7 @@ if (ServletFileUpload.isMultipartContent(request)) { try { final ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); - for (final FileItem item : (List<FileItem>) upload.parseRequest(request)) { + for (final FileItem item : upload.parseRequest(request)) { if ("myInput".equals(item.getFieldName())) { writer.write("CONTENT_TYPE:" + item.getContentType()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java 2013-09-14 09:41:02 UTC (rev 8481) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java 2013-09-14 21:19:01 UTC (rev 8482) @@ -28,7 +28,6 @@ import java.net.URLDecoder; import java.nio.charset.Charset; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,6 +43,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.IOUtils; +import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; @@ -164,10 +164,10 @@ makeHttpMethod.setAccessible(true); final HttpPost httpPost = (HttpPost) makeHttpMethod .invoke(new HttpWebConnection(client), webConnection.getLastWebRequest()); - final MultipartEntity multipartEntity = (MultipartEntity) httpPost.getEntity(); + final HttpEntity httpEntity = httpPost.getEntity(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); - multipartEntity.writeTo(out); + httpEntity.writeTo(out); out.close(); Assert.assertTrue( @@ -212,10 +212,10 @@ makeHttpMethod.setAccessible(true); final HttpPost httpPost = (HttpPost) makeHttpMethod .invoke(new HttpWebConnection(client), webConnection.getLastWebRequest()); - final MultipartEntity multipartEntity = (MultipartEntity) httpPost.getEntity(); + final HttpEntity httpEntity = httpPost.getEntity(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); - multipartEntity.writeTo(out); + httpEntity.writeTo(out); out.close(); if (getBrowserVersion().isIE()) { @@ -266,10 +266,10 @@ makeHttpMethod.setAccessible(true); final HttpPost httpPost = (HttpPost) makeHttpMethod .invoke(new HttpWebConnection(client), webConnection.getLastWebRequest()); - final MultipartEntity multipartEntity = (MultipartEntity) httpPost.getEntity(); + final HttpEntity httpEntity = httpPost.getEntity(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); - multipartEntity.writeTo(out); + httpEntity.writeTo(out); out.close(); assertTrue(out.toString() @@ -336,13 +336,13 @@ f.getInputByName("mysubmit").click(); final KeyDataPair pair = (KeyDataPair) webConnection.getLastParameters().get(0); assertNotNull(pair.getFile()); - Assert.assertFalse("Content type: " + pair.getContentType(), "text/webtest".equals(pair.getContentType())); + Assert.assertFalse("Content type: " + pair.getMimeType(), "text/webtest".equals(pair.getMimeType())); fileInput.setContentType("text/webtest"); f.getInputByName("mysubmit").click(); final KeyDataPair pair2 = (KeyDataPair) webConnection.getLastParameters().get(0); assertNotNull(pair2.getFile()); - assertEquals("text/webtest", pair2.getContentType()); + assertEquals("text/webtest", pair2.getMimeType()); } /** @@ -463,7 +463,6 @@ * {@inheritDoc} */ @Override - @SuppressWarnings("unchecked") protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); @@ -472,7 +471,7 @@ if (ServletFileUpload.isMultipartContent(request)) { try { final ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); - for (final FileItem item : (List<FileItem>) upload.parseRequest(request)) { + for (final FileItem item : upload.parseRequest(request)) { if ("myInput".equals(item.getFieldName())) { final String path = item.getName(); for (final char ch : path.toCharArray()) { |