public <T> ContextResolver<T> createContextResolver(Type contextType,
Message m) {
boolean isRequestor = MessageUtils.isRequestor(m);
Message requestMessage = isRequestor ? m.getExchange().getOutMessage()
: m.getExchange().getInMessage();
HttpHeaders requestHeaders = new HttpHeadersImpl(requestMessage);
MediaType mt = null;
Message responseMessage = isRequestor ? m.getExchange().getInMessage()
: m.getExchange().getOutMessage();
if (responseMessage != null) {
Object ctProperty = responseMessage.get(Message.CONTENT_TYPE);
if (ctProperty == null) {
List<MediaType> accepts = requestHeaders.getAcceptableMediaTypes();
if (accepts.size() > 0) {
mt = accepts.get(0);
}
} else {
mt = JAXRSUtils.toMediaType(ctProperty.toString());
}
} else {
mt = requestHeaders.getMediaType();
}
return createContextResolver(contextType, m,
mt == null ? MediaType.WILDCARD_TYPE : mt);