use of org.mule.runtime.http.api.HttpConstants.Method.GET in project mule by mulesoft.
the class ReflectiveHttpConfigBasedRequester method getHttpHeaders.
/**
* Reflectively introspects the result to find the HTTP Headers.
*
* @param result the {@link Result} returned by the http request operation
*/
private Map<String, String> getHttpHeaders(Result<Object, Object> result) {
try {
Optional httpAttributes = result.getAttributes();
if (!httpAttributes.isPresent()) {
throw new IllegalStateException("No Http Attributes found on the response, cannot get response headers.");
}
Object headers = httpAttributes.get().getClass().getMethod("getHeaders").invoke(httpAttributes.get());
Map<String, List<String>> map = (Map<String, List<String>>) headers.getClass().getMethod("toListValuesMap").invoke(headers);
return map.entrySet().stream().collect(toMap(e -> e.getKey(), e -> e.getValue().stream().collect(joining(" "))));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException("Something went wrong when introspecting the http response attributes.", e);
}
}
Aggregations