Search in sources :

Example 1 with GET

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);
    }
}
Also used : POST(org.mule.runtime.http.api.HttpConstants.Method.POST) DefaultOperationParametersBuilder(org.mule.runtime.extension.api.client.DefaultOperationParametersBuilder) CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) GET(org.mule.runtime.http.api.HttpConstants.Method.GET) Collectors.joining(java.util.stream.Collectors.joining) Result(org.mule.runtime.extension.api.runtime.operation.Result) DefaultOperationParameters.builder(org.mule.runtime.extension.api.client.DefaultOperationParameters.builder) InvocationTargetException(java.lang.reflect.InvocationTargetException) TypedValue(org.mule.runtime.api.metadata.TypedValue) List(java.util.List) Collectors.toMap(java.util.stream.Collectors.toMap) DispatchingException(org.mule.runtime.soap.api.exception.DispatchingException) Map(java.util.Map) MultiMap(org.mule.runtime.api.util.MultiMap) ExtensionsClient(org.mule.runtime.extension.api.client.ExtensionsClient) Optional(java.util.Optional) Pair(org.mule.runtime.api.util.Pair) INPUT_STREAM(org.mule.runtime.api.metadata.DataType.INPUT_STREAM) InputStream(java.io.InputStream) Optional(java.util.Optional) List(java.util.List) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) MultiMap(org.mule.runtime.api.util.MultiMap) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 INPUT_STREAM (org.mule.runtime.api.metadata.DataType.INPUT_STREAM)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)1 MultiMap (org.mule.runtime.api.util.MultiMap)1 Pair (org.mule.runtime.api.util.Pair)1 DefaultOperationParameters.builder (org.mule.runtime.extension.api.client.DefaultOperationParameters.builder)1 DefaultOperationParametersBuilder (org.mule.runtime.extension.api.client.DefaultOperationParametersBuilder)1 ExtensionsClient (org.mule.runtime.extension.api.client.ExtensionsClient)1 Result (org.mule.runtime.extension.api.runtime.operation.Result)1 GET (org.mule.runtime.http.api.HttpConstants.Method.GET)1 POST (org.mule.runtime.http.api.HttpConstants.Method.POST)1 DispatchingException (org.mule.runtime.soap.api.exception.DispatchingException)1