use of org.apache.qpid.server.model.RestContentHeader 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;
}
use of org.apache.qpid.server.model.RestContentHeader in project qpid-broker-j by apache.
the class AbstractServlet method getContentHeaderMethods.
private Map<RestContentHeader, Method> getContentHeaderMethods(CustomRestHeaders content) {
Map<RestContentHeader, Method> results = new HashMap<>();
Method[] methods = content.getClass().getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(RestContentHeader.class)) {
final Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length > 0) {
LOGGER.warn("Parameters are found on method " + method.getName() + " annotated with ContentHeader annotation. No parameter is allowed. Ignoring ContentHeader annotation.");
} else {
method.setAccessible(true);
results.put(method.getAnnotation(RestContentHeader.class), method);
}
}
}
return results;
}
Aggregations