/** * Retrieves the contents of this message as a String, decoded according to the message's Content-Type header. This method caches * the contents, so repeated calls to this method should not incur a penalty; however, modifications to the message contents * outside of this class will result in stale data returned from this method. * * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if the character set declared in the message is not supported on this platform */ public String getTextContents() throws java.nio.charset.UnsupportedCharsetException { // avoid re-extracting the contents if this method is called repeatedly if (textContents == null) { textContents = HttpObjectUtil.extractHttpEntityBody(httpMessage); } return textContents; }
/** * Extracts the entity body from a FullHttpMessage, according to the character set in the message's Content-Type header. If the Content-Type * header is not present or does not specify a charset, assumes the ISO-8859-1 character set (see {@link BrowserMobHttpUtil#DEFAULT_HTTP_CHARSET}). * * @param httpMessage HTTP message to extract entity body from * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if there is a charset specified in the content-type header, but it is not supported */ public static String extractHttpEntityBody(FullHttpMessage httpMessage) { Charset charset; try { charset = getCharsetFromMessage(httpMessage); } catch (UnsupportedCharsetException e) { // the declared character set is not supported, so it is impossible to decode the contents of the message. log an error and throw an exception // to alert the client code. java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE); log.error("Cannot retrieve text contents of message because HTTP message declares a character set that is not supported on this platform. Content type header: {}.", contentTypeHeader, cause); throw cause; } return extractHttpEntityBody(httpMessage, charset); }
/** * Retrieves the contents of this message as a String, decoded according to the message's Content-Type header. This method caches * the contents, so repeated calls to this method should not incur a penalty; however, modifications to the message contents * outside of this class will result in stale data returned from this method. * * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if the character set declared in the message is not supported on this platform */ public String getTextContents() throws java.nio.charset.UnsupportedCharsetException { // avoid re-extracting the contents if this method is called repeatedly if (textContents == null) { textContents = HttpObjectUtil.extractHttpEntityBody(httpMessage); } return textContents; }
/** * Retrieves the contents of this message as a String, decoded according to the message's Content-Type header. This method caches * the contents, so repeated calls to this method should not incur a penalty; however, modifications to the message contents * outside of this class will result in stale data returned from this method. * * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if the character set declared in the message is not supported on this platform */ public String getTextContents() throws java.nio.charset.UnsupportedCharsetException { // avoid re-extracting the contents if this method is called repeatedly if (textContents == null) { textContents = HttpObjectUtil.extractHttpEntityBody(httpMessage); } return textContents; }
/** * Extracts the entity body from a FullHttpMessage, according to the character set in the message's Content-Type header. If the Content-Type * header is not present or does not specify a charset, assumes the ISO-8859-1 character set (see {@link BrowserMobHttpUtil#DEFAULT_HTTP_CHARSET}). * * @param httpMessage HTTP message to extract entity body from * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if there is a charset specified in the content-type header, but it is not supported */ public static String extractHttpEntityBody(FullHttpMessage httpMessage) { Charset charset; try { charset = getCharsetFromMessage(httpMessage); } catch (UnsupportedCharsetException e) { // the declared character set is not supported, so it is impossible to decode the contents of the message. log an error and throw an exception // to alert the client code. java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE); log.error("Cannot retrieve text contents of message because HTTP message declares a character set that is not supported on this platform. Content type header: {}.", contentTypeHeader, cause); throw cause; } return extractHttpEntityBody(httpMessage, charset); }
/** * Extracts the entity body from a FullHttpMessage, according to the character set in the message's Content-Type header. If the Content-Type * header is not present or does not specify a charset, assumes the ISO-8859-1 character set (see {@link BrowserMobHttpUtil#DEFAULT_HTTP_CHARSET}). * * @param httpMessage HTTP message to extract entity body from * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if there is a charset specified in the content-type header, but it is not supported */ public static String extractHttpEntityBody(FullHttpMessage httpMessage) { Charset charset; try { charset = getCharsetFromMessage(httpMessage); } catch (UnsupportedCharsetException e) { // the declared character set is not supported, so it is impossible to decode the contents of the message. log an error and throw an exception // to alert the client code. java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE); log.error("Cannot retrieve text contents of message because HTTP message declares a character set that is not supported on this platform. Content type header: {}.", contentTypeHeader, cause); throw cause; } return extractHttpEntityBody(httpMessage, charset); }