[Wicket-user] FileUpload problem
I've been using wicket 1.2.1 in my application but decided to upgrade to 1.2.3. Basically everything works except my FileUpload to a Jackrabbit-repository. My testcases for my DAO:s working against the jackrabbit repo still works but in my application any file larger than 10kb gets an exception inside Jackrabbit: Bad filedescriptor The only thing I can think of is that the handling of the FileUpload.getInputStream() has changed somehow. The code looks like this (parts omitted for clarity): Button uploadButton; //document. add(uploadButton = new Button(upload) { protected void onSubmit() { final FileUpload upload = fileUploadField.getFileUpload(); if (upload != null) { try { Document document = getDocument(); document.setName(upload.getClientFileName()); document.setFilename(upload.getClientFileName()); document.setMimeType(upload.getContentType()); document.setInputStream(upload.getInputStream()); document.setSize(upload.getSize()); System.out.println(document.getSize()); document.setContentIsNew(true); setDocument(document); } catch (Exception e) { throw new IllegalStateException(Unable to upload file, e); } } } }.setDefaultFormProcessing(false)); Button saveButton = new Button(save) { protected void onSubmit() { Document document = getDocument(); ... documentDAO.save(document); ... } } Inside documentDAO.save: ... Node resNode = null; try { resNode = node.getNode(jcr:content); } catch (PathNotFoundException e) { resNode = node.addNode(jcr:content, nt:resource); } if (document.isContentNew()) { resNode.setProperty(jcr:mimeType, document.getMimeType()); resNode.setProperty(jcr:encoding, document.getEncoding()); resNode.setProperty(jcr:data, document.getInputStream()); // resNode.setProperty(jcr:size, document.getSize()); resNode.setProperty(jcr:lastModified, document.getLastModified()); } The code fails on the jcr:data when accessing document.getInputStream() with: dao.jcr.DocumentException: error saving document node model at xxx.plan.dao.jcr.DocumentDAO.save(DocumentDAO.java:442) at xxx.plan.dao.jcr.DocumentDAO$$FastClassByCGLIB$$339cce88.invoke(generated) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) at wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:282) at se.curalia.plan.dao.jcr.DocumentDAO$$EnhancerByCGLIB$$d394039b.save(generated) at se.curalia.plan.web.page.document.EditDocumentPage$EditDocumentForm$3.onSubmit(EditDocumentPage.java:334) at wicket.markup.html.form.Form.delegateSubmit(Form.java:568) at wicket.markup.html.form.Form.onFormSubmitted(Form.java:313) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:163) at wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:74) at wicket.request.compound.DefaultEventProcessorStrategy.processEvents(DefaultEventProcessorStrategy.java:65) at wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEvents(AbstractCompoundRequestCycleProcessor.java:57) at wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:896) at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:929) at wicket.RequestCycle.step(RequestCycle.java:1010) at wicket.RequestCycle.steps(RequestCycle.java:1084) at wicket.RequestCycle.request(RequestCycle.java:454) at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:219) at wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:262) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at
Re: [Wicket-user] FileUpload problem
Sorry for the spam. I read the javadoc for fileupload and noticed in *bold* that the inputstream is closed between requestsdoh. Strange that it works for files under 10 kb though On 12/6/06, Mats Norén [EMAIL PROTECTED] wrote: I've been using wicket 1.2.1 in my application but decided to upgrade to 1.2.3. Basically everything works except my FileUpload to a Jackrabbit-repository. My testcases for my DAO:s working against the jackrabbit repo still works but in my application any file larger than 10kb gets an exception inside Jackrabbit: Bad filedescriptor The only thing I can think of is that the handling of the FileUpload.getInputStream() has changed somehow. The code looks like this (parts omitted for clarity): Button uploadButton; //document. add(uploadButton = new Button(upload) { protected void onSubmit() { final FileUpload upload = fileUploadField.getFileUpload(); if (upload != null) { try { Document document = getDocument(); document.setName(upload.getClientFileName()); document.setFilename(upload.getClientFileName()); document.setMimeType(upload.getContentType()); document.setInputStream(upload.getInputStream()); document.setSize(upload.getSize()); System.out.println(document.getSize()); document.setContentIsNew(true); setDocument(document); } catch (Exception e) { throw new IllegalStateException(Unable to upload file, e); } } } }.setDefaultFormProcessing(false)); Button saveButton = new Button(save) { protected void onSubmit() { Document document = getDocument(); ... documentDAO.save(document); ... } } Inside documentDAO.save: ... Node resNode = null; try { resNode = node.getNode(jcr:content); } catch (PathNotFoundException e) { resNode = node.addNode(jcr:content, nt:resource); } if (document.isContentNew()) { resNode.setProperty(jcr:mimeType, document.getMimeType()); resNode.setProperty(jcr:encoding, document.getEncoding()); resNode.setProperty(jcr:data, document.getInputStream()); // resNode.setProperty(jcr:size, document.getSize()); resNode.setProperty(jcr:lastModified, document.getLastModified()); } The code fails on the jcr:data when accessing document.getInputStream() with: dao.jcr.DocumentException: error saving document node model at xxx.plan.dao.jcr.DocumentDAO.save(DocumentDAO.java:442) at xxx.plan.dao.jcr.DocumentDAO$$FastClassByCGLIB$$339cce88.invoke(generated) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) at wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:282) at se.curalia.plan.dao.jcr.DocumentDAO$$EnhancerByCGLIB$$d394039b.save(generated) at se.curalia.plan.web.page.document.EditDocumentPage$EditDocumentForm$3.onSubmit(EditDocumentPage.java:334) at wicket.markup.html.form.Form.delegateSubmit(Form.java:568) at wicket.markup.html.form.Form.onFormSubmitted(Form.java:313) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:163) at wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:74) at wicket.request.compound.DefaultEventProcessorStrategy.processEvents(DefaultEventProcessorStrategy.java:65) at wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEvents(AbstractCompoundRequestCycleProcessor.java:57) at wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:896) at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:929) at wicket.RequestCycle.step(RequestCycle.java:1010) at