@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()); } }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
/** * <p> * Return the {@link NIOWriter} associated with this {@link Response}. * </p> * * By default the returned {@link NIOWriter} will work as blocking * {@link java.io.Writer}, but it will be possible to call {@link NIOWriter#canWrite()} or * {@link NIOWriter#notifyCanWrite(org.glassfish.grizzly.WriteHandler)} to * avoid blocking. * * @throws IllegalStateException if {@link #getOutputStream()} or * {@link #getNIOOutputStream()} were already invoked. */ public Writer getWriter() { return getNIOWriter(); }
final NIOWriter out = response.getNIOWriter();
replyInfo -> { response.setCharacterEncoding("utf-8"); try (NIOWriter out = response.getNIOWriter()) { response.setContentType("application/json"); response.setContentLength(replyInfo._1.length());