Return-Path: Delivered-To: apmail-incubator-jspwiki-user-archive@locus.apache.org Received: (qmail 52032 invoked from network); 11 Oct 2008 17:50:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Oct 2008 17:50:36 -0000 Received: (qmail 94298 invoked by uid 500); 11 Oct 2008 17:50:36 -0000 Delivered-To: apmail-incubator-jspwiki-user-archive@incubator.apache.org Received: (qmail 94283 invoked by uid 500); 11 Oct 2008 17:50:36 -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 94272 invoked by uid 99); 11 Oct 2008 17:50:36 -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 10:50:36 -0700 X-ASF-Spam-Status: No, hits=1.8 required=10.0 tests=MIME_QP_LONG_LINE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Janne.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 17:49:30 +0000 Received: from [192.168.9.101] (a91-153-166-149.elisa-laajakaista.fi [91.153.166.149]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.ecyrd.com (Postfix) with ESMTP id 31E8D483B0 for ; Sat, 11 Oct 2008 20:49:20 +0300 (EEST) Mime-Version: 1.0 (Apple Message framework v753.1) In-Reply-To: <48F0E442.5030303@mail.upb.de> References: <36mkjz9PfJvx.jbKZHBdt@mail.ecyrd.com> <48F0937E.5050805@mail.upb.de> <35EC1CC5-1CF0-4910-A80F-DA1A0E0BEF7E@ecyrd.com> <48F0E442.5030303@mail.upb.de> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: quoted-printable From: Janne Jalkanen Subject: Re: VS: Re: Upload Question Date: Sat, 11 Oct 2008 20:48:44 +0300 To: jspwiki-user@incubator.apache.org X-Mailer: Apple Mail (2.753.1) X-Virus-Checked: Checked by ClamAV on apache.org And could you also provide the HTML code resulting from this invocation? /Janne On 11 Oct 2008, at 20:37, Benedikt Mohrmann wrote: > Hi, > > the plugin should be activated by a click on the button. > > Here is the WikiPage > > [{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}] > > Best regards > Benedikt > > > Janne Jalkanen schrieb: >> >> And how do you use this on a page? >> >> /Janne >> >> On 11 Oct 2008, at 14:52, Benedikt Mohrmann wrote: >> >>> Hi, >>> >>> the plugin is quite easy: >>> public class MyPlugin implements WikiPlugin { >>> >>> @Override >>> public String execute(WikiContext context, Map params) throws =20 >>> PluginException { >>> HttpServletRequest request =3D = context.getHttpRequest(); >>> boolean isMultipart =3D ServletFileUpload.isMultipartContent=20= >>> (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"; >>> } >>> boolean empty =3D items.isEmpty(); >>> String valueOf =3D String.valueOf(empty); >>> >>> >>> return valueOf + "Works"; >>> } >>> } >>> >>> As I said, when I hit the submitButton nothing happens. >>> >>> Best regards >>> Benedikt >>> >>> >>> jalkanen@ecyrd.com schrieb: >>>> Hi! >>>> >>>> I think we might need to see the code. Can you post it to the =20 >>>> list, please? >>>> >>>> /janne >>>> >>>> -- alkuper. viesti -- >>>> Aihe: Re: Upload Question >>>> L=E4hett=E4j=E4: Benedikt Mohrmann >>>> P=E4iv=E4m=E4=E4r=E4: 11.10.2008 12:42 >>>> >>>> Hi, >>>> >>>> I did all this. >>>> The HTML output is how it should be, but the request is not =20 >>>> 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, =20 >>>>> rename the class, change the code, and then use [{MyFormOpen}] =20 >>>>> instead of [{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("
>>>> page=3DMyTest\" name=3D\"uploadForm\" accept-charset=3D\"UTF-8\" =20= >>>>> method=3D\"post\" enctype=3D\"multipart/form-data=20= >>>>> \">"); >>>>> returnStringBuffer.append(">>>> \"formname\" value=3D\"uploadForm\"/>"); >>>>> returnStringBuffer.append(">>>> type=3D\"file\">>>>> \"upload\" value=3D\"Hochladen\" />"); >>>>> >>>>> return returnStringBuffer.toString(); >>>>> } >>>>> } >>>>> >>>>> then use [{whatever.package.you.use.MyPlugin}] on a wikipage. =20 >>>>> 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 =20 >>>>>> file. >>>>>> Thus they are no real plugins I guess. >>>>>> I tried to change the FormOpen.java and inserted >>>>>> tag.append( "\" method=3D\""+method+"\" enctype=3D=20 >>>>>> \"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 =20 >>>>>> 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 =20 >>>>>> code the following way: >>>>>> returnStringBuffer.append("
"); >>>>>> returnStringBuffer.append(">>>>> page=3DMyTest\" name=3D\"uploadForm\" accept-charset=3D\"UTF-8\" =20= >>>>>> method=3D\"post\" enctype=3D\"multipart/form-data\">"); >>>>>> returnStringBuffer.append(">>>>> \"formname\" value=3D\"uploadForm\"/>"); >>>>>> returnStringBuffer.append(">>>>> type=3D\"file\">>>>>> \"upload\" value=3D\"Hochladen\" />"); >>>>>> >>>>>> Then just integrate the plugin into the WikiPage. >>>>>> >>>>>> And then put a second plugin via [{FormOutput =20 >>>>>> form=3D'uploadForm' handler=3D'MyPlugin'}] into the WikiPage? >>>>>> >>>>>> At the moment this seems not to work, as nothing happens when =20 >>>>>> I click on the submit button. >>>>>> >>>>>> Best regards >>>>>> Benedikt >>>>>> >>>>>> >>>>>> Janne Jalkanen schrieb: >>>>>> >>>>>>> Probably the quickest way for you now is to simply make a =20 >>>>>>> copy of the >>>>>>> relevant Form plugin, name it something else, and just change =20= >>>>>>> the >>>>>>> enctype. >>>>>>> >>>>>>> Also please put in a JIRA request for the enctype to be =20 >>>>>>> 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 =20 >>>>>>> wrote: >>>>>>> >>>>>>> >>>>>>>> Hi, >>>>>>>> >>>>>>>> just checked it again. >>>>>>>> The problem is definetely the form: >>>>>>>> org.apache.commons.fileupload.FileUploadBase=20 >>>>>>>> $InvalidContentTypeException: the request doesn't contain a =20 >>>>>>>> multipart/form-data or multipart/mixed stream, content type =20 >>>>>>>> header is 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+"\" enctype=3D\"application/=20= >>>>>>>> x-www-form-urlencoded\">\n" ); >>>>>>>> >>>>>>>> Can't I just change this? >>>>>>>> >>>>>>>> Another way could be to write a plugin with the following =20 >>>>>>>> code (snippet): >>>>>>>> returnStringBuffer.append("
"); >>>>>>>> returnStringBuffer.append(">>>>>>> page=3DMyTest\" name=3D\"uploadForm\" accept-charset=3D\"UTF-8\" = =20 >>>>>>>> method=3D\"post\" enctype=3D\"multipart/form-data\">"); >>>>>>>> returnStringBuffer.append(">>>>>>> name=3D\"formname\" value=3D\"uploadForm\"/>"); >>>>>>>> returnStringBuffer.append(">>>>>>> type=3D\"file\">>>>>>>> \"upload\" value=3D\"Hochladen\" />"); >>>>>>>> returnStringBuffer.append("
"); >>>>>>>> >>>>>>>> This would create a form, but how can I tell the Wiki which =20 >>>>>>>> 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 =20= >>>>>>>>> trace would be important, yes. There could be many things =20 >>>>>>>>> failing. >>>>>>>>> >>>>>>>>> /Janne >>>>>>>>> >>>>>>>>> On Oct 9, 2008, at 19:15 , Harry Metske wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> I think so too (multipart/form-data), but can you print =20 >>>>>>>>>> the 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 =20 >>>>>>>>>> be 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 =20 >>>>>>>>>>> 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 =20 >>>>>>>>>>> really simple, just to >>>>>>>>>>> check if it works): >>>>>>>>>>> public class MyTest2 implements WikiPlugin { >>>>>>>>>>> >>>>>>>>>>> @Override >>>>>>>>>>> public String execute(WikiContext context, Map params) =20 >>>>>>>>>>> throws >>>>>>>>>>> PluginException { >>>>>>>>>>> HttpServletRequest request =3D =20 >>>>>>>>>>> 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=20 >>>>>>>>>>> (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 =20= >>>>>>>>>>> and hit the >>>>>>>>>>> submitbutton. >>>>>>>>>>> One problem could be that when I take a look at the =20 >>>>>>>>>>> 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 =20 >>>>>>>>>>>> it does have it : >>>>>>>>>>>> >>>>>>>>>>>> ........ >>>>>>>>>>>> /** >>>>>>>>>>>> * If the request did originate from a HTTP request, >>>>>>>>>>>> * then the HTTP request can be fetched here. =20 >>>>>>>>>>>> However, it the request >>>>>>>>>>>> * did NOT originate from a HTTP request, then this =20 >>>>>>>>>>>> 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 =20= >>>>>>>>>>>> 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 =20 >>>>>>>>>>>>> be resolved. >>>>>>>>>>>>> >>>>>>>>>>>>> In addition I am implementing my plugin in Eclipse and =20 >>>>>>>>>>>>> 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 =20 >>>>>>>>>>>>>> HttpServletRequest ( >>>>>>>>>>>>>> HttpServletRequest request =3D context.getHttpRequest=20 >>>>>>>>>>>>>> (); ) . >>>>>>>>>>>>>> Once you have this, I think you can use many samples/=20 >>>>>>>>>>>>>> tools to handle the >>>>>>>>>>>>>> uploaded file, but maybe the best one is commons =20 >>>>>>>>>>>>>> fileupload ( >>>>>>>>>>>>>> http://commons.apache.org/fileupload/using.html), this =20= >>>>>>>>>>>>>> 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 =20= >>>>>>>>>>>>>>> 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 =20 >>>>>>>>>>>>>>> the server and then >>>>>>>>>>>>>>> handled by a plugin I wrote. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> The plugin just puts the file as a Serializable into =20 >>>>>>>>>>>>>>> a database (which >>>>>>>>>>>>>>> already works, when I read a file from my harddisk). >>>>>>>>>>>>>>> But I am not yet not able to transfer the content of =20 >>>>>>>>>>>>>>> the file as a >>>>>>>>>>>>>>> stream >>>>>>>>>>>>>>> or something like that. >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Any experiences how this could work? >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Best regards >>>>>>>>>>>>>>> Benedikt >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> >>>> >>