Refine search
if (responseContext.hasEntity() && contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); final MultivaluedMap<String, String> headers = getResponseContext().getStringHeaders(); for (final Map.Entry<String, List<String>> e : headers.entrySet()) { final Iterator<String> it = e.getValue().iterator(); if (!it.hasNext()) { final String reasonPhrase = responseContext.getStatusInfo().getReasonPhrase(); if (reasonPhrase != null) { response.setStatus(responseContext.getStatus(), reasonPhrase); } else { response.setStatus(responseContext.getStatus()); if (!responseContext.hasEntity()) { return null; } else { throw new ContainerException(e);
ServerRuntime.ensureAbsolute(response.getLocation(), response.getHeaders(), response.getRequestContext(), runtime.rfc7231LocationHeaderRelativeUriResolution); if (!response.hasEntity()) { tracingLogger.log(ServerTraceEvent.FINISHED, response.getStatusInfo()); tracingLogger.flush(response.getHeaders()); final Object entity = response.getEntity(); boolean skipFinally = false; response.setStreamProvider(new OutboundMessageContext.StreamProvider() { @Override public OutputStream getOutputStream(final int contentLength) throws IOException { if ((writer.enableResponseBuffering() || isHead) && !response.isChunked()) { response.enableBuffering(runtime.configuration); response.setEntityStream(request.getWorkers().writeTo( entity, entity.getClass(), response.getEntityType(), response.getEntityAnnotations(), response.getMediaType(), response.getHeaders(), request.getPropertiesDelegate(), response.getEntityStream(), tracingLogger.log(ServerTraceEvent.FINISHED, response.getStatusInfo()); tracingLogger.flush(response.getHeaders());
@Override public ContainerResponse apply( final RequestProcessingContext requestContext) { return new ContainerResponse(requestContext.request(), abortResponse); } }));
/** * Returns {@code true} if the response entity is a {@link ChunkedOutput} instance. * @return {@code true} if the entity is a {@link ChunkedOutput} instance, {@code false} otherwise. */ public boolean isChunked() { return hasEntity() && ChunkedOutput.class.isAssignableFrom(getEntity().getClass()); } }
@Override public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse responseContext) { List<Object> length = new ArrayList<>(); length.add(String.valueOf(contentLength)); responseContext.getHeaders().put(HttpHeaders.CONTENT_LENGTH, length); headers = responseContext.getStringHeaders(); statusInfo = responseContext.getStatusInfo(); return baos; }
@Override public OutputStream getOutputStream(final int contentLength) throws IOException { if (!runtime.disableLocationHeaderRelativeUriResolution) { ServerRuntime.ensureAbsolute(response.getLocation(), response.getHeaders(), response.getRequestContext(), runtime.rfc7231LocationHeaderRelativeUriResolution); } final OutputStream outputStream = writer.writeResponseStatusAndHeaders(contentLength, response); return isHead ? null : outputStream; } });
response.setStatusCode(responseContext.getStatus()); response.setStatusMessage(responseContext.getStatusInfo().getReasonPhrase()); for (final Map.Entry<String, List<String>> e : responseContext.getStringHeaders().entrySet()) { response.putHeader(e.getKey(), e.getValue()); if (responseContext.isChunked()) { response.setChunked(true); return new VertxChunkedOutputStream(response); } else if (responseContext.hasEntity() && WriteStreamOutput.class.isAssignableFrom(responseContext.getEntityClass())) { WriteStreamOutput writeStreamOutput = (WriteStreamOutput) responseContext.getEntity(); writeStreamOutput.init(response, event -> end()); isWriteStream = true;
throws ContainerException { String reasonPhrase = responseContext.getStatusInfo().getReasonPhrase(); int statusCode = responseContext.getStatus(); response.status(Integer.toString(responseContext.getStatus())); for (final Map.Entry<String, List<String>> e : responseContext.getStringHeaders().entrySet()) { response.add(e.getKey().toLowerCase(), e.getValue());
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? HttpStatus.getMessage(code) : statusInfo.getReasonPhrase(); response.setStatusWithReason(code, reason); if (contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addHeader(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
@Override public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse responseContext) throws ContainerException { httpResponse = new DefaultHttpResponse(protocolVersion, HttpResponseStatus.valueOf(responseContext.getStatus())); if (length == -1 && responseContext.getEntity() instanceof String) { // TODO there's got to be a better way... final String entity = (String) responseContext.getEntity(); final byte[] encodedBytes = entity.getBytes(Charset.forName("UTF-8")); length = encodedBytes.length; if (! responseContext.getHeaders().containsKey(HttpHeaders.Names.CONTENT_LENGTH)) { HttpHeaders.setContentLength(httpResponse, length); log.trace("Writing response status and headers {}, length {}", responseContext, length); for (Map.Entry<String, List<String>> headerEntry : responseContext.getStringHeaders().entrySet()) { HttpHeaders.addHeader(httpResponse, headerEntry.getKey(), join(headerEntry.getValue(), ", "));
DefaultFullHttpResponse httpResponse = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), HttpResponseStatus.valueOf(containerResponse.getStatus()), buffer); int length = containerResponse.getLength(); if (length == -1 && containerResponse.getEntity() instanceof String) { final String entity = (String) containerResponse.getEntity(); final byte[] encodedBytes = entity.getBytes(Charset.forName("UTF-8")); length = encodedBytes.length; if (! containerResponse.getHeaders().containsKey(HttpHeaders.Names.CONTENT_LENGTH)) { HttpHeaders.setContentLength(httpResponse, length); logger.trace("Writing response status and headers {}, length {}", containerResponse, containerResponse.getLength()); for (Map.Entry<String, List<Object>> headerEntry : containerResponse.getHeaders().entrySet()) { HttpHeaders.addHeader(httpResponse, headerEntry.getKey(), Joiner.on(", ").join(headerEntry.getValue()));
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final MultivaluedMap<String, String> responseHeaders = context.getStringHeaders(); final Headers serverHeaders = exchange.getResponseHeaders(); for (final Map.Entry<String, List<String>> e : responseHeaders.entrySet()) { for (final String value : e.getValue()) { serverHeaders.add(e.getKey(), value); } } try { if (context.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) { // Work around bug in LW HTTP server // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6886436 exchange.sendResponseHeaders(context.getStatus(), -1); } else { exchange.sendResponseHeaders(context.getStatus(), getResponseLength(contentLength)); } } catch (final IOException ioe) { throw new ContainerException(LocalizationMessages.ERROR_RESPONSEWRITER_WRITING_HEADERS(), ioe); } return exchange.getResponseBody(); }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse response) { this.response = response; if (contentLength >= 0) { response.getHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength)); } return outputStream; }
@Override public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse context) throws ContainerException { MultivaluedMap<String, String> responseHeaders = context.getStringHeaders(); HttpHeaders nettyHeaders = response.headers(); for (Entry<String, List<String>> entry: responseHeaders.entrySet()) { nettyHeaders.add(entry.getKey(), entry.getValue()); } int status = context.getStatus(); response.setStatus(HttpResponseStatus.valueOf(status)); return new ByteBufOutputStream(response.content()); }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { try { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); if (statusInfo.getReasonPhrase() == null) { grizzlyResponse.setStatus(statusInfo.getStatusCode()); } else { grizzlyResponse.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase()); } grizzlyResponse.setContentLengthLong(contentLength); for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { grizzlyResponse.addHeader(e.getKey(), value); } } return grizzlyResponse.getOutputStream(); } finally { logger.debugLog("{0} - writeResponseStatusAndHeaders() called", name); } }
final boolean hasEntity = responseContext.hasEntity(); final Response.StatusType status = responseContext.getStatusInfo(); if (!hasEntity && status != null && status.getStatusCode() >= 400 && !(useSetStatusOn404 && status == Response.Status.NOT_FOUND)) { throw new ContainerException( LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(status, reason != null ? reason : "--"), ex);
@Override public ContainerResponse apply(final ContainerResponse responseContext) { // we only need to compute and set the effective media type if: // - it hasn't been set already, and // - either there is an entity, or we are responding to a HEAD request if (responseContext.getMediaType() == null && ((responseContext.hasEntity() || HttpMethod.HEAD.equals(request.getMethod())))) { MediaType effectiveResponseType = determineResponseMediaType( responseContext.getEntityClass(), responseContext.getEntityType(), methodSelector.selected, acceptableMediaTypes); if (MediaTypes.isWildcard(effectiveResponseType)) { if (effectiveResponseType.isWildcardType() || "application".equalsIgnoreCase(effectiveResponseType.getType())) { effectiveResponseType = MediaType.APPLICATION_OCTET_STREAM_TYPE; } else { throw new NotAcceptableException(); } } responseContext.setMediaType(effectiveResponseType); } return responseContext; } });
final OutputStream origStream = responseContext.getEntityStream(); final OutputStream writtenStream = requestContext.getWorkers().writeTo( t, t.getClass(), getType(), responseContext.getEntityAnnotations(), responseContext.getMediaType(), responseContext.getHeaders(), requestContext.getPropertiesDelegate(), origStream, responseContext.setEntityStream(writtenStream); responseContext.commitStream();
@Override public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse context) { response.setStatusType(context.getStatusInfo()); response.getHeaders().putAll(context.getStringHeaders()); return response.getEntityOutputStream(); }
/** * Provides response status captured when * {@link #writeResponseStatusAndHeaders(long, org.glassfish.jersey.server.ContainerResponse)} has been invoked. * The method will block if the write method has not been called yet. * * @return response status */ public int getResponseStatus() { return getResponseContext().getStatus(); }