Search in sources :

Example 1 with CustomRestHeaders

use of org.apache.qpid.server.model.CustomRestHeaders in project qpid-broker-j by apache.

the class AbstractServlet method getResponseHeaders.

private Map<String, Object> getResponseHeaders(final Object content) {
    Map<String, Object> headers = Collections.emptyMap();
    if (content instanceof CustomRestHeaders) {
        CustomRestHeaders customRestHeaders = (CustomRestHeaders) content;
        Map<RestContentHeader, Method> contentHeaderGetters = getContentHeaderMethods(customRestHeaders);
        if (contentHeaderGetters != null) {
            headers = new HashMap<>();
            for (Map.Entry<RestContentHeader, Method> entry : contentHeaderGetters.entrySet()) {
                final String headerName = entry.getKey().value();
                try {
                    final Object headerValue = entry.getValue().invoke(customRestHeaders);
                    if (headerValue != null) {
                        headers.put(headerName.toUpperCase(), headerValue);
                    }
                } catch (Exception e) {
                    LOGGER.warn("Unexpected exception whilst setting response header " + headerName, e);
                }
            }
        }
    }
    return headers;
}
Also used : CustomRestHeaders(org.apache.qpid.server.model.CustomRestHeaders) RestContentHeader(org.apache.qpid.server.model.RestContentHeader) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Method(java.lang.reflect.Method) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException)

Aggregations

IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ServletException (javax.servlet.ServletException)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 CustomRestHeaders (org.apache.qpid.server.model.CustomRestHeaders)1 RestContentHeader (org.apache.qpid.server.model.RestContentHeader)1 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)1