eclipse - jax-rs GlassFish4 upload file -
good day
i use eclipseee luna,win7 32bit,java 8_45 , glassfish 4.1 as. create standard dynamic project without maven. want use web service jax-rs upload selected file defined folder. use example (http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/). when want upload(deploy) glassfish in eclipse show me error , project not load as. not know bad. have bad? or have forgot something?
cannot deploy java.rest02.glassfish4.htmlform deploy failing=application name [java.rest02.glassfish4.htmlform] not deployed
application :
package server; import java.util.*; import javax.ws.rs.*; import javax.ws.rs.core.*; import service3.fileupload.*; @applicationpath("server") public class server extends application { private final set<class<?>> classes; public server() { hashset<class<?>> c = new hashset<>(); c.add(restservice3.class); classes = collections.unmodifiableset(c); } public set<class<?>> getclasses() { return classes; } }
restservice :
package service3.fileupload; import java.io.*; import javax.ws.rs.*; import javax.ws.rs.core.*; import org.glassfish.jersey.media.multipart.formdatacontentdisposition; import org.glassfish.jersey.media.multipart.formdataparam; @path("service3") public class restservice3 { @get @path("test3") public string testmetodastring(){ system.out.println("vypis - 3"); return "test-vypis3"; } // not work - loading crash @post @path("upload") @consumes(mediatype.multipart_form_data) public response uploadfile( @formdataparam("file") inputstream uploadedinputstream, @formdataparam("file") formdatacontentdisposition filedetail) { string uploadedfilelocation = "d:\\download\\" + filedetail.getfilename(); writetofile(uploadedinputstream, uploadedfilelocation); string output = "soubor uložen : " + uploadedfilelocation; return response.status(200).entity(output).build(); } private void writetofile(inputstream uploadedinputstream,string uploadedfilelocation) { // save uploaded file new location try { outputstream out = new fileoutputstream(new file(uploadedfilelocation)); int read = 0; byte[] bytes = new byte[1024]; out = new fileoutputstream(new file(uploadedfilelocation)); while ((read = uploadedinputstream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); out.close(); } catch (ioexception e) { e.printstacktrace(); } } }
html page :
<html> <head> <meta charset="utf-8"> <title>webpage test</title> </head> <body> <h1>zde test upload souboru pres jax-rs :</h1><br> <form action="/server/service3/upload" method="post" enctype="multipart/form-data"> <p> select file : <input type="file" name="file" size="45""/></p> <input type="submit" value="nahraj soubor" /></form> </body> </html>
i use glassfish system library :
c:\program files\javaee\glassfish\modules\bean-validator.jar c:\program files\javaee\glassfish\modules\cdi-api.jar c:\program files\javaee\glassfish\modules\endorsed\javax.annotation-api.jar c:\program files\javaee\glassfish\modules\endorsed\jaxb-api.jar c:\program files\javaee\glassfish\modules\endorsed\webservices-api-osgi.jar c:\program files\javaee\glassfish\modules\glassfish-api.jar c:\program files\javaee\glassfish\modules\ha-api.jar c:\program files\javaee\glassfish\modules\javax.batch-api.jar c:\program files\javaee\glassfish\modules\javax.ejb-api.jar c:\program files\javaee\glassfish\modules\javax.el.jar c:\program files\javaee\glassfish\modules\javax.enterprise.concurrent-api.jar c:\program files\javaee\glassfish\modules\javax.enterprise.concurrent.jar c:\program files\javaee\glassfish\modules\javax.enterprise.deploy-api.jar c:\program files\javaee\glassfish\modules\javax.faces.jar c:\program files\javaee\glassfish\modules\javax.inject.jar c:\program files\javaee\glassfish\modules\javax.interceptor-api.jar c:\program files\javaee\glassfish\modules\javax.jms-api.jar c:\program files\javaee\glassfish\modules\javax.json.jar c:\program files\javaee\glassfish\modules\javax.mail.jar c:\program files\javaee\glassfish\modules\javax.management.j2ee-api.jar c:\program files\javaee\glassfish\modules\javax.persistence.jar c:\program files\javaee\glassfish\modules\javax.resource-api.jar c:\program files\javaee\glassfish\modules\javax.security.auth.message-api.jar c:\program files\javaee\glassfish\modules\javax.security.jacc-api.jar c:\program files\javaee\glassfish\modules\javax.servlet-api.jar c:\program files\javaee\glassfish\modules\javax.servlet.jsp-api.jar c:\program files\javaee\glassfish\modules\javax.servlet.jsp.jar c:\program files\javaee\glassfish\modules\javax.servlet.jsp.jstl-api.jar c:\program files\javaee\glassfish\modules\javax.servlet.jsp.jstl.jar c:\program files\javaee\glassfish\modules\javax.transaction-api.jar c:\program files\javaee\glassfish\modules\javax.websocket-api.jar c:\program files\javaee\glassfish\modules\javax.ws.rs-api.jar c:\program files\javaee\glassfish\modules\javax.xml.registry-api.jar c:\program files\javaee\glassfish\modules\javax.xml.rpc-api.jar c:\program files\javaee\glassfish\modules\jaxb-extra-osgi.jar c:\program files\javaee\glassfish\modules\jaxb-osgi.jar c:\program files\javaee\glassfish\modules\jersey-bean-validation.jar c:\program files\javaee\glassfish\modules\jersey-client.jar c:\program files\javaee\glassfish\modules\jersey-common.jar c:\program files\javaee\glassfish\modules\jersey-container-grizzly2-http.jar c:\program files\javaee\glassfish\modules\jersey-container-servlet-core.jar c:\program files\javaee\glassfish\modules\jersey-container-servlet.jar c:\program files\javaee\glassfish\modules\jersey-entity-filtering.jar c:\program files\javaee\glassfish\modules\jersey-gf-cdi.jar c:\program files\javaee\glassfish\modules\jersey-gf-ejb.jar c:\program files\javaee\glassfish\modules\jersey-guava.jar c:\program files\javaee\glassfish\modules\jersey-media-json-jackson.jar c:\program files\javaee\glassfish\modules\jersey-media-json-jettison.jar c:\program files\javaee\glassfish\modules\jersey-media-json-processing.jar c:\program files\javaee\glassfish\modules\jersey-media-moxy.jar c:\program files\javaee\glassfish\modules\jersey-media-multipart.jar c:\program files\javaee\glassfish\modules\jersey-media-sse.jar c:\program files\javaee\glassfish\modules\jersey-mvc-connector.jar c:\program files\javaee\glassfish\modules\jersey-mvc-jsp.jar c:\program files\javaee\glassfish\modules\jersey-mvc.jar c:\program files\javaee\glassfish\modules\jersey-server.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.antlr.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.asm.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.core.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.dbws.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.jpa.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.jpa.jpql.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.jpa.modelgen.processor.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.moxy.jar c:\program files\javaee\glassfish\modules\org.eclipse.persistence.oracle.jar c:\program files\javaee\glassfish\modules\webservices-connector.jar c:\program files\javaee\glassfish\modules\webservices-extra-jdk-packages.jar c:\program files\javaee\glassfish\modules\webservices-osgi.jar c:\program files\javaee\glassfish\modules\webservices.security.jar c:\program files\javaee\glassfish\modules\weld-osgi-bundle.jar c:\program files\javaee\mq\lib\jaxm-api.jar
logs glassfish4 glassfish\domains\domain1\logs\server.log
[2015-06-30t08:48:23.755+0200] [glassfish 4.1] [info] [ncls-logging-00009] [javax.enterprise.logging] [tid: _threadid=15 _threadname=runlevelcontrollerthread-1435646903303] [timemillis: 1435646903755] [levelvalue: 800] [[ running glassfish version: glassfish server open source edition 4.1 (build 13)]] [2015-06-30t08:48:23.755+0200] [glassfish 4.1] [info] [ncls-logging-00010] [javax.enterprise.logging] [tid: _threadid=15 _threadname=runlevelcontrollerthread-1435646903303] [timemillis: 1435646903755] [levelvalue: 800] [[ server log file using formatter class: com.sun.enterprise.server.logging.odllogformatter]] [2015-06-30t08:48:24.130+0200] [glassfish 4.1] [info] [ncls-security-01115] [javax.enterprise.system.core.security] [tid: _threadid=17 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646904130] [levelvalue: 800] [[ realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.filerealm] created.]] [2015-06-30t08:48:24.145+0200] [glassfish 4.1] [info] [ncls-security-01115] [javax.enterprise.system.core.security] [tid: _threadid=17 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646904145] [levelvalue: 800] [[ realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.filerealm] created.]] [2015-06-30t08:48:24.161+0200] [glassfish 4.1] [info] [ncls-security-01115] [javax.enterprise.system.core.security] [tid: _threadid=17 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646904161] [levelvalue: 800] [[ realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.certificaterealm] created.]] [2015-06-30t08:48:24.879+0200] [glassfish 4.1] [info] [] [org.glassfish.ha.store.spi.backingstorefactoryregistry] [tid: _threadid=16 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646904879] [levelvalue: 800] [[ registered org.glassfish.ha.store.adapter.cache.shoalbackingstoreproxy persistence-type = replicated in backingstorefactoryregistry]] [2015-06-30t08:48:24.894+0200] [glassfish 4.1] [info] [sec-svcs-00100] [javax.enterprise.security.services] [tid: _threadid=14 _threadname=runlevelcontrollerthread-1435646903287] [timemillis: 1435646904894] [levelvalue: 800] [[ authorization service has initialized.]] [2015-06-30t08:48:25.581+0200] [glassfish 4.1] [info] [ncls-core-00087] [javax.enterprise.system.core] [tid: _threadid=17 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646905581] [levelvalue: 800] [[ grizzly framework 2.3.15 started in: 406ms - bound [/0.0.0.0:8080]]] [2015-06-30t08:48:25.643+0200] [glassfish 4.1] [info] [ncls-core-00087] [javax.enterprise.system.core] [tid: _threadid=17 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646905643] [levelvalue: 800] [[ grizzly framework 2.3.15 started in: 0ms - bound [/0.0.0.0:8181]]] [2015-06-30t08:48:25.659+0200] [glassfish 4.1] [info] [ncls-core-00087] [javax.enterprise.system.core] [tid: _threadid=17 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646905659] [levelvalue: 800] [[ grizzly framework 2.3.15 started in: 0ms - bound [/0.0.0.0:4848]]] [2015-06-30t08:48:25.752+0200] [glassfish 4.1] [info] [ncls-core-00087] [javax.enterprise.system.core] [tid: _threadid=15 _threadname=runlevelcontrollerthread-1435646903303] [timemillis: 1435646905752] [levelvalue: 800] [[ grizzly framework 2.3.15 started in: 15ms - bound [/0.0.0.0:3700]]] [2015-06-30t08:48:25.752+0200] [glassfish 4.1] [info] [ncls-core-00017] [javax.enterprise.system.core] [tid: _threadid=1 _threadname=main] [timemillis: 1435646905752] [levelvalue: 800] [[ glassfish server open source edition 4.1 (13) startup time : felix (6 366ms), startup services(2 480ms), total(8 846ms)]] [2015-06-30t08:48:26.205+0200] [glassfish 4.1] [info] [ncls-core-00087] [javax.enterprise.system.core] [tid: _threadid=16 _threadname=runlevelcontrollerthread-1435646903334] [timemillis: 1435646906205] [levelvalue: 800] [[ grizzly framework 2.3.15 started in: 0ms - bound [/0.0.0.0:7676]]] [2015-06-30t08:48:26.361+0200] [glassfish 4.1] [info] [ncls-bootstrap-00027] [javax.enterprise.bootstrap] [tid: _threadid=1 _threadname=main] [timemillis: 1435646906361] [levelvalue: 800] [[ registered com.sun.enterprise.glassfish.bootstrap.osgi.embeddedosgiglassfishimpl@3ed581 osgi service registration: org.apache.felix.framework.serviceregistrationimpl@1967222.]] [2015-06-30t08:48:26.579+0200] [glassfish 4.1] [info] [ncls-jmx-00005] [javax.enterprise.system.jmx] [tid: _threadid=54 _threadname=thread-15] [timemillis: 1435646906579] [levelvalue: 800] [[ jmxstartupservice has started jmxconnector on jmxservice url service:jmx:rmi://ntbhp:8686/jndi/rmi://ntbhp:8686/jmxrmi]] [2015-06-30t08:48:28.105+0200] [glassfish 4.1] [info] [] [org.hibernate.validator.internal.util.version] [tid: _threadid=42 _threadname=admin-listener(2)] [timemillis: 1435646908105] [levelvalue: 800] [[ hv000001: hibernate validator 5.0.0.final]]
logs elipse console starting glasfish added project :
2015-06-30t09:19:00.539+0200|info: running glassfish version: glassfish server open source edition 4.1 (build 13) 2015-06-30t09:19:00.554+0200|info: server log file using formatter class: com.sun.enterprise.server.logging.odllogformatter 2015-06-30t09:19:01.054+0200|info: realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.filerealm] created. 2015-06-30t09:19:01.069+0200|info: realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.filerealm] created. 2015-06-30t09:19:01.085+0200|info: realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.certificaterealm] created. 2015-06-30t09:19:01.880+0200|info: authorization service has initialized. 2015-06-30t09:19:02.052+0200|info: registered org.glassfish.ha.store.adapter.cache.shoalbackingstoreproxy persistence-type = replicated in backingstorefactoryregistry 2015-06-30t09:19:02.723+0200|info: grizzly framework 2.3.15 started in: 421ms - bound [/0.0.0.0:8080] 2015-06-30t09:19:02.770+0200|info: grizzly framework 2.3.15 started in: 16ms - bound [/0.0.0.0:8181] 2015-06-30t09:19:02.770+0200|info: grizzly framework 2.3.15 started in: 0ms - bound [/0.0.0.0:4848] 2015-06-30t09:19:02.848+0200|info: grizzly framework 2.3.15 started in: 0ms - bound [/0.0.0.0:3700] 2015-06-30t09:19:02.848+0200|info: glassfish server open source edition 4.1 (13) startup time : felix (5�242ms), startup services(2�746ms), total(7�988ms) 2015-06-30t09:19:03.238+0200|info: grizzly framework 2.3.15 started in: 0ms - bound [/0.0.0.0:7676] 2015-06-30t09:19:03.472+0200|info: registered com.sun.enterprise.glassfish.bootstrap.osgi.embeddedosgiglassfishimpl@7dfd44 osgi service registration: org.apache.felix.framework.serviceregistrationimpl@2eea2a. 2015-06-30t09:19:03.768+0200|info: jmxstartupservice has started jmxconnector on jmxservice url service:jmx:rmi://ntbhp:8686/jndi/rmi://ntbhp:8686/jmxrmi 2015-06-30t09:19:05.827+0200|info: hv000001: hibernate validator 5.0.0.final
Comments
Post a Comment