how to put try catch to an event method in order to customise the catch java -


i have created method handle uploading of files when using p:fileupload tag of primefaces:

public void handlefileupload(fileuploadevent event) throws ioexception {      facescontext.getcurrentinstance()         .getexternalcontext()         .getsessionmap().put("limage", event.getfile());         } 

but when testing code exception:

 grave: c:\tmp\upload_6d3af437_13dda559a63__8000_00000082.tmp (le fichier spécifié est introuvable) java.io.filenotfoundexception: c:\tmp\upload_6d3af437_13dda559a63__8000_00000082.tmp (le fichier spécifié est introuvable)     @ java.io.fileinputstream.open(native method)     @ java.io.fileinputstream.<init>(fileinputstream.java:120)     @ org.apache.commons.fileupload.disk.diskfileitem.readobject(diskfileitem.java:719)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ java.io.objectstreamclass.invokereadobject(objectstreamclass.java:974)     @ java.io.objectinputstream.readserialdata(objectinputstream.java:1848)     @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1752)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1328)     @ java.io.objectinputstream.defaultreadfields(objectinputstream.java:1946)     @ java.io.objectinputstream.readserialdata(objectinputstream.java:1870)     @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1752)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1328)     @ java.io.objectinputstream.defaultreadfields(objectinputstream.java:1946)     @ java.io.objectinputstream.readserialdata(objectinputstream.java:1870)     @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1752)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1328)     @ java.io.objectinputstream.readobject(objectinputstream.java:350)     @ java.util.hashmap.readobject(hashmap.java:1030)     @ sun.reflect.generatedmethodaccessor105.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ java.io.objectstreamclass.invokereadobject(objectstreamclass.java:974)     @ java.io.objectinputstream.readserialdata(objectinputstream.java:1848)     @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1752)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1328)     @ java.io.objectinputstream.defaultreadfields(objectinputstream.java:1946)     @ java.io.objectinputstream.readserialdata(objectinputstream.java:1870)     @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1752)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1328)     @ java.io.objectinputstream.readarray(objectinputstream.java:1666)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1322)     @ java.io.objectinputstream.readobject(objectinputstream.java:350)     @ java.util.hashmap.readobject(hashmap.java:1030)     @ sun.reflect.generatedmethodaccessor105.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ java.io.objectstreamclass.invokereadobject(objectstreamclass.java:974)     @ java.io.objectinputstream.readserialdata(objectinputstream.java:1848)     @ java.io.objectinputstream.readordinaryobject(objectinputstream.java:1752)     @ java.io.objectinputstream.readobject0(objectinputstream.java:1328)     @ java.io.objectinputstream.readobject(objectinputstream.java:350)     @ com.sun.faces.renderkit.clientsidestatehelper.dogetstate(clientsidestatehelper.java:255)     @ com.sun.faces.renderkit.clientsidestatehelper.getstate(clientsidestatehelper.java:198)     @ com.sun.faces.renderkit.responsestatemanagerimpl.getstate(responsestatemanagerimpl.java:100)     @ com.sun.faces.application.view.statemanagementstrategyimpl.restoreview(statemanagementstrategyimpl.java:227)     @ com.sun.faces.application.statemanagerimpl.restoreview(statemanagerimpl.java:188)     @ com.sun.faces.application.view.viewhandlingstrategy.restoreview(viewhandlingstrategy.java:123)     @ com.sun.faces.application.view.faceletviewhandlingstrategy.restoreview(faceletviewhandlingstrategy.java:453)     @ com.sun.faces.application.view.multiviewhandler.restoreview(multiviewhandler.java:148)     @ com.ocpsoft.pretty.faces.application.prettyviewhandler.restoreview(prettyviewhandler.java:109)     @ com.sun.faces.lifecycle.restoreviewphase.execute(restoreviewphase.java:192)     @ com.sun.faces.lifecycle.phase.dophase(phase.java:101)     @ com.sun.faces.lifecycle.restoreviewphase.dophase(restoreviewphase.java:116)     @ com.sun.faces.lifecycle.lifecycleimpl.execute(lifecycleimpl.java:118)     @ javax.faces.webapp.facesservlet.service(facesservlet.java:593)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)     @ org.primefaces.webapp.filter.fileuploadfilter.dofilter(fileuploadfilter.java:79)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)     @ com.ocpsoft.pretty.prettyfilter.dofilter(prettyfilter.java:126)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)     @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222)     @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123)     @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472)     @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171)     @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99)     @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:936)     @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118)     @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:407)     @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1004)     @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589)     @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:312)     @ java.util.concurrent.threadpoolexecutor$worker.runtask(threadpoolexecutor.java:886)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:908)     @ java.lang.thread.run(thread.java:662) 

in order track down exception, wrapped custom logic in try/catch block, handler in catch block should me determine when exception caught. catch not being called:

public void handlefileupload(fileuploadevent event) throws ioexception{     try {         facescontext.getcurrentinstance()            .getexternalcontext()            .getsessionmap().put("limage", event.getfile());     } catch(exception e) {         system.out.println("i in catch ");         e.printstacktrace();     }        } 

i think problem not in instructions, might occurring before instructions run. here ui code:

<p:fileupload   mode="advanced" auto="true"     fileuploadlistener="#{articlesmb.handlefileupload}"  /> 

how can fix error? thanks.

the getfile doesn't throw exception. code show puts file session map. exception thrown somewhere else file object used.

as see stacktrace - happens when session tries deserialized between requests. should store file somewhere else, because file deleted framework right after multipart http request completes.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -