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ähettäjä: Benedikt Mohrmann <[EMAIL PROTECTED]>
Päivämäärä: 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='uploadForm'}]
[{MyFormOpen form='uploadForm'}]
[{FormInput type='file' name='uploadInput'}]
[{FormInput type='submit' name='uploadFile' value='Upload'}]
[{FormOutput form='uploadForm' handler='MyPlugin'}]
[{FormClose}]
To test it I wrote a plugin which justs returns "Works".
Now when I switch to the normal FormOpen tag ([{FormOpen
form='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
> [{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("<div class=\"wikiform\">");
> returnStringBuffer.append("<form
> action=\"Wiki.jsp?page=MyTest\" name=\"uploadForm\"
> accept-charset=\"UTF-8\" method=\"post\"
> enctype=\"multipart/form-data\">");
> returnStringBuffer.append("<input type=\"hidden\"
> name=\"formname\" value=\"uploadForm\"/>");
> returnStringBuffer.append("<input name=\"nbf_Datei\"
> type=\"file\"><input type=\"submit\" name=\"nbf_upload\" id=\"upload\"
> value=\"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=\""+method+"\"
>> enctype=\"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("<div class=\"wikiform\">");
>> returnStringBuffer.append("<form
>> action=\"Wiki.jsp?page=MyTest\" name=\"uploadForm\"
>> accept-charset=\"UTF-8\" method=\"post\"
>> enctype=\"multipart/form-data\">");
>> returnStringBuffer.append("<input type=\"hidden\"
>> name=\"formname\" value=\"uploadForm\"/>");
>> returnStringBuffer.append("<input name=\"nbf_Datei\"
>> type=\"file\"><input type=\"submit\" name=\"nbf_upload\"
>> id=\"upload\" value=\"Hochladen\" />");
>>
>> Then just integrate the plugin into the WikiPage.
>>
>> And then put a second plugin via [{FormOutput form='uploadForm'
>> handler='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
>>>> multipart/mixed stream, content type 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=\""+method+"\"
>>>> enctype=\"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("<div class=\"wikiform\">");
>>>> returnStringBuffer.append("<form
>>>> action=\"Wiki.jsp?page=MyTest\" name=\"uploadForm\"
>>>> accept-charset=\"UTF-8\" method=\"post\"
>>>> enctype=\"multipart/form-data\">");
>>>> returnStringBuffer.append("<input type=\"hidden\"
>>>> name=\"formname\" value=\"uploadForm\"/>");
>>>> returnStringBuffer.append("<input name=\"nbz_Datei\"
>>>> type=\"file\"><input type=\"submit\" name=\"nbz_upload\"
>>>> id=\"upload\" value=\"Hochladen\" />");
>>>> returnStringBuffer.append("</form></div>");
>>>>
>>>> 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
>>>>>> 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
>>>>>> parameterizable
>>>>>> with the current value as the default.
>>>>>>
>>>>>>
>>>>>> regards,
>>>>>> Harry
>>>>>>
>>>>>>
>>>>>> 2008/10/9 Benedikt Mohrmann <[EMAIL PROTECTED]>
>>>>>>
>>>>>>
>>>>>>> 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='searchForm'}]
>>>>>>> [{FormOpen form='searchForm'}]
>>>>>>> [{FormInput type='file' name='searchInput'}]
>>>>>>>
>>>>>>> [{FormInput type='submit' name='submit' value='Submit'}]
>>>>>>> [{FormClose}]
>>>>>>> [{FormOutput form='searchForm' handler='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 = context.getHttpRequest();
>>>>>>> boolean isMultipart =
>>>>>>> ServletFileUpload.isMultipartContent(request);
>>>>>>> // Create a factory for disk-based file items
>>>>>>> FileItemFactory factory = new DiskFileItemFactory();
>>>>>>>
>>>>>>> // Create a new file upload handler
>>>>>>> ServletFileUpload upload = new ServletFileUpload(factory);
>>>>>>>
>>>>>>> // Parse the request
>>>>>>> List<FileItem> items = null;
>>>>>>> try {
>>>>>>> items = 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:
>>>>>>>
>>>>>>> <form action="Wiki.jsp?page=MyTest" name="searchForm"
>>>>>>> accept-charset="UTF-8" method="post"
>>>>>>> enctype="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
>>>>>>>> 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 <[EMAIL PROTECTED]>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> thanks for your answer- I already had a look at commons
>>>>>>>>> fileupload.
>>>>>>>>> But the problem is, when I use:
>>>>>>>>>
>>>>>>>>> HttpServletRequest request = context.getHttpRequest();
>>>>>>>>>
>>>>>>>>> JSPWiki tells me
>>>>>>>>>
>>>>>>>>> HttpServletRequest cannot be resolved to a type
>>>>>>>>> The type javax.servlet.http.HttpServletRequest cannot be
>>>>>>>>> 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 = 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 <[EMAIL PROTECTED]>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> 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
>>>>>>>>>>> containing a file
>>>>>>>>>>> chooser and a submitbutton.
>>>>>>>>>>> The goal is, that the input file is transferred to the
>>>>>>>>>>> server and then
>>>>>>>>>>> handled by a plugin I wrote.
>>>>>>>>>>>
>>>>>>>>>>> The plugin just puts the file as a Serializable into 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 the
>>>>>>>>>>> file as a
>>>>>>>>>>> stream
>>>>>>>>>>> or something like that.
>>>>>>>>>>>
>>>>>>>>>>> Any experiences how this could work?
>>>>>>>>>>>
>>>>>>>>>>> Best regards
>>>>>>>>>>> Benedikt
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>