Skip to content

Instantly share code, notes, and snippets.

@ctoestreich
Created January 31, 2016 02:36
Show Gist options
  • Save ctoestreich/0d690dd88cd0c223900d to your computer and use it in GitHub Desktop.
Save ctoestreich/0d690dd88cd0c223900d to your computer and use it in GitHub Desktop.
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