We use this library to create the Authorization headers for our SOAP requests. However I was finding that if I want to add additional headers they were being overwritten by the library.
I was able to resolve this by changing oauth.signpost.basic.SoapURLCOnnectionRequestAdapter::setHeader() as follows:
FROM:
@Override
public void setHeader(String name, String value) {
Map<String, List<String>> headers = new HashMap<>();
headers.put(name, Collections.singletonList(value));
this.connection.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
}
TO:
@Override
public void setHeader(String name, String value) {
// Ensure that any existing headers are not trashed, but retained
Map<String, List<String>> headers = (Map<String, List<String>>) this.connection.get(MessageContext.HTTP_REQUEST_HEADERS);
if (headers == null) {
headers = new HashMap<String, List<String>>();
}
headers.put(name, Collections.singletonList(value));
this.connection.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
}
This may help others, and maybe a better flow in the setHeader() function?
Additionally, the interface method oauth.signpost.http.HttpRequest::getAllHeaders() is typed incorrectly, the return value ought to be:
Map<String, List<String>>
rather than
(makes inserting headers back into the request impossible due to the underlying cast from String to List<String>
Thanks otherwise for a great simple library that does what it says on the tin!