From: Brad C. <bc...@bo...> - 2003-08-14 17:57:52
|
Support for putting your file name in the box was already there, it just didn't send the file to the server when you submit()ed the containing HtmlForm (I think it just sent the filename as a string). You'll need a recent CVS checkout to apply a patch. Most CVS implementations come with a "patch" command (try "patch --help" or "man patch"), or if you're like me and use Eclipse there's an "Apply Patch..." option on the Team menu. I'm sure most other IDEs have something similar. A good description of what a patch is: http://cocoon.apache.org/2.0/howto/howto-patch.html Brad C At 12:08 PM 8/14/2003, James Asher wrote: >I, too, have just come across a need for this. I >already know the path to the file, I just need a way >of accessing the input field for the path, I'm >assuming I'll be able to do that with this patch? >Also, I don't know how to use this patch, do I need to >do a CVS check out from the HtmlUnit CVS? > >Thanks, > James > > >--- Brad Clarke <bc...@bo...> wrote: > > > > RFE: > > >http://sourceforge.net/tracker/index.php?func=detail&aid=625328&group_id=47038&atid=448269 > > > > I have managed to get an HtmlFileInput to upload a > > file to the server with > > this patch. It's likely in no condition to go into > > just CVS yet, I'm just > > looking for comments and suggestions for > > improvement. > > > > My personal issues with it are: > > - I really have no clue what I'm doing :) > > - It requires the unreleased commons-httpclient 2.0 > > (this is probably > > unavoidable) > > - I've really done nothing to see how this mimics > > real world web browsers, > > I just know it worked for me > > - FormEncodingType seems sort of like a waste to me, > > but it seemed "right" > > to model it after SubmitMethod > > - FormEncodingType naming conventions were basically > > random. Someone with > > more experience with this could probably name things > > better. > > - I had to add a lot of new API to preserve > > compatibility because so many > > things are public. Maybe some of this could be > > removed?? > > - KeyDataPair seems like a really bad idea to me, > > but it helped to not have > > to touch much of the surrounding code > > - I really have no idea how to "properly" unit test > > this, so there are no > > new tests (though all the old ones still pass) > > - The new stuff is completely unimplemented in > > FakeWebConnection > > - There were other little things I noticed in the > > RFCs that I just ignored > > because I don't know exactly how commons-httpclient > > fits in > > - The checkstyle task in the ant build.xml won't > > work so I doubt this meets > > the standards (though I did make an effort) > > - The copyright is not on the new files, but only to > > make the diff smaller. > > Just act like it's there :) > > - If the encoding type on the form is not correct it > > defaults to the old > > broken behavior. From the RFCs it sounds like there > > should be a MIME > > encoding of the file and it added to the POST as > > text. I could live with > > this being ignored but maybe others can't? > > > > Brad C > > > > > > Index: > > >src/java/com/gargoylesoftware/htmlunit/FormEncodingType.java > > >=================================================================== > > RCS file: > > >src/java/com/gargoylesoftware/htmlunit/FormEncodingType.java > > diff -N > > >src/java/com/gargoylesoftware/htmlunit/FormEncodingType.java > > --- /dev/null 1 Jan 1970 00:00:00 -0000 > > +++ > > >src/java/com/gargoylesoftware/htmlunit/FormEncodingType.java > > 12 Aug > > 2003 22:56:55 -0000 > > @@ -0,0 +1,73 @@ > > +package com.gargoylesoftware.htmlunit; > > + > > +import > > org.apache.commons.httpclient.methods.PostMethod; > > +import > > >org.apache.commons.httpclient.methods.MultipartPostMethod; > > + > > +/** > > + * A collection of constants that represent the > > various ways a form can be > > + * encoded when submitted > > + * > > + * @version $Revision: 1.1 $ > > + */ > > +public class FormEncodingType { > > + > > + /** > > + * URL_ENCODED > > + */ > > + public static final FormEncodingType URL_ENCODED = > > + new > > >FormEncodingType(PostMethod.FORM_URL_ENCODED_CONTENT_TYPE); > > + /** > > + * MULTIPART > > + */ > > + public static final FormEncodingType MULTIPART = > > + new > > >FormEncodingType(MultipartPostMethod.MULTIPART_FORM_CONTENT_TYPE); > > + > > + private final String name_; > > + > > + private FormEncodingType(final String name) { > > + name_ = name; > > + } > > + > > + /** > > + * Return the name of this EncodingType > > + * > > + * @return See above > > + */ > > + public String getName() { > > + return name_; > > + } > > + > > + /** > > + * Return the constant that matches the given > > name > > + * > > + * @param name The name to search by > > + * @return See above > > + */ > > + public static FormEncodingType getInstance(final > > String name) { > > + final String lowerCaseName = name.toLowerCase(); > > + final FormEncodingType allInstances[] = new > > FormEncodingType[] { > > URL_ENCODED, MULTIPART }; > > + > > + int i; > > + for (i = 0; i < allInstances.length; i++) { > > + if > > (allInstances[i].getName().equals(lowerCaseName)) { > > + return allInstances[i]; > > + } > > + } > > + > > + // Special case: empty string defaults to url > > encoded > > + if (name.equals("")) { > > + return URL_ENCODED; > > + } > > + > > + throw new IllegalArgumentException("No encoding > > type found for [" + name > > + "]"); > > + } > > + > > + /** > > + * Return a string representation of this object > > + * > > + * @return See above > > + */ > > + public String toString() { > > + return "EncodingType[name=" + getName() + "]"; > > + } > > +} > > Index: > > >src/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java > > >=================================================================== > > RCS file: > > >/cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java,v > > retrieving revision 1.13 > > diff -u -r1.13 HttpWebConnection.java > > --- > > >src/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java > > 19 Jul > > 2003 17:17:30 -0000 1.13 > > +++ > > >src/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java > > 12 Aug > > 2003 22:56:55 -0000 > > @@ -37,6 +37,7 @@ > > */ > > package com.gargoylesoftware.htmlunit; > > > > +import java.io.File; > > import java.io.ByteArrayInputStream; > > import java.io.IOException; > > import java.io.InputStream; > > @@ -58,6 +59,7 @@ > > import org.apache.commons.httpclient.URI; > > import org.apache.commons.httpclient.URIException; > > import > > org.apache.commons.httpclient.cookie.CookiePolicy; > > +import > > >org.apache.commons.httpclient.methods.MultipartPostMethod; > > import > > org.apache.commons.httpclient.methods.GetMethod; > > import > > org.apache.commons.httpclient.methods.PostMethod; > > import org.apache.commons.logging.Log; > > @@ -98,12 +100,32 @@ > > super(webClient, proxyHost, proxyPort); > > } > > > > - > > + /** > > + * Submit a request and retrieve a response > > + * > > >=== message truncated === > > >__________________________________ >Do you Yahoo!? >Yahoo! SiteBuilder - Free, easy-to-use web site design software >http://sitebuilder.yahoo.com > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including >Data Reports, E-commerce, Portals, and Forums are available now. >Download today and enter to win an XBOX or Visual Studio .NET. >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 >_______________________________________________ >HtmlUnit-develop mailing list >Htm...@li... >https://lists.sourceforge.net/lists/listinfo/htmlunit-develop |