0

I have grails plugin project, i need to convert it to webservice, so that my php code can make a request to newly created webservice.

In short, i need to expose my grails plugin project, so that my php based application can make request to that.

Is there any support to make a call from my php based application to grails plugin project.

Any idea is greatly appreciated.

Thanks.

Hardik Patel
  • 937
  • 3
  • 14
  • 39

2 Answers2

1

Plugins can be developed and tested standalone, but in order to use them it has to be installed in a host application.

AFAIU, you have a custom plugin which has some XYZ service which you want to expose as a webservice. In order to do so, you have to follow these steps:

  • Create a grails app. (Not a plugin)
  • Install your plugin in the app. (by defining the plugin in BuildConfig.groovy of the app)
  • One way to expose the service as a RESTful webservice is to follow @Saurabh's approach.
  • Alternative way is to expose the service class in plugin using cxf plugin inside your plugin. (Untested, but you can try if you can achieve what you need without using REST url mappings).

Motive is to create a deployable component (war, ear, jar) which could produce/expose your custom service as a webservice. You can achieve the same from a grails application than a grails plugin which is nothing but a packaged zip archive.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
0

You can try grails web services, for example; REST can be used and you can call your grails application through a url and can pass parameter to it through POST, GET and handle them on grails controller

you can call a URL and handle the url paramters on the URL mapping:

for example if you call your grails app through some URL: product/ then you will be able to handle the request on your grails app as:

"/product/$id"(controller: "product", parseRequest: true) {
            action = [GET: "show", PUT: "update", DELETE: "delete", POST: "save"]

and in your controller you can parse the request like:

if( request.method == "GET" ){
        println( "GET REQUEST RECEIVED" )
            <......Some Code........>
        render resultList as JSON
    }else if( request.method == "POST" ){
        println( "POST REQUEST RECEIVED" )
            <......Some Code........>
        render resultList as JSON
    }
        }

request and reponse can be handled in xml or JSON format, have a look at: http://grails.org/doc/2.2.1/guide/webServices.html#REST

Saurabh Dixit
  • 633
  • 4
  • 16