@Override public void service(Request req, Response resp) throws Exception { try { OTPRequest oreq = new OTPRequest(req, graph); Object result = handlers.get(oreq.action).handle(oreq); ObjectMapper mapper; if (oreq.sfmt == SerializeFormat.XML) { resp.setContentType("application/xml"); mapper = xmlMapper; } else { resp.setContentType("application/json"); mapper = jsonMapper; } resp.setStatus(200); mapper.writeValue(resp.getNIOOutputStream(), result); } catch (Exception ex) { resp.setStatus(500); resp.setContentType("text/plain"); resp.getNIOWriter().write("Error: " + ex.toString()); } }
response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode()); } else { response.setStatus(HttpStatus.OK_200); response.setContentType(mediaType); ReaderWriter.writeTo(fileStream, response.getOutputStream());
@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); } }
response.setStatus(HttpStatus.BAD_REQUEST_400); response.setDetailMessage("path should have at least one part"); response.setStatus(HttpStatus.OK_200); return; } else if (request.getMethod() == Method.GET && "status".equals(pathComponents[1])) { response.setStatus(HttpStatus.NOT_FOUND_404); response.setDetailMessage("no job IDs were found"); response.setStatus(HttpStatus.OK_200); OutputStream os = response.getOutputStream(); mapper.writeValue(os, ret); for (AnalystClusterRequest task : tasks) { if (task.jobId != exemplar.jobId || task.graphId != exemplar.graphId) { response.setStatus(HttpStatus.BAD_REQUEST_400); response.setDetailMessage( "All tasks must be for the same graph and job."); response.setStatus(HttpStatus.ACCEPTED_202); } else { response.setStatus(HttpStatus.NOT_FOUND_404); response.setDetailMessage( "Context not found; should be either 'jobs' or 'priority'"); Response suspendedProducerResponse = broker.deletePriorityTask(taskId); if (suspendedProducerResponse == null) { response.setStatus(HttpStatus.NOT_FOUND_404);
@Override @SuppressWarnings("MagicNumber") public void failure(final Throwable error) { try { if (!grizzlyResponse.isCommitted()) { try { if (configSetStatusOverSendError) { grizzlyResponse.reset(); grizzlyResponse.setStatus(500, "Request failed."); } else { grizzlyResponse.sendError(500, "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... logger.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException( LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(500, "Request failed."), ex); } } } finally { logger.debugLog("{0} - failure(...) called", name); rethrow(error); } }
@Override public void service(Request rqst, Response rspns) throws Exception { rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found"); rspns.getWriter().write("404: not found"); } });
/** * Set the HTTP status to be returned with this response. * * @param status The new HTTP status */ public void setStatus(int status) { setStatus(status, null); }
/** * Set the HTTP status to be returned with this response. * * @param status The new HTTP status */ public void setStatus(int status) { setStatus(status, null); }
/** * {@inheritDoc} */ @Override public void setStatus(int sc) { if (isCommitted()) return; response.setStatus(sc); }
@Override public void acknowledge() throws IOException { if (isAcknowledged) { throw new IllegalStateException("Already acknowledged"); } isAcknowledged = true; response.setStatus(HttpStatus.CONINTUE_100); response.sendAcknowledgement(); }
/** * Reset this response, and specify the values for the HTTP status code * and corresponding message. * * @exception IllegalStateException if this response has already been * committed */ public void reset(final int status, final String message) { reset(); setStatus(status, message); }
/** * {@inheritDoc} */ @Override public void setStatus(int sc, String sm) { if (isCommitted()) return; response.setStatus(sc, sm); }
@Override public void acknowledge() throws IOException { if (isAcknowledged) { throw new IllegalStateException("Already acknowledged"); } isAcknowledged = true; response.setStatus(HttpStatus.CONINTUE_100); response.sendAcknowledgement(); }
/** * Reset this response, and specify the values for the HTTP status code * and corresponding message. * * @exception IllegalStateException if this response has already been * committed */ public void reset(final int status, final String message) { reset(); setStatus(status, message); }
@Override public void onError(Throwable t) { logger.error("Error parsing request data", t); response.setStatus(400, "Bad request"); response.resume(); }
@Override public void onError(Throwable t) { LOGGER.log(Level.FINE, "[onError] ", t); response.setStatus(500, t.getMessage()); complete(true); }
/** * {@inheritDoc} */ @Override public void setStatus(int sc) { if (isCommitted()) return; response.setStatus(sc); }
protected void onTraceRequest(final Request request, final Response response) throws IOException { if (config.isTraceEnabled()) { HtmlHelper.writeTraceMessage(request, response); } else { response.setStatus(HttpStatus.METHOD_NOT_ALLOWED_405); response.setHeader(Header.Allow, "POST, GET, DELETE, OPTIONS, PUT, HEAD"); } }
protected void onTraceRequest(final Request request, final Response response) throws IOException { if (config.isTraceEnabled()) { HtmlHelper.writeTraceMessage(request, response); } else { response.setStatus(HttpStatus.METHOD_NOT_ALLOWED_405); response.setHeader(Header.Allow, "POST, GET, DELETE, OPTIONS, PUT, HEAD"); } }