duminică, 29 martie 2015

[OmniFaces utilities (2.0)] Get HTTP servlet response / response buffer size / response character encoding


[OmniFaces utilities] The getResponse() method returns the HTTP servlet response.
[OmniFaces utilities] The getResponseBufferSize() method returns the HTTP response buffer size. If Facelets is used and the javax.faces.FACELETS_BUFFER_SIZE context parameter is been set, then it's the context parameter value which will be returned. Otherwise it returns the implementation independent default value, which is 1024 in Mojarra.
[OmniFaces utilities] The getResponseCharacterEncoding() method returns the HTTP response character encoding.

Method Faces#getResponse() - returns the HTTP servlet response
See also: Faces#getContext()

Method Faces#getResponseBufferSize() - returns the HTTP response buffer size
See also: Faces#getContext()

Method Faces#getResponseCharacterEncoding() - returns the HTTP response character encoding
See also: Faces#getContext()
Usage:

The HTTP servlet response can be obtain via Faces#getResponse(), as below:

import org.omnifaces.util.Faces;
import javax.servlet.http.HttpServletResponse;
...
HttpServletResponse response = Faces.getResponse();
// further, invoke HttpServletResponse methods

The HTTP servlet response buffer size can be obtain via Faces#getResponseBufferSize(), as below:

import org.omnifaces.util.Faces;
...
// e.g. 8192
int bufferSize = Faces.getResponseBufferSize();

Or, you can achieve this via Faces#getResponse(), as:

import org.omnifaces.util.Faces;
import javax.servlet.http.HttpServletResponse;
...
HttpServletResponse response = Faces.getResponse();
int bufferSize = response.getBufferSize();

The HTTP servlet response character encoding can be obtain via Faces#getResponseCharacterEncoding(), as below:

import org.omnifaces.util.Faces;
...
// e.g. ISO-8859-1
String characterEncoding = Faces.getResponseCharacterEncoding();

Or, you can achieve this via Faces#getResponse(), as:
import org.omnifaces.util.Faces;
import javax.servlet.http.HttpServletResponse;
...
HttpServletResponse response = Faces.getResponse();
String characterEncoding = response.getCharacterEncoding();

Niciun comentariu:

Trimiteți un comentariu