@Override public Locale getLanguage() { return HttpHelper.getContentLanguageAsLocale(this); }
/** * Get the list of language tag from the "Accept-Language" of an HTTP request. * <p> * @deprecated see {@link #getAcceptLanguage(com.sun.jersey.api.core.HttpRequestContext) }. * @param request The HTTP request. * @return The list of LanguageTag. This list * is ordered with the highest quality acceptable language tag occurring first. */ @Deprecated public static List<AcceptableLanguageTag> getAcceptLangauge(HttpRequestContext request) { return getAcceptLanguage(request); }
@Override public List<MediaType> getAcceptableMediaTypes(List<QualitySourceMediaType> priorityMediaTypes) { return new ArrayList<MediaType>(HttpHelper.getAccept(this, priorityMediaTypes)); }
private void processMethods( final AbstractResource resource, final List<QualitySourceMediaType> implictProduces, final RulesMap<UriRule> rulesMap) { final ResourceMethodMap rmm = new ResourceMethodMap(); for (final AbstractResourceMethod resourceMethod : resource.getResourceMethods()) { ResourceMethod rm = new ResourceHttpMethod(dp, ff, resourceMethod); if (isValidResourceMethod(rm, rmm)) { rmm.put(rm); } } addImplicitMethod(implictProduces, rmm); processHead(rmm); processOptions(rmm, resource, null); // Create the rules for the HTTP methods rmm.sort(); if (!rmm.isEmpty()) { // No need to adapt with the RightHandPathRule as the URI path // will be consumed when such a rule is accepted rulesMap.put(PathPattern.EMPTY_PATH, new HttpMethodRule(rmm, dispatchingListener)); } }
private void processHead(final ResourceMethodMap methodMap) { final List<ResourceMethod> getList = methodMap.get(HttpMethod.GET); if (getList == null || getList.isEmpty()) { return; } List<ResourceMethod> headList = methodMap.get(HttpMethod.HEAD); if (headList == null) { headList = new ArrayList<ResourceMethod>(); } for (final ResourceMethod getMethod : getList) { if (!containsMediaOfMethod(headList, getMethod)) { final ResourceMethod headMethod = new ResourceHeadWrapperMethod(getMethod); methodMap.put(headMethod); headList = methodMap.get(HttpMethod.HEAD); } } }
private void processOptions( final ResourceMethodMap methodMap, final AbstractResource resource, final PathPattern p) { final List<ResourceMethod> l = methodMap.get("OPTIONS"); if (l != null) { return; } ResourceMethod optionsMethod = wadlFactory.createWadlOptionsMethod(methodMap, resource, p); if (optionsMethod == null) { optionsMethod = new ResourceHttpOptionsMethod(methodMap); } methodMap.put(optionsMethod); } }
public void processConflicts(ConflictClosure cc) { final List<PathPattern> ks = new ArrayList<PathPattern>(keySet()); for (int i = 0; i < ks.size(); i++) { final PathPattern p1 = ks.get(i); for (int j = i + 1; j < ks.size(); j++) { final PathPattern p2 = ks.get(j); if (p1.equals(p2)) { cc.onConflict(p1, p2); } } } }
private void addImplicitMethod( final List<QualitySourceMediaType> implictProduces, final ResourceMethodMap rmm) { if (implictProduces != null) { final List<ResourceMethod> getList = rmm.get(HttpMethod.GET); if (getList != null && !getList.isEmpty()) { rmm.put(new ViewResourceMethod(implictProduces)); } } }
/** * Get the content type from a String. * <p> * @param contentTypeString the content type as a String. * @return The content type. If no "Content-Type is present then null is * returned. */ public static MediaType getContentType(String contentTypeString) { try { return (contentTypeString != null) ? MediaType.valueOf(contentTypeString) : null; } catch(IllegalArgumentException e) { throw clientError("Bad Content-Type header value: '" + contentTypeString + "'", e); } }
@Override public MediaType getMediaType() { if (contentType == null || headersModCount != headers.getModCount()) contentType = HttpHelper.getContentType(this); return contentType; }
/** * Sort the list methods for each value in the method map. */ public void sort() { for (Map.Entry<String, List<ResourceMethod>> e : entrySet()) { Collections.sort(e.getValue(), ResourceMethod.COMPARATOR); } } }
public PathPattern hasConflict(PathPattern p) { for (PathPattern cp : keySet()) { if (cp.equals(p)) { return cp; } } return null; }
@Override public ResponseBuilder evaluatePreconditions() { Set<MatchingEntityTag> matchingTags = HttpHelper.getIfMatch(this); if (matchingTags == null) { return null; } // Since the resource does not exist the method must not be // perform and 412 Precondition Failed is returned return Responses.preconditionFailed(); }
/** * Get the content language as a Locale instance. * * @param request The HTTP request. * @return the content language as a locale instance. */ public static Locale getContentLanguageAsLocale(HttpRequestContext request) { return HttpHelper.getLanguageTagAsLocale(request.getRequestHeaders(). getFirst(HttpHeaders.CONTENT_LANGUAGE)); }
private ResponseBuilder evaluateIfNoneMatch(EntityTag eTag) { Set<MatchingEntityTag> matchingTags = HttpHelper.getIfNoneMatch(this); if (matchingTags == null) return null; final String httpMethod = getMethod(); return evaluateIfNoneMatch( eTag, matchingTags, httpMethod.equals("GET") || httpMethod.equals("HEAD")); }
public static Locale getLanguageTagAsLocale(String language) { if (language == null) return null; try { return new LanguageTag(language).getAsLocale(); } catch (java.text.ParseException e) { throw clientError("Bad Content-Language header value: '" + language + "'", e); } }
/** * Get the content type from the "Content-Type" of an HTTP request. * <p> * @param request The HTTP request. * @return The content type. If no "Content-Type is present then null is * returned. */ public static MediaType getContentType(HttpRequestContext request) { return getContentType(request.getRequestHeaders().getFirst(HttpHeaders.CONTENT_TYPE)); }
@Override public List<MediaType> getAcceptableMediaTypes() { if (accept == null || headersModCount != headers.getModCount()) accept = new ArrayList<MediaType>(HttpHelper.getAccept(this)); return accept; }
public static Set<MatchingEntityTag> getIfMatch(HttpRequestContext request) { final String ifMatch = request.getHeaderValue(HttpHeaders.IF_MATCH); if (ifMatch == null || ifMatch.length() == 0) { return null; } try { return HttpHeaderReader.readMatchingEntityTag(ifMatch); } catch (java.text.ParseException e) { throw clientError("Bad If-Match header value: '" + ifMatch + "'", e); } }
public static Set<MatchingEntityTag> getIfNoneMatch(HttpRequestContext request) { final String ifNoneMatch = request.getHeaderValue(HttpHeaders.IF_NONE_MATCH); if (ifNoneMatch == null || ifNoneMatch.length() == 0) { return null; } try { return HttpHeaderReader.readMatchingEntityTag(ifNoneMatch); } catch (java.text.ParseException e) { throw clientError("Bad If-None-Match header value: '" + ifNoneMatch + "'", e); } }