smartystreets / smartystreets-java-sdk

The official client libraries for accessing SmartyStreets APIs from Java (and JRE-based languages)
https://smartystreets.com/docs/sdk/java
14 stars 18 forks source link

Authorization header throwing exceptions (withCustomHeaders) #5

Closed markovujo closed 6 years ago

markovujo commented 6 years ago

Thank you for including custom headers in the new 3.3.0 release.

I noticed an issue if I use the Authorization custom header(s) with this package:

val url = "api-gateway-test/smartystreets/street-address"
val customHeaders = new HashMap[String, String]()
val bearerToken = "test123" 
customHeaders.put("Authorization", s"Bearer ${bearerToken}")

val client = new ClientBuilder(credentials)
          .withCustomBaseUrl(url)
          .withCustomHeaders(customHeaders)
          .buildUsStreetApiClient()

val lookup = new Lookup();
lookup.setStreet("1600 Amphitheatre Pkwy");
lookup.setCity("Mountain View");
lookup.setState("CA");
batch.add(lookup);
client.send(batch);

Exception: java.lang.IllegalArgumentException: Can not set java.util.List field com.google.api.client.http.HttpHeaders.authorization to java.lang.String.

Any thoughts on how I would pass custom Authorization headers to the client?

Thanks for your time.

Marko Vujovic

MouaYing commented 6 years ago

@markovujo - For some reason the HTTP client we use under the hood wants the value of the Authorization header to be a List of Strings, not just a string.

It looks like our client builder's withCustomHeaders method took a Map<String, String>, so we have changed it to take a Map<String, Object>.

As of version 3.3.1, you should now be able to pass your Authorization header by wrapping the value in a List object.

markovujo commented 6 years ago

@MouaYing Thank you for the quick fix. Much appreciated.