/** * Converts a list of message header values to a single string value (with individual values separated by * {@code ','}). * * Each single header value is converted to String using a * {@link javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one is available * via {@link javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} * for the header value class or using its {@code toString()} method if a header * delegate is not available. * * @param values list of individual header values. * @param rd {@link RuntimeDelegate} instance or {@code null} (in that case {@link RuntimeDelegate#getInstance()} * will be called for before conversion of elements). * @return single string consisting of all the values passed in as a parameter. If values parameter is {@code null}, * {@code null} is returned. If the list of values is empty, an empty string is returned. */ public static String asHeaderString(final List<Object> values, final RuntimeDelegate rd) { if (values == null) { return null; } final Iterator<String> stringValues = asStringList(values, rd).iterator(); if (!stringValues.hasNext()) { return ""; } final StringBuilder buffer = new StringBuilder(stringValues.next()); while (stringValues.hasNext()) { buffer.append(',').append(stringValues.next()); } return buffer.toString(); }
/** * Converts a list of message header values to a single string value (with individual values separated by * {@code ','}). * * Each single header value is converted to String using a * {@link javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one is available * via {@link javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} * for the header value class or using its {@code toString()} method if a header * delegate is not available. * * @param values list of individual header values. * @param rd {@link RuntimeDelegate} instance or {@code null} (in that case {@link RuntimeDelegate#getInstance()} * will be called for before conversion of elements). * @return single string consisting of all the values passed in as a parameter. If values parameter is {@code null}, * {@code null} is returned. If the list of values is empty, an empty string is returned. */ public static String asHeaderString(final List<Object> values, final RuntimeDelegate rd) { if (values == null) { return null; } final Iterator<String> stringValues = asStringList(values, rd).iterator(); if (!stringValues.hasNext()) { return ""; } final StringBuilder buffer = new StringBuilder(stringValues.next()); while (stringValues.hasNext()) { buffer.append(',').append(stringValues.next()); } return buffer.toString(); }
/** * Get any cookies that accompanied the message. * * @return a read-only map of cookie name (String) to {@link javax.ws.rs.core.Cookie}. */ public Map<String, Cookie> getRequestCookies() { final List<Object> cookies = headers.get(HttpHeaders.COOKIE); if (cookies == null || cookies.isEmpty()) { return Collections.emptyMap(); } Map<String, Cookie> result = new HashMap<String, Cookie>(); for (String cookie : HeaderUtils.asStringList(cookies, RuntimeDelegate.getInstance())) { if (cookie != null) { result.putAll(HttpHeaderReader.readCookies(cookie)); } } return result; }
/** * Get any cookies that accompanied the message. * * @return a read-only map of cookie name (String) to {@link javax.ws.rs.core.Cookie}. */ public Map<String, Cookie> getRequestCookies() { final List<Object> cookies = headers.get(HttpHeaders.COOKIE); if (cookies == null || cookies.isEmpty()) { return Collections.emptyMap(); } Map<String, Cookie> result = new HashMap<String, Cookie>(); for (String cookie : HeaderUtils.asStringList(cookies, RuntimeDelegate.getInstance())) { if (cookie != null) { result.putAll(HttpHeaderReader.readCookies(cookie)); } } return result; }
/** * Get any new cookies set on the message message. * * @return a read-only map of cookie name (String) to a {@link javax.ws.rs.core.NewCookie new cookie}. */ public Map<String, NewCookie> getResponseCookies() { List<Object> cookies = headers.get(HttpHeaders.SET_COOKIE); if (cookies == null || cookies.isEmpty()) { return Collections.emptyMap(); } Map<String, NewCookie> result = new HashMap<String, NewCookie>(); for (String cookie : HeaderUtils.asStringList(cookies, RuntimeDelegate.getInstance())) { if (cookie != null) { NewCookie newCookie = HttpHeaderReader.readNewCookie(cookie); result.put(newCookie.getName(), newCookie); } } return result; }
/** * Get any new cookies set on the message message. * * @return a read-only map of cookie name (String) to a {@link javax.ws.rs.core.NewCookie new cookie}. */ public Map<String, NewCookie> getResponseCookies() { List<Object> cookies = headers.get(HttpHeaders.SET_COOKIE); if (cookies == null || cookies.isEmpty()) { return Collections.emptyMap(); } Map<String, NewCookie> result = new HashMap<String, NewCookie>(); for (String cookie : HeaderUtils.asStringList(cookies, RuntimeDelegate.getInstance())) { if (cookie != null) { NewCookie newCookie = HttpHeaderReader.readNewCookie(cookie); result.put(newCookie.getName(), newCookie); } } return result; }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
/** * Returns string view of passed headers. Any modifications to the headers are visible to the view, the view also * supports removal of elements. Does not support other modifications. * * @param headers headers. * @return String view of headers or {@code null} if {code headers} input parameter is {@code null}. */ public static MultivaluedMap<String, String> asStringHeaders(final MultivaluedMap<String, Object> headers) { if (headers == null) { return null; } final RuntimeDelegate rd = RuntimeDelegate.getInstance(); return new AbstractMultivaluedMap<String, String>( Views.mapView(headers, input -> HeaderUtils.asStringList(input, rd)) ) { }; }
/** * Returns string view of passed headers. Any modifications to the headers are visible to the view, the view also * supports removal of elements. Does not support other modifications. * * @param headers headers. * @return String view of headers or {@code null} if {code headers} input parameter is {@code null}. */ public static MultivaluedMap<String, String> asStringHeaders(final MultivaluedMap<String, Object> headers) { if (headers == null) { return null; } final RuntimeDelegate rd = RuntimeDelegate.getInstance(); return new AbstractMultivaluedMap<String, String>( Views.mapView(headers, input -> HeaderUtils.asStringList(input, rd)) ) { }; }
private void putHeaders(final String name, final Object... values) { if (values == null) { request.getHeaders().remove(name); return; } request.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), delegate)); }
@Override public List<String> apply(final List<Object> input) { return HeaderUtils.asStringList(input, rd); } })
@Override public List<String> apply(final List<Object> input) { return HeaderUtils.asStringList(input, rd); } })
@Override public List<String> apply(final List<Object> input) { return HeaderUtils.asStringList(input, rd); } })
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
/** * Add new header values. * * @param name header name. * @param values header values. * @return updated context. */ public InboundMessageContext headers(String name, Object... values) { this.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), RuntimeDelegate.getInstance())); return this; }
private void putHeaders(final String name, final Object... values) { if (values == null) { request.getHeaders().remove(name); return; } request.getHeaders().addAll(name, HeaderUtils.asStringList(Arrays.asList(values), delegate)); }