Java Code Examples for org.glassfish.jersey.server.ContainerResponse#getStatus()

The following examples show how to use org.glassfish.jersey.server.ContainerResponse#getStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpHandlerContainer.java    From metrics with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: JerseyTags.java    From micrometer with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code uri} tag based on the URI of the given {@code event}. Uses the
 * {@link ExtendedUriInfo#getMatchedTemplates()} if
 * available. {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND} for 404 responses.
 * @param event the request event
 * @return the uri tag derived from the request event
 */
public static Tag uri(RequestEvent event) {
    ContainerResponse response = event.getContainerResponse();
    if (response != null) {
        int status = response.getStatus();
        if (isRedirection(status)) {
            return URI_REDIRECTION;
        }
        if (status == 404) {
            return URI_NOT_FOUND;
        }
    }
    String matchingPattern = getMatchingPattern(event);
    if (matchingPattern.equals("/")) {
        return URI_ROOT;
    }
    return Tag.of("uri", matchingPattern);
}
 
Example 3
Source File: TracingApplicationEventListener.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public int statusCode() {
  ContainerResponse response = event.getContainerResponse();
  if (response != null) return response.getStatus();

  Throwable error = event.getException();
  // For example, if thrown in an async controller
  if (error instanceof MappableException && error.getCause() != null) {
    error = error.getCause();
  }
  if (error instanceof WebApplicationException) {
    return ((WebApplicationException) error).getResponse().getStatus();
  }
  return 0;
}