In the previous post about consuming web services in Grails using RestBuilder grails plugin, I explained how to set up a call to the remote service provider. However, I have recently encountered an annoying error as reported on its GitHub repository. Although the bug had committed into the next releases, the commit has not included into the currently latest released version for Grails2.x. The developer might plan to have a release to this version we don’t know yet. Having said that, I want to leave here an example for the future reference.
Let’s resume the demo project introduced in How to consume Web services in Grails.
Opening the application at http://localhost:8181/rest-client-builder-demo/search, you won’t get any result and see an error page. That’s why we have this writing. It’s time to tackle that error based on suggestions from the reported issue on the plugin’s page. To fix the problem, adding the following snippet into the retrieveBioModelsAllCuratedModels method of SearchService:
String serverURL = "https://www.ebi.ac.uk/ebisearch/ws/rest" String queryLink = "biomodels_all?query=metabolism&format=json" String queryURL = serverURL + "/" + queryLink def proxy = null RestBuilder rest = new RestBuilder(connectTimeout: 10000, readTimeout: 100000, proxy: proxy) rest.restTemplate.messageConverters.removeAll { it.class.name == 'org.springframework.http.converter.json.GsonHttpMessageConverter' } def response = rest.get(queryURL) { accept("application/json") contentType("application/json;charset=UTF-8") }
Retrieving the search page again, you probably observe the following JSON objects.
{"models":[{"submitter":"Michael Schubert","format":"SBML","name":"Wajima2009_BloodCoagulation_aPTTtest","submissionDate":"2016-02-08T00:00:00Z","id":"BIOMD0000000338","lastModified":"2016-02-08T00:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000338"},{"submitter":"Alexander Ratushny","format":"SBML","name":"Ratushny2012_ASSURE_II","submissionDate":"2014-09-02T23:00:00Z","id":"BIOMD0000000421","lastModified":"2014-09-02T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000421"},{"submitter":"Mohammad Umer Sharif Shohan","format":"SBML","name":"Dubey2008 - Modeling the interaction between avascular cancerous cells and acquired immune response","submissionDate":"2019-12-10T00:00:00Z","id":"BIOMD0000000886","lastModified":"2019-12-10T00:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000886"},{"submitter":"Barbara Bravi","format":"SBML","name":"Baker2017 - The role of cytokines, MMPs and fibronectin fragments osteoarthritis","submissionDate":"2018-10-11T23:00:00Z","id":"BIOMD0000000927","lastModified":"2020-04-01T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000927"},{"submitter":"Lukas Endler","format":"SBML","name":"Alexander2010_Tcell_Regulation_Sys2","submissionDate":"2014-03-11T00:00:00Z","id":"BIOMD0000000290","lastModified":"2014-03-11T00:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000290"},{"submitter":"Matthieu MAIRE","format":"SBML","name":"Ferrel2011 - Autonomous biochemical oscillator in regulation of CDK1, Plk1, and APC in Xenopus Laevis cell cycle","submissionDate":"2018-09-04T23:00:00Z","id":"BIOMD0000000937","lastModified":"2020-04-26T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000937"},{"submitter":"Nicolas Le Novère","format":"SBML","name":"Curien2003_MetThr_synthesis","submissionDate":"2012-05-15T23:00:00Z","id":"BIOMD0000000068","lastModified":"2012-05-15T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000068"},{"submitter":"Ahmad Zyoud","format":"SBML","name":"Gerard2013 - Model 3 - Embryonic-type eukaryotic Cell Cycle regulation based on negative feedback between Cdk/cyclin and APC and competitive inhibition between Cdk/cyclin and securin for polyubiquitylation_1","submissionDate":"2020-04-26T23:00:00Z","id":"BIOMD0000000938","lastModified":"2020-04-26T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000938"},{"submitter":"Matthieu MAIRE","format":"SBML","name":"Iwamoto2010 - Cell cycle reponse to DNA damage","submissionDate":"2018-09-05T23:00:00Z","id":"BIOMD0000000939","lastModified":"2020-04-26T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000939"},{"submitter":"Joerg Schaber","format":"SBML","name":"Kollarovic2016 - Cell fate decision at G1-S transition","submissionDate":"2017-04-10T23:00:00Z","id":"BIOMD0000000632","lastModified":"2017-04-10T23:00:00Z","url":"https://www.ebi.ac.uk/biomodels/BIOMD0000000632"}],"queryParameters":{"sortDirection":"desc","offset":0,"numResults":10,"sortBy":"relevance"},"matches":941}
The JSON data could be accessed from the shared link: http://jsoneditoronline.org/#left=cloud.826ce393bb9142d8ba0188318bca4adb to view JSON objects in a prettier presentation.
To display JSON string in a much better view, I have recently added a view called curated which is accessed via the URL http://localhost:8181/rest-client-builder-demo/search/curated. If the index view displays a raw JSON string, the new representation lets you see the results in the table view. The page looks like the screenshot below.
Hopefully, this post offers some additional tips/tricks and/or insights into how to consume RESTful services with RestBuilder plugin. Happy coding!
All constructive comments are welcomed. If you are willing to contribute financial support for our website, please follow the instructions below.