1

I am trying to convert some old style Groovy HttpBuilder code to HttpBuilder-NG. One thing I had to do in old style was to add request interceptor to handle the basic authorization. This is how I did it in the old HttpBuilder

def http = new RESTClient(url)
    http.client.addRequestInterceptor(new HttpRequestInterceptor() {
        void process(HttpRequest httpRequest, HttpContext httpContext) {
            log.debug("Request intercepted, adding authorization")
            httpRequest.addHeader('Authorization','Basic ' + "${username}:${password}".bytes.encodeBase64().toString())
        }
    })
    return http

How should it be done in HttpBuilder-NG? (and yes I've been reading the User Guide).

Updated 16/May/2017

I ask because using the ApacheHttpBuilder it get this in the log.

DEBUG - Authentication required
DEBUG - gpdevjira.broadinstitute.org:8443 requested authentication
DEBUG - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
DEBUG - Challenge for Negotiate authentication scheme not available
DEBUG - Challenge for Kerberos authentication scheme not available
DEBUG - Challenge for NTLM authentication scheme not available
DEBUG - Challenge for Digest authentication scheme not available
DEBUG - Challenge for Basic authentication scheme not available

I was able to use the old HttpBuilder with the request interceptor to handle the Basic authentication.

Erik Husby
  • 21
  • 3
  • You shouldn't need the interceptor in the BAG version. Just use the built-in basic authentication support. https://http-builder-ng.github.io/http-builder-ng/asciidoc/html5/#_authentication – cjstehno May 13 '17 at 15:55
  • That should be NG version not BAG version. Auto-correct! – cjstehno May 13 '17 at 16:08

1 Answers1

0

If you are here due to JIRA is mis-behavior. What claimed in document does not work - not due to client library problem, but JIRA has some special behavior.

Following code works

   def builder = HttpBuilder.configure {
            request.uri = 'http://ies-iesd-jira.ies.mentorg.com:8080'
            request.contentType = 'application/json'
           // request.auth.digest("user","password", true) -->does not work with JIRA
            request.headers['Authorization'] = 'Basic ' + 'user:password'.bytes.encodeBase64()
        }
Jayan
  • 18,003
  • 15
  • 89
  • 143