public class HTTPResponseUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
getHTTPStatusString(int statusCode) |
static HTTPResponseHeader |
getResponseHeader(boolean secure)
Creates HTTP 204 "No Content" Header.
|
static HTTPResponseHeader |
getResponseHeader(int status,
boolean secure)
Returns the default HTTP response header for the given status code.
|
static HTTPResponseHeader |
handleResponse(java.io.InputStream in,
boolean secure) |
static void |
sendBadRequest(java.io.OutputStream out,
boolean secure,
java.lang.String note)
Sends an HTTP bad request.
|
static void |
sendCountinueResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
Sends default HTTP 100 Continue response.
|
static void |
sendDefaultDocument(java.io.OutputStream out,
boolean secure)
Sends the default document.
|
static void |
sendDefaultErrorDocument(java.io.OutputStream out,
boolean secure,
java.lang.String request)
Sends the default Error document.
|
static void |
sendHTTPVersionNotSupported(java.io.OutputStream out,
boolean secure,
java.lang.String note)
Sends an HTTP version not supported.
|
static void |
sendInternalServerError(java.io.OutputStream out,
boolean secure,
java.lang.String note)
Sends an HTTP bad request.
|
static void |
sendNoContentResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
Sends default HTTP 204 No Content response.
|
static void |
sendNotFoundResponse(java.io.OutputStream out,
boolean secure,
HTMLDocument document)
Sends default HTTP 404 Not Found response.
|
static void |
sendNotFoundResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
Sends default HTTP 404 Not Found response.
|
static void |
sendOKResponse(java.io.OutputStream out,
boolean secure,
HTMLDocument document)
Sends default HTTP 200 OK response.
|
static void |
sendOKResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
Sends default HTTP 200 OK response.
|
static void |
sendRedirect(java.io.OutputStream out,
URI request,
java.lang.String note)
Sends a HTTP redirect.
|
static boolean |
sendResource(java.io.OutputStream out,
boolean secure,
java.lang.String res,
ContentType type,
boolean chunked,
boolean trailer)
Sends the resource.
|
static void |
sendResponse(java.io.OutputStream out,
boolean secure,
int status,
HTMLDocument message)
Sends a byte array with correct HTTP response.
|
static void |
sendResponse(java.io.OutputStream out,
boolean secure,
int status,
java.lang.String message)
Sends a byte array with correct HTTP response.
|
static void |
sendResponse(java.io.OutputStream out,
byte[] message,
HTTPResponseHeader header)
Sends a byte array with correct HTTP response.
|
static void |
sendUnsupportedMediaType(java.io.OutputStream out,
boolean secure,
java.lang.String note)
Sends an HTTP unsupported media type
|
static java.io.OutputStream |
writeResponse(java.io.OutputStream out,
boolean secure,
int code,
ContentType type,
boolean chunked,
boolean trailer)
Writes an HTTP response header to the stream with given media type (e.g.
|
public static void sendCountinueResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
out - stream to work with.message - message body.public static void sendOKResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
out - stream to work with.message - message body.public static void sendOKResponse(java.io.OutputStream out,
boolean secure,
HTMLDocument document)
out - stream to work with.document - message document.public static void sendNoContentResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
out - stream to work with.message - message body.public static void sendNotFoundResponse(java.io.OutputStream out,
boolean secure,
HTMLDocument document)
out - stream to work with.document - message document.public static void sendNotFoundResponse(java.io.OutputStream out,
boolean secure,
java.lang.String message)
out - stream to work with.message - message body.public static void sendResponse(java.io.OutputStream out,
boolean secure,
int status,
java.lang.String message)
out - stream to work with.status - HTTP status code for the response.message - message body.public static void sendResponse(java.io.OutputStream out,
boolean secure,
int status,
HTMLDocument message)
out - stream to work with.status - HTTP status code for the response.message - message body.public static void sendResponse(java.io.OutputStream out,
byte[] message,
HTTPResponseHeader header)
out - stream to work with.message - message body.header - the HTTP response header. Please set the correct content length etc.public static void sendBadRequest(java.io.OutputStream out,
boolean secure,
java.lang.String note)
out - stream to work with.note - the error note.public static void sendInternalServerError(java.io.OutputStream out,
boolean secure,
java.lang.String note)
out - stream to work with.note - the error note.public static void sendHTTPVersionNotSupported(java.io.OutputStream out,
boolean secure,
java.lang.String note)
out - stream to work with.note - the error note.public static void sendUnsupportedMediaType(java.io.OutputStream out,
boolean secure,
java.lang.String note)
out - stream to work with.note - the error note.public static void sendRedirect(java.io.OutputStream out,
URI request,
java.lang.String note)
out - stream to work with.request - the request which was done.note - the error note.public static void sendDefaultErrorDocument(java.io.OutputStream out,
boolean secure,
java.lang.String request)
out - stream to work with.request - the request which was done.public static void sendDefaultDocument(java.io.OutputStream out,
boolean secure)
out - stream to work with.public static HTTPResponseHeader getResponseHeader(boolean secure)
public static HTTPResponseHeader getResponseHeader(int status, boolean secure)
status - the status code.public static java.lang.String getHTTPStatusString(int statusCode)
public static HTTPResponseHeader handleResponse(java.io.InputStream in, boolean secure) throws java.io.IOException, ProtocolException
java.io.IOExceptionProtocolExceptionpublic static java.io.OutputStream writeResponse(java.io.OutputStream out,
boolean secure,
int code,
ContentType type,
boolean chunked,
boolean trailer)
throws java.io.IOException
OutputStream MUST be used it should be ensured that the chunks are
written correctly.out - the output stream to write the HTTP request to.code - the HTTP response code.type - the internet media type.chunked - true if a special chunked output stream should be returned, false otherwise.trailer - true if the chunk trailer should be appended at the end, false otherwise.ChunkedOutputStream if chunked is true, the normal output stream otherwise.java.io.IOExceptionpublic static boolean sendResource(java.io.OutputStream out,
boolean secure,
java.lang.String res,
ContentType type,
boolean chunked,
boolean trailer)
out - stream to work with.res - resource to send.type - MIME type for this resource.chunked - if false the whole resource is loaded into memory before it is sent. if true
the resource is sent as chunked response, with out much memory usage.trailer - true if you want to send the OPTIONAL chunk trailer, false otherwise.true if the resource could be loaded and could be sent, false otherwise.