httpbuilder

Groovy HTTPBuilder Mocking the Client

老子叫甜甜 提交于 2019-12-06 01:14:10
This question is closely related to this question . The difference is that I'd like to follow the recommended approach of mocking the client. So, I have the following HTTPBuilder defined: protected readUrl() { def http = new HTTPBuilder("http://example.com") def status = http.request(Method.GET, ContentType.JSON) {req -> response.success = {resp, json -> result = json.toString() new Success<String>(result) } response.'401' = {resp -> final String errMsg = "Not Authorized" new Failed(Failable.Fail.ACCESS_DENIED, errMsg) } response.failure = {resp -> final String errMsg = "General failure ${resp

HTTPBuilder and MultipartEntity / multipart form-data in Groovy

我只是一个虾纸丫 提交于 2019-12-05 11:04:20
Trying to simulate a HTTP POST that needs to combine some INPUT/TEXT fields along with data from a file. It looks like I can have one or the other, but not both? In the snippet below, paramsToPost = [name: 'John', age:22] @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0') Boolean doHttpPost(String url, Map paramsToPost, String fileContent) { HTTPBuilder http = new HTTPBuilder(url) def resp = http.request(Method.POST ) { req -> MultipartEntity mpe = new MultipartEntity() mpe.addPart "foo", new StringBody(fileContent) req.entity = mpe // body =

How to install and use httpbuilder plugin in grails

我的未来我决定 提交于 2019-12-05 02:59:35
问题 How to install and use httpbuilder plugin in Grails? 回答1: There is the REST Client plugin: Installation: grails install-plugin rest Example: withHttp(uri: "http://www.google.com") { def html = get(path : '/search', query : [q:'Groovy']) assert html.HEAD.size() == 1 assert html.BODY.size() == 1 } 回答2: Adding httpbuilder 0.5.1 to your application dependencies will cause errors. In particular, you'll get an error something like this: java.lang.LinkageError: loader constraint violation: when

Groovy HttpBuilder - Get Body Of Failed Response

喜夏-厌秋 提交于 2019-12-04 09:29:35
问题 I am trying to use the Groovy HTTPBuilder to write an integration test that will verify a correct error message is returned in the body along with an HTTP 409 status message. However, I can't figure out how to actually access the body of the HTTP response in failure cases. http.request(ENV_URL, Method.POST, ContentType.TEXT) { uri.path = "/curate/${id}/submit" contentType = ContentType.JSON response.failure = { failresp_inner -> failresp = failresp_inner } } then: assert failresp.status ==

Grails:Groovy:SSLPeerUnverifiedException: peer not authenticated

别等时光非礼了梦想. 提交于 2019-12-04 03:19:01
问题 I want to hit an xml request to a url while running the code in my local system it is working well i have created a war file and deployed the same in server,but while running in server getting an exception 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' i have used groovy http builder def http = new HTTPBuilder(url) http.auth.basic('username', 'password') try { http.request(Method.POST, ContentType.TEXT) { req-> headers.accept = "application/xml" body = request //xml

Cannot install HTTPBuilder

孤人 提交于 2019-12-04 01:36:34
问题 I'm trying to install HTTPBuilder like this: @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.2') However, I'm getting this error: java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-lang#commons-lang;2.4!commons-lang.jar] $ grape -V resolve org.codehaus.groovy.modules.http-builder http-builder 0.7.2 :: loading settings :: url = jar:file:/home/zoran/.gvm/groovy/2.4.4/lib/ivy-2.4.0.jar!/org/apache/ivy/core/settings

How to install and use httpbuilder plugin in grails

 ̄綄美尐妖づ 提交于 2019-12-03 20:07:48
How to install and use httpbuilder plugin in Grails? There is the REST Client plugin : Installation: grails install-plugin rest Example: withHttp(uri: "http://www.google.com") { def html = get(path : '/search', query : [q:'Groovy']) assert html.HEAD.size() == 1 assert html.BODY.size() == 1 } Adding httpbuilder 0.5.1 to your application dependencies will cause errors. In particular, you'll get an error something like this: java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.xerces.jaxp.SAXParserImpl.getParser()Lorg/xml/sax/Parser;" the class loader

using groovy http-builder in preemptive mode

走远了吗. 提交于 2019-12-03 07:48:30
问题 When using groovy's http-builder with basic authentication the default behavior is to send an unauthenticated request first and resend the request with credentials after receiving a 401 in the first place. Apache's Httpclient offers preemptive authentication to send the credentials directly on the first request. How can I use preemptive auth in Groovy's http-builder? Any code examples are appreciated. 回答1: Based on a JIRA issue you can do something like that : def http = new RESTClient('http:

Posting JSON data with Groovy's HTTPBuilder

ぐ巨炮叔叔 提交于 2019-12-03 07:22:22
问题 I've found this doc on how to post JSON data using HttpBuilder. I'm new to this, but it is very straightforward example and easy to follow. Here is the code, assuming I had imported all required dependencies. def http = new HTTPBuilder( 'http://example.com/handler.php' ) http.request( POST, JSON ) { req -> body = [name:'bob', title:'construction worker'] response.success = { resp, json -> // response handling here } } Now my problem is, I'm getting an exception of java.lang

using groovy http-builder in preemptive mode

不想你离开。 提交于 2019-12-02 20:31:25
When using groovy's http-builder with basic authentication the default behavior is to send an unauthenticated request first and resend the request with credentials after receiving a 401 in the first place. Apache's Httpclient offers preemptive authentication to send the credentials directly on the first request. How can I use preemptive auth in Groovy's http-builder? Any code examples are appreciated. Based on a JIRA issue you can do something like that : def http = new RESTClient('http://awesomeUrl/') http.client.addRequestInterceptor(new HttpRequestInterceptor() { void process(HttpRequest