java - 415 Unsupported Media Error in PUT method using REST -


firstly new development , have started working directly rest. may stupid ask silly questions. please accept apologies in advance!

regarding problem - trying learn how rest api webservices can developed started mavan project using archetype - "jersey-quickstart-webapp" , using chrome postman rest client. successful in writing methods getting struck while writing put. every time 2 things - a) runtime exception 404 error or b) 415 error media unsupported.

i have tried different combinations @consumes annotation , method parameters @formparam, @queryparam no luck. neither successful in reading value sent via put application postman nor able send simple response postman. please suggest , drive me path can overcome these small hurdles.

my code -

package tcs.suraj.learnwebservices;  import java.util.arraylist;  import javax.ws.rs.*; import javax.ws.rs.core.mediatype; import javax.ws.rs.core.response; import tcs.suraj.learnwebservices.domain.moviebean;  @path("/movies") public class movies {      static arraylist<moviebean> movielist = new arraylist<moviebean>() ;      @get     @produces(mediatype.text_plain)     public string getmovie(){         system.out.println("under construction");             return "under construction";     }      @put     @consumes("application/x-www-form-urlencoded")     @produces(mediatype.text_plain)     public string updatemovie(@formparam("name") string name){         response r ;         system.out.println(name +" updated!");         return name;     } } 

i assuming using tomcat deployment, add web.xml , try again.

<filter>         <filter-name>corsfilter</filter-name>         <filter-class>org.apache.catalina.filters.corsfilter</filter-class>          <init-param>             <param-name>cors.allowed.methods</param-name>             <param-value>get,post,head,options,put,delete</param-value>         </init-param> </filter> <filter-mapping>     <filter-name>corsfilter</filter-name>     <url-pattern>/*</url-pattern> </filter-mapping> 

note: have used org.apache.catalina.filters.corsfilter in tomcat 7.0.53. not sure least version supported corsfilter.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -