public boolean doesProduce(List<? extends MediaType> accepts) { if (accepts == null || accepts.size() == 0) { // System.out.println("**** no accepts " +" method: " + method); return true; } if (method.getProduces().length == 0) { // System.out.println("**** no produces " +" method: " + method); return true; } for (MediaType accept : accepts) { for (MediaType type : method.getProduces()) { if (type.isCompatible(accept)) { return true; } } } return false; }
private JaxrsResourceLocatorDescription resLocatorDescription( ResourceClass resClass, String contextPath, String mapping, Collection<String> servletMappings, List<Class<?>> resolvedCls) { JaxrsResourceLocatorDescription locatorRes = new JaxrsResourceLocatorDescription(); locatorRes.resourceClass = resClass.getClazz(); resolvedCls.add(resClass.getClazz()); for (ResourceMethod resMethod : resClass.getResourceMethods()) { JaxrsResourceMethodDescription jaxrsRes = new JaxrsResourceMethodDescription(); jaxrsRes.consumeTypes = resMethod.getConsumes(); jaxrsRes.contextPath = contextPath; jaxrsRes.httpMethods = resMethod.getHttpMethods(); jaxrsRes.method = resMethod.getMethod(); jaxrsRes.produceTypes = resMethod.getProduces(); jaxrsRes.resourceClass = resClass.getClazz(); String resPath = new StringBuilder(mapping) .append("/") .append(resMethod.getFullpath()) .toString() .replace("//", "/"); jaxrsRes.resourcePath = resPath; jaxrsRes.servletMappings = servletMappings; addMethodParameters(jaxrsRes, resMethod.getMethod()); locatorRes.methodsDescriptions.add(jaxrsRes); } for (ResourceLocator resLocator : resClass.getResourceLocators()) { Class<?> clz = resLocator.getReturnType(); if (clz.equals(resClass.getClazz())) { break; } if (resolvedCls.contains(clz)) { break; } else { resolvedCls.add(clz); } ResourceClass subResClass = ResourceBuilder.locatorFromAnnotations(clz); String subMapping = new StringBuilder(mapping) .append("/") .append(resLocator.getFullpath()) .toString() .replace("//", "/"); JaxrsResourceLocatorDescription inner = resLocatorDescription(subResClass, contextPath, subMapping, servletMappings, resolvedCls); if (inner.containsMethodResources()) { locatorRes.subLocatorDescriptions.add(inner); } } return locatorRes; }
public MediaType resolveContentType(HttpRequest in, Object entity) { MediaType chosen = (MediaType) in.getAttribute(SegmentNode.RESTEASY_CHOSEN_ACCEPT); if (chosen != null && !chosen.equals(MediaType.WILDCARD_TYPE)) { return chosen; } List<MediaType> accepts = in.getHttpHeaders().getAcceptableMediaTypes(); if (accepts == null || accepts.size() == 0) { if (method.getProduces().length == 0) return MediaType.WILDCARD_TYPE; else return method.getProduces()[0]; } if (method.getProduces().length == 0) { return resolveContentTypeByAccept(accepts, entity); } for (MediaType accept : accepts) { for (MediaType type : method.getProduces()) { if (type.isCompatible(accept)) return type; } } return MediaType.WILDCARD_TYPE; }
public MediaType[] getProduces() { return method.getProduces(); }