private static List<String> iterableToList(final Iterable<?> values) { final LinkedList<String> linkedList = new LinkedList<String>(); final RuntimeDelegate rd = RuntimeDelegate.getInstance(); for (Object element : values) { linkedList.add(HeaderUtils.asString(element, rd)); } return linkedList; }
private static List<String> iterableToList(final Iterable<?> values) { final LinkedList<String> linkedList = new LinkedList<String>(); final RuntimeDelegate rd = RuntimeDelegate.getInstance(); for (Object element : values) { linkedList.add(HeaderUtils.asString(element, rd)); } return linkedList; }
/** * Add content type of the entity. * * @param contentType content media type. * @return the updated builder. */ public ContainerRequestBuilder type(final MediaType contentType) { request.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, HeaderUtils.asString(contentType, delegate)); return this; }
/** * Add a new header value. * * @param name header name. * @param value header value. * @return updated context. */ public InboundMessageContext header(String name, Object value) { getHeaders().add(name, HeaderUtils.asString(value, RuntimeDelegate.getInstance())); return this; }
/** * Add a new header value. * * @param name header name. * @param value header value. * @return updated context. */ public InboundMessageContext header(String name, Object value) { getHeaders().add(name, HeaderUtils.asString(value, RuntimeDelegate.getInstance())); return this; }
/** * Returns string view of list of header values. Any modifications to the underlying list are visible to the view, * the view also supports removal of elements. Does not support other modifications. * * @param headerValues header values. * @param rd RuntimeDelegate instance or {@code null} (in that case {@link RuntimeDelegate#getInstance()} * will be called for before element conversion. * @return String view of header values. */ public static List<String> asStringList(final List<Object> headerValues, final RuntimeDelegate rd) { if (headerValues == null || headerValues.isEmpty()) { return Collections.emptyList(); } final RuntimeDelegate delegate; if (rd == null) { delegate = RuntimeDelegate.getInstance(); } else { delegate = rd; } return Views.listView(headerValues, input -> (input == null) ? "[null]" : HeaderUtils.asString(input, delegate)); }
/** * Returns string view of list of header values. Any modifications to the underlying list are visible to the view, * the view also supports removal of elements. Does not support other modifications. * * @param headerValues header values. * @param rd RuntimeDelegate instance or {@code null} (in that case {@link RuntimeDelegate#getInstance()} * will be called for before element conversion. * @return String view of header values. */ public static List<String> asStringList(final List<Object> headerValues, final RuntimeDelegate rd) { if (headerValues == null || headerValues.isEmpty()) { return Collections.emptyList(); } final RuntimeDelegate delegate; if (rd == null) { delegate = RuntimeDelegate.getInstance(); } else { delegate = rd; } return Views.listView(headerValues, input -> (input == null) ? "[null]" : HeaderUtils.asString(input, delegate)); }
/** * Get a single typed header value. * * @param name header name. * @param converter from string conversion function. Is expected to throw {@link ProcessingException} * if conversion fails. * @param convertNull if {@code true} this method calls the provided converter even for {@code null}. Otherwise this * method returns the {@code null} without calling the converter. * @return value of the header, or (possibly converted) {@code null} if not present. */ private <T> T singleHeader(String name, Function<String, T> converter, boolean convertNull) { final List<String> values = this.headers.get(name); if (values == null || values.isEmpty()) { return convertNull ? converter.apply(null) : null; } if (values.size() > 1) { throw new HeaderValueException(LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()), HeaderValueException.Context.INBOUND); } Object value = values.get(0); if (value == null) { return convertNull ? converter.apply(null) : null; } try { return converter.apply(HeaderUtils.asString(value, null)); } catch (ProcessingException ex) { throw exception(name, value, ex); } }
/** * Get a single typed header value. * * @param name header name. * @param converter from string conversion function. Is expected to throw {@link ProcessingException} * if conversion fails. * @param convertNull if {@code true} this method calls the provided converter even for {@code null}. Otherwise this * method returns the {@code null} without calling the converter. * @return value of the header, or (possibly converted) {@code null} if not present. */ private <T> T singleHeader(String name, Function<String, T> converter, boolean convertNull) { final List<String> values = this.headers.get(name); if (values == null || values.isEmpty()) { return convertNull ? converter.apply(null) : null; } if (values.size() > 1) { throw new HeaderValueException(LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()), HeaderValueException.Context.INBOUND); } Object value = values.get(0); if (value == null) { return convertNull ? converter.apply(null) : null; } try { return converter.apply(HeaderUtils.asString(value, null)); } catch (ProcessingException ex) { throw exception(name, value, ex); } }
conversionApplied = true; try { result.add(Link.valueOf(HeaderUtils.asString(value, rd))); } catch (IllegalArgumentException e) { throw exception(HttpHeaders.LINK, value, e);
conversionApplied = true; try { result.add(Link.valueOf(HeaderUtils.asString(value, rd))); } catch (IllegalArgumentException e) { throw exception(HttpHeaders.LINK, value, e);
} else { try { return converter.apply(HeaderUtils.asString(value, null)); } catch (ProcessingException ex) { throw exception(name, value, ex);
} else { try { return converter.apply(HeaderUtils.asString(value, null)); } catch (ProcessingException ex) { throw exception(name, value, ex);
conversionApplied = true; try { result.addAll(HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)) .stream() .map(LanguageTag::getAsLocale)
conversionApplied = true; try { result.addAll(HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)) .stream() .map(LanguageTag::getAsLocale)
} else { conversionApplied = true; result.addAll(HttpHeaderReader.readAcceptMediaType(HeaderUtils.asString(value, rd)));
} else { conversionApplied = true; result.addAll(HttpHeaderReader.readAcceptMediaType(HeaderUtils.asString(value, rd)));
private void putHeader(final String name, final Object value) { if (value == null) { request.getHeaders().remove(name); return; } request.header(name, HeaderUtils.asString(value, delegate)); }
private static List<String> iterableToList(final Iterable<?> values) { final LinkedList<String> linkedList = new LinkedList<String>(); final RuntimeDelegate rd = RuntimeDelegate.getInstance(); for (Object element : values) { linkedList.add(HeaderUtils.asString(element, rd)); } return linkedList; }
/** * Add a new header value. * * @param name header name. * @param value header value. * @return updated context. */ public InboundMessageContext header(String name, Object value) { getHeaders().add(name, HeaderUtils.asString(value, RuntimeDelegate.getInstance())); return this; }