java - Cannot Upload a file using Jax-RS -


i want use jersey framework. i´m running web service, using ant app, on java ee7. application server glassfish

my method this:

 package mypackage.service;         ...          import org.glassfish.jersey.media.multipart.formdatacontentdisposition;         import org.glassfish.jersey.media.multipart.formdataparam;          @post         @path("createsomething")         @consumes(multipart_form_data)         @produces(application_xml)         public response createsomething(@formdataparam("upload") inputstream is, @formdataparam("upload") formdatacontentdisposition formdata, @queryparam("some") string some,  @context httpservletrequest request) {              string filelocation = "c:\\uploadfile\\" + formdata.getfilename();          //more things, not matter              try {                 ctrl.savefile(is, filelocation);                 string result = "successfully file uploaded on path " + filelocation;                 return response.status(response.status.ok).entity(result).build();             } catch (ioexception e) {                 e.printstacktrace();                 return response.status(response.status.internal_server_error).build();              } 

i have application config:

package mypackage.service;  import java.util.hashset; import java.util.set; import javax.ws.rs.core.application; import org.glassfish.jersey.media.multipart.multipartfeature;  @javax.ws.rs.applicationpath("") public class applicationconfig extends application {      @override     public set<class<?>> getclasses() {         final set<class<?>> resources = new hashset<>();         addrestresourceclasses(resources);         resources.add(multipartfeature.class);          return resources;      }      /**      * not modify addrestresourceclasses() method. automatically      * populated resources defined in project. if required, comment      * out calling method in getclasses().      */     private void addrestresourceclasses(set<class<?>> resources) {         resources.add(mypackage.service.myservice.class);       }  } 

on myweb.xml have:

<servlet>     <servlet-name>servletadaptor</servlet-name>     <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>     <init-param>         <param-name>javax.ws.rs.application</param-name>         <param-value>mypackage.service.applicationconfig</param-value>     </init-param>     <init-param>         <param-name>jersey.config.server.provider.packages</param-name>         <param-value>mypackage.service</param-value>     </init-param>     <init-param>         <param-name>jersey.config.server.provider.classnames</param-name>         <param-value>org.glassfish.jersey.filter.loggingfilter;org.glassfish.jersey.media.multipart.multipartfeature</param-value>     </init-param>      <load-on-startup>1</load-on-startup> </servlet>  <servlet-mapping>     <servlet-name>servletadaptor</servlet-name>     <url-pattern>/createsomething/*</url-pattern> </servlet-mapping> 

i still same message:

caused by: org.apache.catalina.lifecycleexception: org.glassfish.jersey.server.model.modelvalidationexception: validation of application resource model has failed during application initialization. [[fatal] no injection source found parameter of type public javax.ws.rs.core.response

what i´m doing wrong??

it works fine me. though rid of application subclass. not needed, , may cause conflict/confusion. xml sufficient configuration, rid of javax.ws.rs.application <init-param>. making multipart jars compile-time jars (meaning not built war - might conflict glassfish's version). don't work ant, i'm not sure how can that, know it's possible.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -