Created
January 31, 2016 02:36
-
-
Save ctoestreich/0d690dd88cd0c223900d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.grails.demo | |
| import grails.plugins.rest.client.RestBuilder | |
| import grails.plugins.rest.client.RestResponse | |
| import org.springframework.http.HttpStatus | |
| class ExternalRestBuilderService { | |
| void invokeRestBuilderPostWithUrl(String url) { | |
| if (url) { | |
| try { | |
| def rest = new RestBuilder() | |
| RestResponse response = rest.post(url) { | |
| header 'Cookie', "TEST=test" | |
| header 'X-DEBUG', "true" | |
| contentType "application/json" | |
| } | |
| if (response.statusCode != HttpStatus.OK) { | |
| log.error("Error calling post, response code: ${response.statusCode}") | |
| } | |
| } catch (Exception e) { | |
| log.error("Exception", e) | |
| } | |
| } | |
| } | |
| void invokeRestBuilderGetWithUrl(String url) { | |
| if (url) { | |
| try { | |
| def rest = new RestBuilder() | |
| RestResponse response = rest.get(url) { | |
| header 'Cookie', "TEST=test2" | |
| header 'X-DEBUG', "false" | |
| contentType "application/json" | |
| } | |
| if (response.statusCode != HttpStatus.OK) { | |
| log.error("Error calling post, response code: ${response.statusCode}") | |
| } | |
| } catch (Exception e) { | |
| log.error("Exception", e) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment