Hi Everyone,

I'm new to Groovy. I'm using Groovy and Jersey Rest.

Below is the code:

import static javax.ws.rs.core.Response.Status.OK
import groovy.json.JsonSlurper

import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.core.Response

@Path("/test")
class RestApi {

       @POST
       @Consumes(["application/json", "text/x-json"])
       @Produces(["application/json", "text/x-json"])
       @Path("{mid}/test/upload-groovy-test")
       def upload(@PathParam("mid") String mid, params) {
             println "---------groovy --- "
             println params
             def slurpedTxt = new JsonSlurper().parseText(params)
             println slurpedTxt
             Response.status(OK).build()
       }

       @GET
       @Produces(["application/json", "text/x-json"])
       def show() {
             "groovy response"
       }
}

GET Rest API is working fine when tested. Whereas POST doesn't work. I get 
error code 415, unsupported media type.
What am I missing? Do I need to do any additional configuration?
I did enough googling on this but in vain. Anyone has tried Groovy/Jersey Rest 
POST calls. Any examples that you can share for me to try.

Regards
GP



Confidentiality Notice:This email and any files transmitted with it are 
confidential and intended solely for the use of the individual or entity to 
whom they are addressed. This message contains confidential information and is 
intended only for the individual named. If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail. Please notify the 
sender immediately by e-mail if you have received this e-mail by mistake and 
delete this e-mail from your system. If you are not the intended recipient you 
are notified that disclosing, copying, distributing or taking any action in 
reliance on the contents of this information is strictly prohibited

Reply via email to