/** * Get a message header as a single string value. * <p> * 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 name the message header. * @return the message header value. If the message header is not present then * {@code null} is returned. If the message header is present but has no * value then the empty string is returned. If the message header is present * more than once then the values of joined together and separated by a ',' * character. */ public String getHeaderString(String name) { return HeaderUtils.asHeaderString(headers.get(name), RuntimeDelegate.getInstance()); }
/** * Get a multi-valued map representing outbound message headers with their values converted * to strings. * * @return multi-valued map of outbound message header names to their string-converted values. */ public MultivaluedMap<String, String> getStringHeaders() { return HeaderUtils.asStringHeaders(headers); }
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; }
/** * 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(); }
/** * Create new outbound message context. */ public OutboundMessageContext() { this.headers = HeaderUtils.createOutbound(); this.committingOutputStream = new CommittingOutputStream(); this.entityStream = committingOutputStream; }
@Override public void onHeaders(final Response jettyResponse) { HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, jerseyRequest.getHeaders(), JettyConnector.this.getClass().getName()); if (responseFuture.isDone()) { if (!callbackInvoked.compareAndSet(false, true)) { return; } } final ClientResponse response = translateResponse(jerseyRequest, jettyResponse, entityStream); jerseyResponse.set(response); }
/** * Create new inbound message context. * * @param translateNce if {@code true}, the {@link javax.ws.rs.core.NoContentException} thrown by a * selected message body reader will be translated into a {@link javax.ws.rs.BadRequestException} * as required by JAX-RS specification on the server side. */ public InboundMessageContext(boolean translateNce) { this.headers = HeaderUtils.createInbound(); this.entityContent = new EntityContent(); this.translateNce = translateNce; }
private static Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Object> headers, final HttpUriRequest request) { final Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers); for (final Map.Entry<String, String> e : stringHeaders.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } return stringHeaders; }
/** * 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(); }
/** * Create new outbound message context. */ public OutboundMessageContext() { this.headers = HeaderUtils.createOutbound(); this.committingOutputStream = new CommittingOutputStream(); this.entityStream = committingOutputStream; }
@Override public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { if (!futureSet.compareAndSet(false, true)) { return STATE.ABORT; } HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, request.getHeaders(), GrizzlyConnector.this.getClass().getName()); responseFuture.complete(translate(request, this.status, headers, entityStream)); return STATE.CONTINUE; }
/** * Create new inbound message context. * * @param translateNce if {@code true}, the {@link javax.ws.rs.core.NoContentException} thrown by a * selected message body reader will be translated into a {@link javax.ws.rs.BadRequestException} * as required by JAX-RS specification on the server side. */ public InboundMessageContext(boolean translateNce) { this.headers = HeaderUtils.createInbound(); this.entityContent = new EntityContent(); this.translateNce = translateNce; }
private static Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Object> headers, final com.ning.http.client.Request request) { Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers); for (Map.Entry<String, String> e : stringHeaders.entrySet()) { request.getHeaders().add(e.getKey(), e.getValue()); } return stringHeaders; }
/** * Get a message header as a single string value. * <p> * 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 name the message header. * @return the message header value. If the message header is not present then * {@code null} is returned. If the message header is present but has no * value then the empty string is returned. If the message header is present * more than once then the values of joined together and separated by a ',' * character. */ public String getHeaderString(String name) { return HeaderUtils.asHeaderString(headers.get(name), RuntimeDelegate.getInstance()); }
/** * 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; }
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; }
/** * Get a multi-valued map representing outbound message headers with their values converted * to strings. * * @return multi-valued map of outbound message header names to their string-converted values. */ public MultivaluedMap<String, String> getStringHeaders() { return HeaderUtils.asStringHeaders(headers); }
/** * Create new outbound message context copying the content * of another context. * * @param original the original outbound message context. */ public OutboundMessageContext(OutboundMessageContext original) { this.headers = HeaderUtils.createOutbound(); this.headers.putAll(original.headers); this.committingOutputStream = new CommittingOutputStream(); this.entityStream = committingOutputStream; this.entity = original.entity; this.entityType = original.entityType; this.entityAnnotations = original.entityAnnotations; }
@Override public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { if (!callbackInvoked.compareAndSet(false, true)) { return STATE.ABORT; } HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, request.getHeaders(), GrizzlyConnector.this.getClass().getName()); // hand-off to grizzly's application thread pool for response processing processResponse(new Runnable() { @Override public void run() { callback.response(translate(request, status, headers, entityStream)); } }); return STATE.CONTINUE; }
/** * Create new inbound message context. * * @param translateNce if {@code true}, the {@link javax.ws.rs.core.NoContentException} thrown by a * selected message body reader will be translated into a {@link javax.ws.rs.BadRequestException} * as required by JAX-RS specification on the server side. */ public InboundMessageContext(boolean translateNce) { this.headers = HeaderUtils.createInbound(); this.entityContent = new EntityContent(); this.translateNce = translateNce; }