/** This could be improved at some day in the future * to also include a stack trace of the exceptions * @param message the error message to be sent * @return the HttpResponseImpl that this error belongs to */ protected static HttpResponseImpl createError(String message){ return createError(message, null); }
@Override public int getStatus() { return getCode(); }
/** * gets the content type that will be sent to the browser * * @return the content type (i.e. "text/html") */ public String getContentType() { return getHeader("Content-Type"); }
/** * resets the data to be sent to the browser with the response code and response * string * * @param code the code to be sent to the browser * @param responseString the response string to be sent to the browser */ public void reset(final int code, final String responseString) { setCode(code); setResponseString(responseString); initBody(); }
@Override public void setStatus(final int i, final String s) { setCode(i); setStatusMessage(s); }
/** * closes the message sent to the browser */ private void closeMessage() { setContentLengthHeader(); setCookieHeader(); }
/** * Takes care of sending the response line, headers and body * <p/> * HTTP/1.1 200 OK * Server: Netscape-Enterprise/3.6 SP3 * Date: Thu, 07 Jun 2001 17:30:42 GMT * Content-Type: text/html * Connection: close * * @param output the output to send the response to * @throws java.io.IOException if an exception is thrown */ protected void writeMessage(final OutputStream output, final boolean indent) throws IOException { flushBuffer(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos); closeMessage(); writeResponseLine(out); writeHeaders(out); writeBody(out, indent); out.flush(); output.write(baos.toByteArray()); output.flush(); }
private HttpResponseImpl process(final URI socketURI, final InputStream in) throws OpenEJBException { final HttpRequestImpl req = new HttpRequestImpl(socketURI); final HttpResponseImpl res = new HttpResponseImpl(); res.setRequest(req); } catch (final Throwable t) { res.setCode(400); res.setResponseString("Could not read the request"); try { res.getWriter().println(t.getMessage()); t.printStackTrace(res.getWriter()); } catch (final IOException e) {
private HttpResponseImpl process(URI socketURI, InputStream in) throws OpenEJBException { HttpRequestImpl req = new HttpRequestImpl(socketURI); HttpResponseImpl res = new HttpResponseImpl(); res.setRequest(req); } catch (Throwable t) { res.setCode(400); res.setResponseString("Could not read the request"); res.getPrintWriter().println(t.getMessage()); t.printStackTrace(res.getPrintWriter()); log.error("BAD REQUEST", t); throw new OpenEJBException("Could not read the request.\n" + t.getClass().getName() + ":\n" + t.getMessage(), t);
/** Creates a new HttpResponseImpl with user provided parameters * @param code the HTTP Response code, see <a href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a> * for these codes * @param responseString the response string to be sent back * @param contentType the content type to be sent back */ protected HttpResponseImpl(int code, String responseString, String contentType){ this.responseString = responseString; this.code = code; // Default headers setHeader("Server", getServerName()); setHeader("Connection","close"); setHeader("Content-Type",contentType); // create the body. initBody(); }
/** * takes care of processing requests and creating the webadmin ejb's * * @param in the input stream from the browser * @param out the output stream to the browser */ private void processRequest(URI socketURI, InputStream in, OutputStream out) { HttpResponseImpl response = null; try { response = process(socketURI, in); } catch (Throwable t) { response = HttpResponseImpl.createError(t.getMessage(), t); } finally { try { response.writeMessage(out); } catch (Throwable t2) { log.error("Could not write response", t2); } } }
/** * Creates a forbidden response to be sent to the browser using IP authentication * * @param ip the ip that is forbidden * @return the HttpResponseImpl that this error belongs to */ @SuppressWarnings("unused") protected static HttpResponseImpl createForbidden(final String ip) { final HttpResponseImpl res = new HttpResponseImpl(403, "Forbidden", "text/html"); final PrintWriter body; try { body = res.getWriter(); } catch (final IOException e) { // normally impossible return res; } body.println("<html>"); body.println("<body>"); body.println("<h3>Forbidden</h3>"); body.println("<br><br>"); // Add more text here // IP not allowed, etc. body.println("IP address: " + ip + " is not registered on this server, please contact your system administrator."); body.println("</body>"); body.println("</html>"); return res; }
@Override public void setStatus(final int i) { setCode(i); }
/** Creates a forbidden response to be sent to the browser using IP authentication * @param ip the ip that is forbidden * @return the HttpResponseImpl that this error belongs to */ protected static HttpResponseImpl createForbidden(String ip){ HttpResponseImpl res = new HttpResponseImpl(403, "Forbidden", "text/html"); PrintWriter body = res.getPrintWriter(); body.println("<html>"); body.println("<body>"); body.println("<h3>Forbidden</h3>"); body.println("<br><br>"); // Add more text here // IP not allowed, etc. body.println("IP address: " + ip + " is not registered on this server, please contact your system administrator."); body.println("</body>"); body.println("</html>"); return res; }
/** * resets the data to be sent to the browser */ public void reset() { initBody(); }
/** Takes care of sending the response line, headers and body * * HTTP/1.1 200 OK * Server: Netscape-Enterprise/3.6 SP3 * Date: Thu, 07 Jun 2001 17:30:42 GMT * Content-Type: text/html * Connection: close * @param output the output to send the response to * @throws java.io.IOException if an exception is thrown */ protected void writeMessage(OutputStream output) throws IOException{ ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); //DataOutput log = new DataOutputStream(System.out); //System.out.println("\nRESPONSE"); closeMessage(); // writeResponseLine(log); // writeHeaders(log); // writeBody(log); writeResponseLine(out); writeHeaders(out); writeBody(out); out.flush(); output.write(baos.toByteArray()); output.flush(); }
private HttpResponseImpl process(final Socket socket, final URI socketURI, final InputStream in) throws OpenEJBException { final HttpRequestImpl req = new HttpRequestImpl(socketURI); final HttpResponseImpl res = new HttpResponseImpl(); res.setRequest(req); } catch (Throwable t) { res.setCode(400); res.setResponseString("Could not read the request"); try { res.getWriter().println(t.getMessage()); t.printStackTrace(res.getWriter()); } catch (IOException e) {
/** * resets the data to be sent to the browser with the response code and response * string * * @param code the code to be sent to the browser * @param responseString the response string to be sent to the browser */ public void reset(final int code, final String responseString) { setCode(code); setResponseString(responseString); initBody(); }
/** * Creates a new HttpResponseImpl with user provided parameters * * @param code the HTTP Response code, see <a href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a> * for these codes * @param responseString the response string to be sent back * @param contentType the content type to be sent back */ protected HttpResponseImpl(final int code, final String responseString, final String contentType) { this.responseString = responseString; this.code = code; // Default headers setHeader("Server", getServerName()); setHeader("Connection", "close"); setHeader("Content-Type", contentType); // create the body. initBody(); }
/** * closes the message sent to the browser */ private void closeMessage() { setContentLengthHeader(); setCookieHeader(); }