Hello Udo, thanks for the quick response. I go forward did some checks
and tests:
- application is running on Tomcat 6.0.18 with myfaces 1.2.8 and tobago
1.0.24 on a Windows7 x64 machine
- I moved the file-upload form from the popout to a normal form. Same
error so the popup is not responsible
- I checked my web.xml file for the filter configuration. It's there.
- I want to install the tobago-fileupload.jar but can't find it in the
tobago myfaces-tobago-1.0.28-dist.zip. Where can I find it?
- It's also not pretty clear for me where to place the <env-entry>
elements described in at
http://myfaces.apache.org/tobago/apidocs/org/apache/myfaces/tobago/fileupload/FileUploadFacesContextFactoryImpl.html
The file upload process works basically. What I do is to open the
filestream read the data to a buffer and then copy the buffer via a
setter function of a class to another buffer OR I set the size via the
setter, here I got the exception. Since I got the exception also setting
the size element it depends not directly to the buffer-copy operation.
Here is the snippset of the upload handling code. ticketAttachment an
instance of class org.apache.commons.fileupload.FileItem:
if (ticketAttachment.getSize() > 0 )
{
InputStream inStream;
OutputStream outStream;
// read Data to memory buffer
try {
inStream =
ticketAttachment.getInputStream();
} catch (IOException e) {
e.printStackTrace();
return null;
}
int fSize = (int) ticketAttachment.getSize();
byte [] buffer = new byte[fSize*2];
try {
int readbytes = 0;
readbytes = inStream.read(buffer, 0,
fSize);
inStream.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
try {
// create new TicketAttachment object
ticketAttachmentToAdd.setTicket(ticketToAdd);
ticketAttachmentToAdd.setCreated(new
Date());
ticketAttachmentToAdd.setFilename(ticketAttachment.getName());
ticketAttachmentToAdd.setSize(fSize);
// HERE THE EXCEPTION IS FIRED
ticketAttachmentToAdd.setData(buffer);
// IF I OUCOMMNET THE PRVIOUS Line it happens here
....
with the both lines setting size and data to my Attachment Hibernate
model class there is no problem.
The relevant part of the TicketAttachment class is:
public class TicketAttachment {
private Integer size;
private byte[] data;
public void setSize(Integer size) {
this.size = size;
}
public void setData(byte[] data) {
this.data = data;
}
The stacktrace looks like the following. See the read line there is an
Exception about a missing setter function. But the missed function is
not existing and calles from nowhere. Looks that there is some garbage
inside "|*Ljava/lang/Integer;)V at" *|Looks like a buffer overflow which
writes some garbage to the function call
|javax.faces.FacesException: Error calling action method of component
with id page:j_id_jsp_885078903_2:j_id_jsp_885078903_17 at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:127) at
org.apache.myfaces.tobago.component.UIViewRoot.broadcastForPhase(UIViewRoot.java:135)
at
org.apache.myfaces.tobago.component.UIViewRoot.processApplication(UIViewRoot.java:211)
at
org.apache.myfaces.tobago.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:30)
at
org.apache.myfaces.tobago.lifecycle.TobagoLifecycle.executePhase(TobagoLifecycle.java:101)
at
org.apache.myfaces.tobago.lifecycle.TobagoLifecycle.execute(TobagoLifecycle.java:75)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:178) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.myfaces.tobago.webapp.TobagoMultipartFormdataFilter.doFilter(TobagoMultipartFormdataFilter.java:127)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source) Caused by:
*javax.faces.el.EvaluationException: java.lang.NoSuchMethodError:
com.mycompany.model.TicketAttachment.setSize(Ljava/lang/Integer;)V at
*org.apache.myfaces.el.convert.MethodExpressionToMethodBinding.invoke(MethodExpressionToMethodBinding.java:79)
at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:57)
... 23 more Caused by: java.lang.NoSuchMethodError:
com.mycompany.model.TicketAttachment.setSize(Ljava/lang/Integer;)V at
com.mycompany.billing.BillingController.newTicket(BillingController.java:2622)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
org.apache.el.parser.AstValue.invoke(AstValue.java:172) at
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at
org.apache.myfaces.el.convert.MethodExpressionToMethodBinding.invoke(MethodExpressionToMethodBinding.java:75)
... 24 more |
Am 21.09.2010 13:42, schrieb Udo Schnurpfeil:
Hello Michael,
there are two options to use the fileupload, see
http://myfaces.apache.org/tobago/faq.html#tobagofileupload
The jar-option might be better than the filter-option.
You can find an example in the addressbook demo.
If you still have problems with the Java exceptions, please sent it,
with the Tobago version and the way you chose (jar or filter).
Regards,
Udo
An example you can find in the
Am 21.09.10 09:56, schrieb Michael Kakuschky:
Hello, I use a form in a popup to submit some data. It worked fine
until I add the tx:file component to the form.
If I submit the form with a file selected I receive the data but it
seems that it corrupts somehow the memory and I got some strange Java
exceptions about (existing) methods that can't be found.
If the file upload is supported can somebody give me a basic example
and maybe tell me which attributes have to be set and which maybe not?
KInd regards Michael