@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { response.setCode(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setDescription(error.getMessage()); } } finally { logger.debugLog("failure(...) called"); commit(); rethrow(error); } }
@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 ? Status.getDescription(code) : statusInfo.getReasonPhrase(); response.setCode(code); response.setDescription(reason); if (contentLength != -1) { response.setContentLength(contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addValue(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
/** * This is used to set the text of the HTTP status line. * This should match the status code specified by the RFC. * * @param text the descriptive text message of the status */ public void setDescription(String text) { response.setDescription(text); }
/** * This is used to set the text of the HTTP status line. * This should match the status code specified by the RFC. * * @param text the descriptive text message of the status */ public void setDescription(String text) { response.setDescription(text); }
/** * This is used to set the text of the HTTP status line. * This should match the status code specified by the RFC. * * @param text the descriptive text message of the status */ public void setDescription(String text) { response.setDescription(text); }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { response.setCode(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setDescription(error.getMessage()); } } finally { logger.debugLog("failure(...) called"); commit(); rethrow(error); } }
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse cResponse) throws IOException { int code = cResponse.getStatus(); String text = Status.getDescription(code); String method = request.getMethod(); response.setCode(code); response.setDescription(text); if (!method.equalsIgnoreCase("HEAD") && contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) { for (Object value : e.getValue()) { response.setValue(e.getKey(), ContainerResponse.getHeaderValue(value)); } } return response.getOutputStream(); }
/** * This is used to respond to the client with a HTTP 101 response * to indicate that the WebSocket handshake succeeeded. Once this * response has been sent all traffic between the client and * server will be with WebSocket frames as defined by RFC 6455. */ private void accept() throws IOException { long time = System.currentTimeMillis(); String accept = token.create(); response.setStatus(Status.SWITCHING_PROTOCOLS); response.setDescription(UPGRADE); response.setValue(CONNECTION, UPGRADE); response.setDate(DATE, time); response.setValue(SEC_WEBSOCKET_ACCEPT, accept); response.setValue(UPGRADE, WEBSOCKET); String header = response.toString(); byte[] message = header.getBytes("UTF-8"); trace.trace(WRITE_HEADER, header); writer.write(message); writer.flush(); } }
/** * This is used to respond to the client with a HTTP 101 response * to indicate that the WebSocket handshake succeeeded. Once this * response has been sent all traffic between the client and * server will be with WebSocket frames as defined by RFC 6455. */ private void accept() throws IOException { long time = System.currentTimeMillis(); String accept = token.create(); response.setStatus(Status.SWITCHING_PROTOCOLS); response.setDescription(UPGRADE); response.setValue(CONNECTION, UPGRADE); response.setDate(DATE, time); response.setValue(SEC_WEBSOCKET_ACCEPT, accept); response.setValue(UPGRADE, WEBSOCKET); String header = response.toString(); byte[] message = header.getBytes("UTF-8"); trace.trace(WRITE_HEADER, header); writer.write(message); writer.flush(); } }
@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 ? Status.getDescription(code) : statusInfo.getReasonPhrase(); response.setCode(code); response.setDescription(reason); if (contentLength != -1) { response.setContentLength(contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addValue(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }