Java Code Examples for net.lightbody.bmp.util.BrowserMobHttpUtil#getContentAsString()
The following examples show how to use
net.lightbody.bmp.util.BrowserMobHttpUtil#getContentAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 5 votes |
protected void captureResponseContent(HttpResponse httpResponse, byte[] fullMessage) { // force binary if the content encoding is not supported boolean forceBinary = false; String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in response from {}. Content will be treated as {}", originalRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } if (responseCaptureFilter.isResponseCompressed() && !responseCaptureFilter.isDecompressionSuccessful()) { log.warn("Unable to decompress content with encoding: {}. Contents will be encoded as base64 binary data.", responseCaptureFilter.getContentEncoding()); forceBinary = true; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP response from {}. Content will not be captured in HAR.", contentType, originalRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents from {}", charset, originalRequest.getUri()); } if (!forceBinary && BrowserMobHttpUtil.hasTextualContent(contentType)) { String text = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getResponse().getContent().setText(text); } else if (dataToCapture.contains(CaptureType.RESPONSE_BINARY_CONTENT)) { harEntry.getResponse().getContent().setText(BaseEncoding.base64().encode(fullMessage)); harEntry.getResponse().getContent().setEncoding("base64"); } harEntry.getResponse().getContent().setSize(fullMessage.length); }
Example 2
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 5 votes |
protected void captureResponseContent(HttpResponse httpResponse, byte[] fullMessage) { // force binary if the content encoding is not supported boolean forceBinary = false; String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in response from {}. Content will be treated as {}", originalRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } if (responseCaptureFilter.isResponseCompressed() && !responseCaptureFilter.isDecompressionSuccessful()) { log.warn("Unable to decompress content with encoding: {}. Contents will be encoded as base64 binary data.", responseCaptureFilter.getContentEncoding()); forceBinary = true; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP response from {}. Content will not be captured in HAR.", contentType, originalRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents from {}", charset, originalRequest.getUri()); } if (!forceBinary && BrowserMobHttpUtil.hasTextualContent(contentType)) { String text = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getResponse().getContent().setText(text); } else if (dataToCapture.contains(CaptureType.RESPONSE_BINARY_CONTENT)) { harEntry.getResponse().getContent().setText(BaseEncoding.base64().encode(fullMessage)); harEntry.getResponse().getContent().setEncoding("base64"); } harEntry.getResponse().getContent().setSize(fullMessage.length); }
Example 3
Source File: HarCaptureFilter.java From CapturePacket with MIT License | 4 votes |
protected void captureRequestContent(HttpRequest httpRequest, byte[] fullMessage) { if (fullMessage.length == 0) { return; } String contentType = HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in request to {}. Content will be treated as {}", httpRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } HarPostData postData = new HarPostData(); harEntry.getRequest().setPostData(postData); postData.setMimeType(contentType); boolean urlEncoded; if (contentType.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED)) { urlEncoded = true; } else { urlEncoded = false; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP request to {}. Content will not be captured in HAR.", contentType, httpRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents to {}", charset, httpRequest.getUri()); } if (urlEncoded) { String textContents = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(textContents, charset, false); ImmutableList.Builder<HarPostDataParam> paramBuilder = ImmutableList.builder(); for (Map.Entry<String, List<String>> entry : queryStringDecoder.parameters().entrySet()) { for (String value : entry.getValue()) { paramBuilder.add(new HarPostDataParam(entry.getKey(), value)); } } harEntry.getRequest().getPostData().setParams(paramBuilder.build()); } else { //TODO: implement capture of files and multipart form data // not URL encoded, so let's grab the body of the POST and capture that String postBody = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getRequest().getPostData().setText(postBody); } }
Example 4
Source File: HarCaptureFilter.java From AndroidHttpCapture with MIT License | 4 votes |
protected void captureRequestContent(HttpRequest httpRequest, byte[] fullMessage) { if (fullMessage.length == 0) { return; } String contentType = HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in request to {}. Content will be treated as {}", httpRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE); contentType = BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } HarPostData postData = new HarPostData(); harEntry.getRequest().setPostData(postData); postData.setMimeType(contentType); boolean urlEncoded; if (contentType.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED)) { urlEncoded = true; } else { urlEncoded = false; } Charset charset; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentType); } catch (UnsupportedCharsetException e) { log.warn("Found unsupported character set in Content-Type header '{}' in HTTP request to {}. Content will not be captured in HAR.", contentType, httpRequest.getUri(), e); return; } if (charset == null) { // no charset specified, so use the default -- but log a message since this might not encode the data correctly charset = BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; log.debug("No charset specified; using charset {} to decode contents to {}", charset, httpRequest.getUri()); } if (urlEncoded) { String textContents = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(textContents, charset, false); ImmutableList.Builder<HarPostDataParam> paramBuilder = ImmutableList.builder(); for (Map.Entry<String, List<String>> entry : queryStringDecoder.parameters().entrySet()) { for (String value : entry.getValue()) { paramBuilder.add(new HarPostDataParam(entry.getKey(), value)); } } harEntry.getRequest().getPostData().setParams(paramBuilder.build()); } else { //TODO: implement capture of files and multipart form data // not URL encoded, so let's grab the body of the POST and capture that String postBody = BrowserMobHttpUtil.getContentAsString(fullMessage, charset); harEntry.getRequest().getPostData().setText(postBody); } }