public AbstractRequestContextImpl(Message message, boolean responseContext) { super(message); this.h = new HttpHeadersImpl(message); this.responseContext = responseContext; }
private List<String> getHeaderValues(String headerName, String originalValue) { return getHeaderValues(headerName, originalValue, DEFAULT_SEPARATOR); }
public Locale getLanguage() { List<String> values = getListValues(HttpHeaders.CONTENT_LANGUAGE); return values.isEmpty() ? null : HttpUtils.getLocale(values.get(0).trim()); }
private static Object processHeaderParam(Message m, String header, Class<?> pClass, Type genericType, Annotation[] paramAnns, String defaultValue) { List<String> values = new HttpHeadersImpl(m).getRequestHeader(header); if (values != null && values.isEmpty()) { values = null; } return InjectionUtils.createParameterObject(values, pClass, genericType, paramAnns, defaultValue, false, ParameterType.HEADER, m); }
public static String getProtocolHeader(Message m, String name, String defaultValue, boolean setOnMessage) { String value = (String)m.get(name); if (value == null) { value = new HttpHeadersImpl(m).getRequestHeaders().getFirst(name); if (value != null && setOnMessage) { m.put(name, value); } } return value == null ? defaultValue : value; }
private static Object processCookieParam(Message m, String cookieName, Class<?> pClass, Type genericType, Annotation[] paramAnns, String defaultValue) { Cookie c = new HttpHeadersImpl(m).getCookies().get(cookieName); if (c == null && defaultValue != null) { c = Cookie.valueOf(cookieName + '=' + defaultValue); } if (c == null) { return null; } if (pClass.isAssignableFrom(Cookie.class)) { return c; } return InjectionUtils.handleParameter(c.getValue(), false, pClass, paramAnns, ParameterType.COOKIE, m); }
public List<String> getRequestHeader(String name) { boolean splitIndividualValue = MessageUtils.getContextualBoolean(message, HEADER_SPLIT_PROPERTY, false); List<String> values = headers.get(name); if (!splitIndividualValue || values == null || HttpUtils.isDateRelatedHeader(name)) { return values; } List<String> ls = new LinkedList<>(); for (String value : values) { if (value == null) { continue; } String sep = HttpHeaders.COOKIE.equalsIgnoreCase(name) ? getCookieSeparator(value) : DEFAULT_SEPARATOR; ls.addAll(getHeaderValues(name, value, sep)); } return ls; }
public List<String> getRequestHeader(String name) { return httpHeaders.getRequestHeader(name); }
public MultivaluedMap<String, String> getRequestHeaders() { return httpHeaders.getRequestHeaders(); }
public static String getProtocolHeader(Message m, String name, String defaultValue, boolean setOnMessage) { String value = (String)m.get(name); if (value == null) { value = new HttpHeadersImpl(m).getRequestHeaders().getFirst(name); if (value != null && setOnMessage) { m.put(name, value); } } return value == null ? defaultValue : value; }
private static Object processCookieParam(Message m, String cookieName, Class<?> pClass, Type genericType, Annotation[] paramAnns, String defaultValue) { Cookie c = new HttpHeadersImpl(m).getCookies().get(cookieName); if (c == null && defaultValue != null) { c = Cookie.valueOf(cookieName + '=' + defaultValue); } if (c == null) { return null; } if (pClass.isAssignableFrom(Cookie.class)) { return c; } String value = InjectionUtils.isSupportedCollectionOrArray(pClass) && InjectionUtils.getActualType(genericType) == Cookie.class ? c.toString() : c.getValue(); return InjectionUtils.createParameterObject(Collections.singletonList(value), pClass, genericType, paramAnns, null, false, ParameterType.COOKIE, m); }
private static Object processHeaderParam(Message m, String header, Class<?> pClass, Type genericType, Annotation[] paramAnns, String defaultValue) { List<String> values = new HttpHeadersImpl(m).getRequestHeader(header); if (values != null && values.isEmpty()) { values = null; } return InjectionUtils.createParameterObject(values, pClass, genericType, paramAnns, defaultValue, false, ParameterType.HEADER, m); }
public Map<String, Cookie> getCookies() { List<String> values = headers.get(HttpHeaders.COOKIE); if (values == null || values.isEmpty()) { return Collections.emptyMap(); } Map<String, Cookie> cl = new HashMap<>(); for (String value : values) { if (value == null) { continue; } List<String> cs = getHeaderValues(HttpHeaders.COOKIE, value, getCookieSeparator(value)); for (String c : cs) { Cookie cookie = Cookie.valueOf(c); cl.put(cookie.getName(), cookie); } } return cl; }
public List<String> getRequestHeader(String name) { return httpHeaders.getRequestHeader(name); }
public MultivaluedMap<String, String> getRequestHeaders() { return httpHeaders.getRequestHeaders(); }
public RequestImpl(Message m) { this.m = m; this.headers = new HttpHeadersImpl(m); }
@SuppressWarnings("unchecked") public static Object readFromMessageBodyReader(List<ReaderInterceptor> readers, Class<?> targetTypeClass, Type parameterType, Annotation[] parameterAnnotations, InputStream is, MediaType mediaType, Message m) throws IOException, WebApplicationException { // Verbose but avoids an extra context instantiation for the typical path if (readers.size() > 1) { ReaderInterceptor first = readers.remove(0); ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass, parameterType, parameterAnnotations, is, m, readers); return first.aroundReadFrom(context); } MessageBodyReader<?> provider = ((ReaderInterceptorMBR)readers.get(0)).getMBR(); @SuppressWarnings("rawtypes") Class cls = targetTypeClass; return provider.readFrom( cls, parameterType, parameterAnnotations, mediaType, new HttpHeadersImpl(m).getRequestHeaders(), is); }
public Map<String, Cookie> getCookies() { List<String> values = headers.get(HttpHeaders.COOKIE); if (values == null || values.isEmpty()) { return Collections.emptyMap(); } Map<String, Cookie> cl = new HashMap<String, Cookie>(); for (String value : values) { if (value == null) { continue; } List<String> cs = value.contains("$") ? Collections.singletonList(value) : getHeaderValues(HttpHeaders.COOKIE, value, getCookieSeparator()); for (String c : cs) { Cookie cookie = Cookie.valueOf(c); cl.put(cookie.getName(), cookie); } } return cl; }
public MediaType getMediaType() { List<String> values = getListValues(HttpHeaders.CONTENT_TYPE); return values.isEmpty() ? null : JAXRSUtils.toMediaType(values.get(0)); }
public MultivaluedMap<String, String> getRequestHeaders() { boolean splitIndividualValue = MessageUtils.getContextualBoolean(message, HEADER_SPLIT_PROPERTY, false); if (splitIndividualValue) { Map<String, List<String>> newHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (Map.Entry<String, List<String>> entry : headers.entrySet()) { newHeaders.put(entry.getKey(), getRequestHeader(entry.getKey())); } return new MetadataMap<String, String>(Collections.unmodifiableMap(newHeaders), false); } return new MetadataMap<String, String>(Collections.unmodifiableMap(headers), false); }