Created
July 1, 2016 09:54
-
-
Save magnuspalmer/3d4e479fa1f28e3f3bf41c568de68058 to your computer and use it in GitHub Desktop.
How to replace default charset used by wslite responses
This file contains 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
@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