Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnuspalmer/3d4e479fa1f28e3f3bf41c568de68058 to your computer and use it in GitHub Desktop.
Save magnuspalmer/3d4e479fa1f28e3f3bf41c568de68058 to your computer and use it in GitHub Desktop.
How to replace default charset used by wslite responses
@Grapes(
[
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.2'),
]
)
import wslite.rest.*
import wslite.http.HTTP
String restEndpoint = "http://someurl"
String someId = "123"
def client = new RESTClient(restEndpoint)
def myResponse = getWithDefaultCharsetUTF8 {
client.get(path:"/someresource/$someId", accept: ContentType.XML)
}
def getWithDefaultCharsetUTF8(closure){
def c = closure.clone()
c.delegate = this
HTTP.metaClass.'static'.getDEFAULT_CHARSET = { -> 'UTF-8' }
def response = c()
HTTP.metaClass.'static'.getDEFAULT_CHARSET = { -> 'ISO-8859-1' }
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment