Dropwizard and jQuery ajax post json gives either 204 or 415 -


I am trying to find a solution that how to send json data to the dropwizard server with jQuery, but it seems mission Impossible.

My Dod Wizard resource looks like this:

  Package resources; Import java.util.Arrays; Import java.util.list; Import javax.validation.Valid; Import javax.ws.rs.Consumes; Import javax.ws.rs.GET; Import javax.ws.rs.POST; Import javax.ws.rs.Path; Import javax.ws.rs.produces; Import javax.ws.rs.core.MediaType; Import javax.ws.rs.core.Response; Import model Blog; Import com.yammer.metrics.annotation.Timed; Import Configuration Simple API configuration; @ Path ("/") @ product (mediatip.appleisation_jsn) public class index resource (personal finals simple API configuration conf; public index resource (simple API configuration conferens) {this.conf = conf; blog B = new blog ("day 12: OpenCV - face recognition for Java developers "," https://www.openshift.com/blogs/day-12-opencv-face-detection-for-java-developers "); conf.addBlog (b); } @GET @ product (value = mediaTip.appleisation_JSOn) @Timede Public List & lt; Log & gt; Index () {List & lt; Blog & gt; L = conf.getBlogs (); Return L;} @ POST @ Timed Public Response Adblog (@Walig Blog Blog) {conf.addBlog (blog); Return Response.ok (). Build ();}}  

Update: and my HTML + jQuery looks like this:

  & lt; html & gt; & lt; top & gt; & lt; script type = "text / javascript" src = "http://code.jquery.com/jquery-1.11.1.min.js "& Gt; & lt; / script & gt; & lt; script type =" text / javascript "& gt; Function sendBlogs () {var blogInfo = JSON.stringify ({title: "good blog", url: "http://nice.blog.com/1"}); Var url = "http: // localhost: 8080 /"; $ AJAX ({url: url, type: "post", data: bloginfo, content type: "app / jason; charset = utf-8", data type: "jason", success: function (data, textstats, jxaxhr) { Alert (data);}}); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Button onClick = "sendBlogs ()" & gt; Post it & lt; / Button & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

If I extract the ContentType line from Ajax POST, I get a 415 error message I and if it is, then I get 204 (there is no content).

< P> If I use the curl command from the terminal then everything is fine.

  curl -i -x post-H "content type: application / jason" -d "{" title ":" awesome blog "," url ":" http: // in fact Awesome / "} 'http: // localhost: 8080 /   

Can anyone help me?

HTML>

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -