groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nibin Varghese <nibin...@gmail.com>
Subject Re: Groovy Jersey Rest POST call
Date Fri, 22 Jul 2016 22:37:14 GMT
Hi GP,

What is the error you are seeing at the backend ? Most probably you might
be getting an error due to the type adapters.

Can you try changing the signature to 'String params'.

*def* upload(@PathParam("mid") String mid, String params) {

//

}

May be it is failing because it is trying to convert to "object" type and
there might not be a type adapter with target as "Object" for the content
you are sending.

Do you have jersey-media moxy in the classpath[1] ?

PS: I am able to get jersey working with groovy (for GET and POST)

[1] https://jersey.java.net/documentation/latest/media.html

-Nibin

On Fri, Jul 22, 2016 at 2:55 PM, Gopalakrishnan P <gpuliyar@metricstream.com
> wrote:

> 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
>

Mime
View raw message