public void writeJson (Response response, Object object) throws IOException { mapper.writeValue(response.getOutputStream(), object); }
OutputStream os = wr.response.getOutputStream(); mapper.writeValue(os, tasks); os.close();
OutputStream out = response.getOutputStream(); mapper.writeValue(out, tasks); response.resume();
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); } }
OutputStream os = response.getOutputStream(); mapper.writeValue(os, ret); os.close(); suspendedProducerResponse.getOutputStream()); } catch (IOException ioex) {
@Override public OutputStream getOutputStream() { return r.getOutputStream(); }
@Override public void sendError(Status status, String message) { try { r.sendError(status.code, message); }catch(java.lang.IllegalStateException e) { log.error("Failed to send error, response already commited", e.getMessage()); } catch (IOException ex) { log.error("Failed to send error", ex); } try { r.getOutputStream().close(); log.info("Closed outputstream after sendError"); } catch (Throwable e) { log.warn("Failed to close outputstream after sendError"); } }
/** * Writes bytes content to response */ public static Action bytesContent(final byte[] content) { return new Action(response -> { response.setContentLength(content.length); try { response.getOutputStream().write(content); } catch (IOException e) { throw new RuntimeException("Can not write resource content for restito stubbing."); } return response; }); }
@NotNull @Override public OutputStream getOutput() throws IOException { response.setStatus(status); if (responseHeaders != null) { for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) { String name = entry.getKey(); if (name == null) { continue; } if (name.equalsIgnoreCase("Content-Type") || name.equalsIgnoreCase("Content-Length")) { continue; // ignore headers that interfere with the operation } for (String value : entry.getValue()) { response.addHeader(name, value); } } } return response.getOutputStream(); }
private void handleResourceRequest(Request req, Response res) throws IOException { String resourcePath = RESOURCE_PACKAGE + req.getRequestURI(); ClassLoader loader = AdminConsoleAdapter.class.getClassLoader(); InputStream in = null; try { in = loader.getResourceAsStream(resourcePath); if (in == null) { logger.log(Level.WARNING, KernelLoggerInfo.consoleResourceNotFound, resourcePath); return; } byte[] buf = new byte[512]; ByteArrayOutputStream baos = new ByteArrayOutputStream(512); for (int i = in.read(buf); i != -1; i = in.read(buf)) { baos.write(buf, 0, i); } String contentType = getContentType(resourcePath); if (contentType != null) { res.setContentType(contentType); } res.setContentLength(baos.size()); OutputStream out = res.getOutputStream(); baos.writeTo(out); out.flush(); } finally { if (in != null) { in.close(); } } }
int suffixIndex = uri.lastIndexOf('.'); String fileType = uri.substring(suffixIndex); OutputStream outStream = response.getOutputStream(); try { String[] coords = uri.substring(1, suffixIndex).split("[,;]");
} catch (IllegalStateException ise1) { try { getOutputStream().write(sb.toString().getBytes( org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET)); } catch (IllegalStateException ise2) {
} catch (IllegalStateException ise1) { try { getOutputStream().write(sb.toString().getBytes( org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET)); } catch (IllegalStateException ise2) {
} catch (IllegalStateException ise1) { try { getOutputStream().write(sb.toString().getBytes( org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET)); } catch (IllegalStateException ise2) {
} catch (IllegalStateException ise1) { try { getOutputStream().write(sb.toString().getBytes( org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARSET)); } catch (IllegalStateException ise2) {
private void reportAuthFailure(final Response res, final ActionReport report, final String msgKey, final String msg, final int httpStatus, final String headerName, final String headerValue) throws IOException { report.setActionExitCode(ActionReport.ExitCode.FAILURE); final String messageForResponse = adminStrings.getLocalString(msgKey, msg); report.setMessage(messageForResponse); report.setActionDescription("Authentication error"); res.setStatus(httpStatus, messageForResponse); if (headerName != null) { res.setHeader(headerName, headerValue); } res.setContentType(report.getContentType()); report.writeReport(res.getOutputStream()); res.getOutputStream().flush(); res.finish(); }
@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); } }
@Override public OutputStream writeStatusAndHeaders(final long contentLength, final ContainerResponse cResponse) throws IOException { final javax.ws.rs.core.Response.StatusType statusInfo = cResponse.getStatusType(); if (statusInfo.getReasonPhrase() == null) { response.setStatus(statusInfo.getStatusCode()); } else { response.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase()); } if (contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (final Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) { for (final Object value : e.getValue()) { response.addHeader(e.getKey(), ContainerResponse.getHeaderValue(value)); } } final String contentType = response.getHeader("Content-Type"); if (contentType != null) { response.setContentType(contentType); } return response.getOutputStream(); } }
@Override public OutputStream writeStatusAndHeaders(final long contentLength, final ContainerResponse cResponse) throws IOException { final javax.ws.rs.core.Response.StatusType statusInfo = cResponse.getStatusType(); if (statusInfo.getReasonPhrase() == null) { response.setStatus(statusInfo.getStatusCode()); } else { response.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase()); } if (contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (final Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) { for (final Object value : e.getValue()) { response.addHeader(e.getKey(), ContainerResponse.getHeaderValue(value)); } } final String contentType = response.getHeader("Content-Type"); if (contentType != null) { response.setContentType(contentType); } return response.getOutputStream(); } }