Return-Path: Delivered-To: apmail-incubator-jspwiki-user-archive@locus.apache.org Received: (qmail 61815 invoked from network); 11 Oct 2008 10:44:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Oct 2008 10:44:14 -0000 Received: (qmail 99215 invoked by uid 500); 11 Oct 2008 10:44:13 -0000 Delivered-To: apmail-incubator-jspwiki-user-archive@incubator.apache.org Received: (qmail 99196 invoked by uid 500); 11 Oct 2008 10:44:12 -0000 Mailing-List: contact jspwiki-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jspwiki-user@incubator.apache.org Delivered-To: mailing list jspwiki-user@incubator.apache.org Received: (qmail 99184 invoked by uid 99); 11 Oct 2008 10:44:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Oct 2008 03:44:12 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jalkanen@ecyrd.com designates 193.64.5.122 as permitted sender) Received: from [193.64.5.122] (HELO mail.ecyrd.com) (193.64.5.122) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Oct 2008 10:43:07 +0000 Received: from [80.186.92.4] (80-186-92-4.elisa-mobile.fi [80.186.92.4]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ecyrd.com (Postfix) with ESMTP id 09A79483D2 for ; Sat, 11 Oct 2008 13:42:50 +0300 (EEST) From: jalkanen@ecyrd.com Reply-to: jalkanen@ecyrd.com To: jspwiki-user@incubator.apache.org Subject: VS: Re: Upload Question Date: Sat, 11 Oct 2008 13:42:45 +0300 Message-ID: <36mkjz9PfJvx.jbKZHBdt@mail.ecyrd.com> X-Mailer: EPOC Email Version 2.10 MIME-Version: 1.0 Content-Language: i-default Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Hi! I think we might need to see the code. Can you post it to the list, = please? /janne -- alkuper. viesti -- Aihe: Re: Upload Question L=C3=A4hett=C3=A4j=C3=A4: Benedikt Mohrmann P=C3=A4iv=C3=A4m=C3=A4=C3=A4r=C3=A4: 11.10.2008 12:42 Hi, I did all this. The HTML output is how it should be, but the request is not handled when = I hit the button. The WikiSite: [{FormSet form=3D'uploadForm'}] [{MyFormOpen form=3D'uploadForm'}] [{FormInput type=3D'file' name=3D'uploadInput'}] [{FormInput type=3D'submit' name=3D'uploadFile' value=3D'Upload'}] [{FormOutput form=3D'uploadForm' handler=3D'MyPlugin'}] [{FormClose}] To test it I wrote a plugin which justs returns "Works". Now when I switch to the normal FormOpen tag ([{FormOpen=20 form=3D'uploadForm'}]) the output is "Works". When I use my own one, there is no output. Any ideas, why this is not handled? Best regards Benedikt Janne Jalkanen schrieb: > > They are real plugins. > > I recommend that you copy FormOpen.java to MyFormOpen.java, rename the = > class, change the code, and then use [{MyFormOpen}] instead of=20 > [{FormOpen}] in the plugins that you need. > > You can easily write your own plugin which does what you said: > > package whatever.package.you.use; > > public class MyPlugin implements WikiPlugin > { > public String execute(WikiContext ctx, Map params) > { > returnStringBuffer.append("
"); > returnStringBuffer.append(" action=3D\"Wiki.jsp?page=3DMyTest\" name=3D\"uploadForm\"=20 > accept-charset=3D\"UTF-8\" method=3D\"post\" =20 > enctype=3D\"multipart/form-data\">"); > returnStringBuffer.append(" name=3D\"formname\" value=3D\"uploadForm\"/>"); > returnStringBuffer.append(" type=3D\"file\"> value=3D\"Hochladen\" />"); > > return returnStringBuffer.toString(); > } > } > > then use [{whatever.package.you.use.MyPlugin}] on a wikipage. I don't = > know what it does, but it is easy :-) > > /Janne > > On Oct 10, 2008, at 16:16 , Benedikt Mohrmann wrote: > >> Hi, >> >> the problem is that the Forms are directly in the JSPWiki.jar = file. >> Thus they are no real plugins I guess. >> I tried to change the FormOpen.java and inserted >> tag.append( "\" method=3D\""+method+"\"=20 >> enctype=3D\"multipart/form-data\">\n" ); >> then build the class file and just put it into the JSPWiki.jar. >> >> As a result all the other plugins which use forms were not working = >> correctly (that was of course clear). >> But my Upload Plugin did not work, too. >> When I hit the submit button nothing happened. >> >> Is there no possibility to insert a plugin which creates HTML code = >> the following way: >> returnStringBuffer.append("
"); >> returnStringBuffer.append("> action=3D\"Wiki.jsp?page=3DMyTest\" name=3D\"uploadForm\"=20 >> accept-charset=3D\"UTF-8\" method=3D\"post\"=20 >> enctype=3D\"multipart/form-data\">"); >> returnStringBuffer.append("> name=3D\"formname\" value=3D\"uploadForm\"/>"); >> returnStringBuffer.append("> type=3D\"file\">> id=3D\"upload\" value=3D\"Hochladen\" />"); >> >> Then just integrate the plugin into the WikiPage. >> >> And then put a second plugin via [{FormOutput form=3D'uploadForm' = >> handler=3D'MyPlugin'}] into the WikiPage? >> >> At the moment this seems not to work, as nothing happens when I click = >> on the submit button. >> >> Best regards >> Benedikt >> >> >> Janne Jalkanen schrieb: >>> Probably the quickest way for you now is to simply make a copy of = the >>> relevant Form plugin, name it something else, and just change the >>> enctype. >>> >>> Also please put in a JIRA request for the enctype to be = changeable, >>> and we'll snatch it in either 2.8.1 or 3.0. >>> >>> /Janne >>> >>> On Fri, Oct 10, 2008 at 10:50:32AM +0200, Benedikt Mohrmann = wrote: >>> >>>> Hi, >>>> >>>> just checked it again. >>>> The problem is definetely the form: >>>> = org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: = >>>> the request doesn't contain a multipart/form-data or=20 >>>> multipart/mixed stream, content type header is=20 >>>> application/x-www-form-urlencoded >>>> >>>> Pretty bad that you can not change the enctype. >>>> In the Wiki Src it is: >>>> tag.append( "\" method=3D\""+method+"\"=20 >>>> enctype=3D\"application/x-www-form-urlencoded\">\n" ); >>>> >>>> Can't I just change this? >>>> >>>> Another way could be to write a plugin with the following code = >>>> (snippet): >>>> returnStringBuffer.append("
"); >>>> returnStringBuffer.append(">>> action=3D\"Wiki.jsp?page=3DMyTest\" name=3D\"uploadForm\"=20 >>>> accept-charset=3D\"UTF-8\" method=3D\"post\"=20 >>>> enctype=3D\"multipart/form-data\">"); >>>> returnStringBuffer.append(">>> name=3D\"formname\" value=3D\"uploadForm\"/>"); >>>> returnStringBuffer.append(">>> type=3D\"file\">>>> id=3D\"upload\" value=3D\"Hochladen\" />"); >>>> returnStringBuffer.append("
"); >>>> >>>> This would create a form, but how can I tell the Wiki which plugin = >>>> to use, when the button is hit? >>>> >>>> Regards >>>> Benedikt >>>> >>>> >>>> Janne Jalkanen schrieb: >>>> >>>>> I think it is important to look into the cause... The stack trace = >>>>> would be important, yes. There could be many things failing. >>>>> >>>>> /Janne >>>>> >>>>> On Oct 9, 2008, at 19:15 , Harry Metske wrote: >>>>> >>>>> >>>>>> I think so too (multipart/form-data), but can you print the=20 >>>>>> stacktrace just >>>>>> before returning " BUG" , maybe you'll get a clue then ? >>>>>> >>>>>> The FormOpen class currently has a hardcoded >>>>>> "application/x-www-form-urlencoded", I think this should be=20 >>>>>> parameterizable >>>>>> with the current value as the default. >>>>>> >>>>>> >>>>>> regards, >>>>>> Harry >>>>>> >>>>>> >>>>>> 2008/10/9 Benedikt Mohrmann >>>>>> >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> I tried a few things already, but did not get it to work so = far. >>>>>>> >>>>>>> At first I created a new site, which contains: >>>>>>> [{FormSet form=3D'searchForm'}] >>>>>>> [{FormOpen form=3D'searchForm'}] >>>>>>> [{FormInput type=3D'file' name=3D'searchInput'}] >>>>>>> >>>>>>> [{FormInput type=3D'submit' name=3D'submit' = value=3D'Submit'}] >>>>>>> [{FormClose}] >>>>>>> [{FormOutput form=3D'searchForm' handler=3D'MyTest2'}] >>>>>>> >>>>>>> Thus there is only a form where you can upload your data. >>>>>>> >>>>>>> The Plugin contains the following code (at this time really = >>>>>>> simple, just to >>>>>>> check if it works): >>>>>>> public class MyTest2 implements WikiPlugin { >>>>>>> >>>>>>> @Override >>>>>>> public String execute(WikiContext context, Map params) = throws >>>>>>> PluginException { >>>>>>> HttpServletRequest request =3D = context.getHttpRequest(); >>>>>>> boolean isMultipart =3D=20 >>>>>>> ServletFileUpload.isMultipartContent(request); >>>>>>> // Create a factory for disk-based file items >>>>>>> FileItemFactory factory =3D new DiskFileItemFactory(); >>>>>>> >>>>>>> // Create a new file upload handler >>>>>>> ServletFileUpload upload =3D new = ServletFileUpload(factory); >>>>>>> >>>>>>> // Parse the request >>>>>>> List items =3D null; >>>>>>> try { >>>>>>> items =3D upload.parseRequest(request); >>>>>>> } catch (Exception e) { >>>>>>> // TODO Auto-generated catch block >>>>>>> return "BUG"; >>>>>>> } >>>>>>> return "Works"; >>>>>>> } >>>>>>> } >>>>>>> >>>>>>> So far I always get the "BUG" output when I choose a file and = >>>>>>> hit the >>>>>>> submitbutton. >>>>>>> One problem could be that when I take a look at the produced = >>>>>>> HTML code, the >>>>>>> form is introduced with: >>>>>>> >>>>>>>
>>>>>> accept-charset=3D"UTF-8" method=3D"post" >>>>>>> enctype=3D"application/x-www-form-urlencoded"> >>>>>>> >>>>>>> I think it should be the enctype: multipart/form-data >>>>>>> But I don't know if that is the point. >>>>>>> >>>>>>> Any other ideas? >>>>>>> >>>>>>> >>>>>>> Best regards >>>>>>> Benedikt >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> Harry Metske schrieb: >>>>>>> >>>>>>> >>>>>>>> my previous answer was a bit too much in a hurry.... >>>>>>>> >>>>>>>> first your compile, Eclipse tells you there is no method=20 >>>>>>>> getHttpRequest >>>>>>>> for >>>>>>>> a wiki context, that is strange, looking at the source it does = >>>>>>>> have it : >>>>>>>> >>>>>>>> ........ >>>>>>>> /** >>>>>>>> * If the request did originate from a HTTP request, >>>>>>>> * then the HTTP request can be fetched here. However, it = >>>>>>>> the request >>>>>>>> * did NOT originate from a HTTP request, then this method = will >>>>>>>> * return null, and YOU SHOULD CHECK FOR IT! >>>>>>>> * >>>>>>>> * @return Null, if no HTTP request was done. >>>>>>>> * @since 2.0.13. >>>>>>>> */ >>>>>>>> public HttpServletRequest getHttpRequest() >>>>>>>> { >>>>>>>> return m_request; >>>>>>>> } >>>>>>>> ....... >>>>>>>> >>>>>>>> and if you can't compile it, I shouldn't even try to run it. >>>>>>>> Maybe you can reply the complete source of your plugin ? >>>>>>>> >>>>>>>> regards, >>>>>>>> Harry >>>>>>>> >>>>>>>> 2008/10/8 Benedikt Mohrmann >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Hi, >>>>>>>>> >>>>>>>>> thanks for your answer- I already had a look at commons=20 >>>>>>>>> fileupload. >>>>>>>>> But the problem is, when I use: >>>>>>>>> >>>>>>>>> HttpServletRequest request =3D context.getHttpRequest(); >>>>>>>>> >>>>>>>>> JSPWiki tells me >>>>>>>>> >>>>>>>>> HttpServletRequest cannot be resolved to a type >>>>>>>>> The type javax.servlet.http.HttpServletRequest cannot be=20 >>>>>>>>> resolved. >>>>>>>>> >>>>>>>>> In addition I am implementing my plugin in Eclipse and it = >>>>>>>>> tells me that >>>>>>>>> there is no method getHttpRequest for a wiki context. >>>>>>>>> >>>>>>>>> Best regards >>>>>>>>> Benedikt >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Harry Metske schrieb: >>>>>>>>> >>>>>>>>> Benedikt, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> in your plugin you have access to the HttpServletRequest ( >>>>>>>>>> HttpServletRequest request =3D context.getHttpRequest(); ) = . >>>>>>>>>> Once you have this, I think you can use many samples/tools to = >>>>>>>>>> handle the >>>>>>>>>> uploaded file, but maybe the best one is commons fileupload = ( >>>>>>>>>> http://commons.apache.org/fileupload/using.html), this binary = >>>>>>>>>> jar is >>>>>>>>>> already >>>>>>>>>> in the JSPWiki distribution. >>>>>>>>>> >>>>>>>>>> regards, >>>>>>>>>> Harry >>>>>>>>>> >>>>>>>>>> 2008/10/7 Benedikt Mohrmann >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> Hi, >>>>>>>>>>> >>>>>>>>>>> my intention is to upload a file via JSPWiki, but not as an = >>>>>>>>>>> attachment. >>>>>>>>>>> >>>>>>>>>>> I am trying to upload a file, thus I created a form=20 >>>>>>>>>>> containing a file >>>>>>>>>>> chooser and a submitbutton. >>>>>>>>>>> The goal is, that the input file is transferred to the=20 >>>>>>>>>>> server and then >>>>>>>>>>> handled by a plugin I wrote. >>>>>>>>>>> >>>>>>>>>>> The plugin just puts the file as a Serializable into a=20 >>>>>>>>>>> database (which >>>>>>>>>>> already works, when I read a file from my harddisk). >>>>>>>>>>> But I am not yet not able to transfer the content of the = >>>>>>>>>>> file as a >>>>>>>>>>> stream >>>>>>>>>>> or something like that. >>>>>>>>>>> >>>>>>>>>>> Any experiences how this could work? >>>>>>>>>>> >>>>>>>>>>> Best regards >>>>>>>>>>> Benedikt >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >