FileDocCategorySizeDatePackage
HtmlHelper.javaAPI DocGlassfish v2 API5658Fri May 04 22:37:04 BST 2007com.sun.enterprise.web.connector.grizzly

HtmlHelper

public class HtmlHelper extends Object
Utility class used to generate HTML pages.
author
Jean-Francois Arcand

Fields Summary
private static final String
CSS
private static CharBuffer
reponseBuffer
CharBuffer used to store the HTML response, containing the headers and the body of the response.
private static CharsetEncoder
encoder
Encoder used to encode the HTML response
private static String
NEWLINE
HTTP end line.
public static final String
OK
HTTP OK header
public static final String
BAD_REQUEST
HTTP Bas Request
Constructors Summary
Methods Summary
private static voidappendHeaderValue(java.lang.String name, java.lang.String value)
Utility to add headers to the HTTP response.

        reponseBuffer.put(name);
        reponseBuffer.put(": ");
        reponseBuffer.put(value);
        reponseBuffer.put(NEWLINE);
    
public static synchronized java.nio.ByteBuffergetErrorPage(java.lang.String message, java.lang.String code)
When Grizzlu has reached its connection-queue pool limits, an HTML error pages will to be returned to the clients.

return
A ByteBuffer containings the HTTP response.

 
    
                                   
        
                  
        String body = prepareBody(message);
        reponseBuffer.clear();
        reponseBuffer.put(code);
        appendHeaderValue("Content-Type", "text/html");
        appendHeaderValue("Content-Length", body.getBytes().length + "");
        appendHeaderValue("Date", new Date().toString());
        appendHeaderValue("Connection", "Close");
        appendHeaderValue("Server", SelectorThread.SERVER_NAME);
        reponseBuffer.put(NEWLINE);
        reponseBuffer.put(body);
        reponseBuffer.flip();
        return encoder.encode(reponseBuffer);
    
private static java.lang.StringprepareBody(java.lang.String message)
Prepare the HTTP body containing the error messages.

        StringBuffer sb = new StringBuffer();

        sb.append("<html><head><title>");
        sb.append(SelectorThread.SERVER_NAME);
        sb.append("</title>");
        sb.append("<style><!--");
        sb.append(CSS);
        sb.append("--></style> ");
        sb.append("</head><body>");
        sb.append("<h1>");
        sb.append(message);
        sb.append("</h1>");
        sb.append("<HR size=\"1\" noshade>");
        sb.append("<h3>").append(SelectorThread.SERVER_NAME)
            .append("</h3>");
        sb.append("</body></html>");
        return sb.toString();