/** * Returns the response stream if it exists, null otherwise. * * @return The response stream if it exists, null otherwise. */ @Override public OutputStream getResponseEntityStream() { try { return getResponse().getOutputStream(); } catch (IOException e) { return null; } }
getResponse().addHeader(header.getName(), header.getValue()); getResponse().sendError(getStatusCode(), getReasonPhrase()); } catch (IOException ioe) { getLogger().log(Level.WARNING, getResponse().setStatus(getStatusCode()); contentLengthHeader = header; } else { getResponse() .addHeader(header.getName(), header.getValue()); getResponse().addHeader(contentLengthHeader.getName(), contentLengthHeader.getValue());
if (request instanceof HttpRequest && ((HttpRequest) request).getHttpCall() instanceof ServletCall) { ServletCall httpCall = (ServletCall) ((HttpRequest) request).getHttpCall(); // fetch the HTTP dispatcher RequestDispatcher dispatcher = httpCall.getRequest().getRequestDispatcher("representation.jsp"); HttpServletRequest proxyReq = new HttpServletRequestWrapper(httpCall.getRequest()); // Overload the http response stream to grab the JSP output into a dedicated proxy buffer // The BufferedServletResponseWrapper is a custom response wrapper that 'hijacks' the // output of the JSP engine and stores it on the side instead of forwarding it to the original // HTTP response. // This is needed to avoid having the JSP engine mess with the actual HTTP stream of the // current request, which must stay under the control of the restlet engine. BufferedServletResponseWrapper proxyResp = new BufferedServletResponseWrapper(httpCall.getResponse()); // Add any objects to be encoded in the http request scope proxyReq.setAttribute("myobjects", someObjects); // Actual JSP encoding dispatcher.include(proxyReq, proxyResp); // Return the content of the proxy buffer Representation rep = new InputRepresentation(proxyResp.toInputStream(),someMediaType);