java - Javax ClientBuilder post() removes file before sending to web service -
i'm trying send temporary file restful web service. i'm using following function this:
private static string nlpfileupload(string filepath) throws ioexception { // check file exists file file = new file(filepath); if(!file.isfile()) { throw new filenotfoundexception(); } // upload file web service return clientbuilder.newclient() .target(nlpresturl + "upload") .request() .post( entity.entity(file, mediatype.application_octet_stream) ).readentity(string.class); }
the problem is, in method .post()
file removed disk , filenotfound exception returned:
[error] [04/18/2016 19:04:35.945] [application-akka.actor.default-dispatcher-2] [taskinvocation] java.io.filenotfoundexception: /tmp/multipartbody3655134388737861177astemporaryfile (no such file or directory) javax.ws.rs.processingexception: java.io.filenotfoundexception: /tmp/multipartbody3655134388737861177astemporaryfile (no such file or directory) @ org.glassfish.jersey.client.internal.httpurlconnector.apply(httpurlconnector.java:287) @ org.glassfish.jersey.client.clientruntime.invoke(clientruntime.java:255) @ org.glassfish.jersey.client.jerseyinvocation$1.call(jerseyinvocation.java:684) @ org.glassfish.jersey.client.jerseyinvocation$1.call(jerseyinvocation.java:681) @ org.glassfish.jersey.internal.errors.process(errors.java:315) @ org.glassfish.jersey.internal.errors.process(errors.java:297) @ org.glassfish.jersey.internal.errors.process(errors.java:228) @ org.glassfish.jersey.process.internal.requestscope.runinscope(requestscope.java:444) @ org.glassfish.jersey.client.jerseyinvocation.invoke(jerseyinvocation.java:681) @ org.glassfish.jersey.client.jerseyinvocation$builder.method(jerseyinvocation.java:437) @ org.glassfish.jersey.client.jerseyinvocation$builder.post(jerseyinvocation.java:343) @ pl.edu.pwr.services.serel.serelservicers.nlpfileupload(serelservicers.java:97) @ pl.edu.pwr.services.serel.serelservicers.processfile(serelservicers.java:181) @ jobs.processdocuments.run(processdocuments.java:54) @ akka.dispatch.taskinvocation.run(abstractdispatcher.scala:41) @ akka.dispatch.forkjoinexecutorconfigurator$akkaforkjointask.exec(abstractdispatcher.scala:393) @ scala.concurrent.forkjoin.forkjointask.doexec(forkjointask.java:260) @ scala.concurrent.forkjoin.forkjoinpool$workqueue.runtask(forkjoinpool.java:1339) @ scala.concurrent.forkjoin.forkjoinpool.runworker(forkjoinpool.java:1979) @ scala.concurrent.forkjoin.forkjoinworkerthread.run(forkjoinworkerthread.java:107) caused by: java.io.filenotfoundexception: /tmp/multipartbody3655134388737861177astemporaryfile (no such file or directory) @ java.io.fileinputstream.open0(native method) @ java.io.fileinputstream.open(fileinputstream.java:195) @ java.io.fileinputstream.<init>(fileinputstream.java:138) @ org.glassfish.jersey.message.internal.fileprovider.writeto(fileprovider.java:115) @ org.glassfish.jersey.message.internal.fileprovider.writeto(fileprovider.java:67) @ org.glassfish.jersey.message.internal.writerinterceptorexecutor$terminalwriterinterceptor.invokewriteto(writerinterceptorexecutor.java:265) @ org.glassfish.jersey.message.internal.writerinterceptorexecutor$terminalwriterinterceptor.aroundwriteto(writerinterceptorexecutor.java:250) @ org.glassfish.jersey.message.internal.writerinterceptorexecutor.proceed(writerinterceptorexecutor.java:162) @ org.glassfish.jersey.message.internal.messagebodyfactory.writeto(messagebodyfactory.java:1130) @ org.glassfish.jersey.client.clientrequest.writeentity(clientrequest.java:502) @ org.glassfish.jersey.client.internal.httpurlconnector._apply(httpurlconnector.java:388) @ org.glassfish.jersey.client.internal.httpurlconnector.apply(httpurlconnector.java:285) ... 19 more
but exception not appears always. while debugging i've found out file sent service correctly, in other time above exception appears. don't know wrong here. service able read files mediatype.application_octet_stream
think problem on client side. why .post()
method removes file before sending web service?
i'm using play framework 2.3.9 in application. nlpfileupload(string filepath)
function called akka scheduler.
the problem play temporary files deleted when garbaged collected. temporary files created when file uploaded client , handled multipartformdata
. must why code works.
to solve this, can try keep reference file it's not cleaned garbage collector. can start changing definition of function use reference:
static string nlpfileupload(file file) throws ioexception
Comments
Post a Comment