Exception at server while uploading image file using jersey client -
i trying send image file server using jersey client. getting below error in server
from client application opening file stored in local driver , passing on using jersey client apis.
feb 06, 2016 7:38:09 org.jvnet.mimepull.tempfiles createtempfile severe: exception caught java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.jvnet.mimepull.tempfiles.createtempfile(tempfiles.java:139) @ org.jvnet.mimepull.memorydata.createnext(memorydata.java:96) @ org.jvnet.mimepull.chunk.createnext(chunk.java:64) @ org.jvnet.mimepull.datahead.addbody(datahead.java:87) @ org.jvnet.mimepull.mimepart.addbody(mimepart.java:231) @ org.jvnet.mimepull.mimemessage.makeprogress(mimemessage.java:240) @ org.jvnet.mimepull.mimemessage.parseall(mimemessage.java:181) @ org.jvnet.mimepull.mimemessage.getattachments(mimemessage.java:106) @ com.sun.jersey.multipart.impl.multipartreaderclientside.readmultipart (multipartreaderclientside.java:205) @ com.sun.jersey.multipart.impl.multipartreaderserverside.readmultipart (multipartreaderserverside.java:80) @ com.sun.jersey.multipart.impl.multipartreaderclientside.readfrom(mult ipartreaderclientside.java:158) @ com.sun.jersey.multipart.impl.multipartreaderclientside.readfrom(mult ipartreaderclientside.java:85) @ com.sun.jersey.spi.container.containerrequest.getentity(containerrequ est.java:490) @ com.sun.jersey.spi.container.containerrequest.getentity(containerrequ est.java:555) @ com.sun.jersey.multipart.impl.formdatamultipartdispatchprovider$formd atainjectablevaluesprovider.getinjectablevalues(formdatamultipartdispatchprovide r.java:122) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemeth oddispatchprovider$entityparamininvoker.getparams(abstractresourcemethoddispatch provider.java:153) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemeth oddispatchprovider$responseoutinvoker._dispatch(abstractresourcemethoddispatchpr ovider.java:203) @ com.sun.jersey.server.impl.model.method.dispatch.resourcejavamethoddi spatcher.dispatch(resourcejavamethoddispatcher.java:75) @ com.sun.jersey.server.impl.uri.rules.httpmethodrule.accept(httpmethod rule.java:302) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(rightha ndpathrule.java:147) @ com.sun.jersey.server.impl.uri.rules.resourceclassrule.accept(resourc eclassrule.java:108) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(rightha ndpathrule.java:147) @ com.sun.jersey.server.impl.uri.rules.rootresourceclassesrule.accept(r ootresourceclassesrule.java:84) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequ est(webapplicationimpl.java:1542) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequ est(webapplicationimpl.java:1473) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlereque st(webapplicationimpl.java:1419) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlereque st(webapplicationimpl.java:1409) @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponen t.java:409) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servlet container.java:558) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servlet container.java:733) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(appl icationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationf ilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52 ) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(appl icationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationf ilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrapperv alve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextv alve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authentica torbase.java:505) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.j ava:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.j ava:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java: 950) @ org.apache.catalina.core.standardenginevalve.invoke(standardengineval ve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.jav a:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp 11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process( abstractprotocol.java:620) @ org.apache.tomcat.util.net.aprendpoint$socketprocessor.dorun(aprendpo int.java:2476) @ org.apache.tomcat.util.net.aprendpoint$socketprocessor.run(aprendpoin t.java:2465) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskth read.java:61) @ java.lang.thread.run(unknown source) caused by: java.nio.file.nosuchfileexception: d:\personal\apache-tomcat-7.0.61\t emp\mime8685830544490166217.tmp @ sun.nio.fs.windowsexception.translatetoioexception(unknown source) @ sun.nio.fs.windowsexception.rethrowasioexception(unknown source) @ sun.nio.fs.windowsexception.rethrowasioexception(unknown source) @ sun.nio.fs.windowsfilesystemprovider.newbytechannel(unknown source) @ java.nio.file.files.newbytechannel(unknown source) @ java.nio.file.files.createfile(unknown source) @ java.nio.file.tempfilehelper.create(unknown source) @ java.nio.file.tempfilehelper.createtempfile(unknown source) @ java.nio.file.files.createtempfile(unknown source) ... 56 more feb 06, 2016 7:38:09 org.jvnet.mimepull.tempfiles createtempfile warning: error invoking java.nio api, temp file (path: null, prefix:mime, suffix :null) being created using old java.io api. java.io.ioexception: system cannot find path specified @ java.io.winntfilesystem.createfileexclusively(native method) @ java.io.file.createtempfile(unknown source) @ org.jvnet.mimepull.tempfiles.createtempfile(tempfiles.java:152) @ org.jvnet.mimepull.memorydata.createnext(memorydata.java:96) @ org.jvnet.mimepull.chunk.createnext(chunk.java:64) @ org.jvnet.mimepull.datahead.addbody(datahead.java:87) @ org.jvnet.mimepull.mimepart.addbody(mimepart.java:231) @ org.jvnet.mimepull.mimemessage.makeprogress(mimemessage.java:240) @ org.jvnet.mimepull.mimemessage.parseall(mimemessage.java:181) @ org.jvnet.mimepull.mimemessage.getattachments(mimemessage.java:106) @ com.sun.jersey.multipart.impl.multipartreaderclientside.readmultipart (multipartreaderclientside.java:205) @ com.sun.jersey.multipart.impl.multipartreaderserverside.readmultipart (multipartreaderserverside.java:80) @ com.sun.jersey.multipart.impl.multipartreaderclientside.readfrom(mult ipartreaderclientside.java:158) @ com.sun.jersey.multipart.impl.multipartreaderclientside.readfrom(mult ipartreaderclientside.java:85) @ com.sun.jersey.spi.container.containerrequest.getentity(containerrequ est.java:490) @ com.sun.jersey.spi.container.containerrequest.getentity(containerrequ est.java:555) @ com.sun.jersey.multipart.impl.formdatamultipartdispatchprovider$formd atainjectablevaluesprovider.getinjectablevalues(formdatamultipartdispatchprovide r.java:122) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemeth oddispatchprovider$entityparamininvoker.getparams(abstractresourcemethoddispatch provider.java:153) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemeth oddispatchprovider$responseoutinvoker._dispatch(abstractresourcemethoddispatchpr ovider.java:203) @ com.sun.jersey.server.impl.model.method.dispatch.resourcejavamethoddi spatcher.dispatch(resourcejavamethoddispatcher.java:75) @ com.sun.jersey.server.impl.uri.rules.httpmethodrule.accept(httpmethod rule.java:302) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(rightha ndpathrule.java:147) @ com.sun.jersey.server.impl.uri.rules.resourceclassrule.accept(resourc eclassrule.java:108) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(rightha ndpathrule.java:147) @ com.sun.jersey.server.impl.uri.rules.rootresourceclassesrule.accept(r ootresourceclassesrule.java:84) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequ est(webapplicationimpl.java:1542) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequ est(webapplicationimpl.java:1473) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlereque st(webapplicationimpl.java:1419) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlereque st(webapplicationimpl.java:1409) @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponen t.java:409) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servlet container.java:558) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servlet container.java:733) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(appl icationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationf ilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52 ) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(appl icationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationf ilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrapperv alve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextv alve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authentica torbase.java:505) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.j ava:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.j ava:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java: 950) @ org.apache.catalina.core.standardenginevalve.invoke(standardengineval ve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.jav a:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp 11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process( abstractprotocol.java:620) @ org.apache.tomcat.util.net.aprendpoint$socketprocessor.dorun(aprendpo int.java:2476) @ org.apache.tomcat.util.net.aprendpoint$socketprocessor.run(aprendpoin t.java:2465) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskth read.java:61) @ java.lang.thread.run(unknown source)
my server code:
@post @path("/image") @consumes(mediatype.multipart_form_data) @produces({mediatype.application_xml,mediatype.application_json}) public response uploadfile(@formdataparam("file") inputstream uploadedinputstream, @formdataparam("file") formdatacontentdisposition filedetail) { system.out.println("xxxxxxxxxxxxxxxxxxxxxx"); transactionhandler th = new transactionhandlerimpl(); boolean bol = th.savefiletodisk(uploadedinputstream,4545); if(bol){ return response.ok().build(); }else{ return response.nocontent().build(); } }
client call
public boolean uploadimage(long id){ fileinputstream fis = null; boolean returnval = false; clientconfig cc = new defaultclientconfig(); cc.getclasses().add(multipartwriter.class); client client = client.create(cc); webresource service = client.resource(util.getserveripaddress() + "/pos-1/rest"); file file = new file("\\myphotos\\images\\"+id + ".png"); formdatamultipart multipart = new formdatamultipart(); multipart.setmediatype(mediatype.multipart_form_data_type); multipart.bodypart(new filedatabodypart("file", file, mediatype.application_octet_stream_type)); clientresponse response = service.path("image").type(mediatype.multipart_form_data_type).post(clientresponse.class,multipart); if(response.getstatus() == 200){ returnval = true; } return returnval; }
from error:
java.nio.file.nosuchfileexception: d:\personal\apache-tomcat-7.0.61\t emp\mime8685830544490166217.tmp
the path d:\personal\apache-tomcat-7.0.61\temp not exist. create temp directory. should work.
faced same issue. , resolved through way mentioned above.
source: https://www.garysieling.com/blog
Comments
Post a Comment