private WebResponseData webResponseData() throws IOException { List<NameValuePair> responseHeaders = responseHeaders(); int statusCode = (this.response.getRedirectedUrl() != null ? HttpStatus.MOVED_PERMANENTLY.value() : this.response.getStatus()); String statusMessage = statusMessage(statusCode); return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage, responseHeaders); }
@Before public void setup() throws Exception { request = new WebRequest(new URL("http://localhost/")); WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.emptyList()); expectedResponse = new WebResponse(data, request, 100L); webConnection = new DelegatingWebConnection(defaultConnection, new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2)); }
private WebResponseData webResponseData() throws IOException { List<NameValuePair> responseHeaders = responseHeaders(); HttpStatus status = this.exchangeResult.getStatus(); return new WebResponseData(this.exchangeResult.getResponseBodyContent(), status.value(), status.getReasonPhrase(), responseHeaders); }
private static WebResponseData getWebResponseData(final byte[] data, final String contentType) { final List<NameValuePair> compiledHeaders = new ArrayList<NameValuePair>(); compiledHeaders.add(new NameValuePair("Content-Type", contentType)); return new WebResponseData(data, HttpStatus.SC_OK, "OK", compiledHeaders); }
WebResponseData asWebResponseData() { final byte[] content; if (byteContent_ != null) { content = byteContent_; } else if (stringContent_ == null) { content = new byte[] {}; } else { content = TextUtil.stringToByteArray(stringContent_, charset_); } return new WebResponseData(content, statusCode_, statusMessage_, headers_); }
private static WebResponseData getWebResponseData(final byte[] data, final String contentType) { final List<NameValuePair> compiledHeaders = new ArrayList<NameValuePair>(); compiledHeaders.add(new NameValuePair("Content-Type", contentType)); return new WebResponseData(data, HttpStatus.SC_OK, "OK", compiledHeaders); }
private static WebResponseData getWebResponseData(final byte[] data, final String contentType) { final List<NameValuePair> compiledHeaders = new ArrayList<NameValuePair>(); compiledHeaders.add(new NameValuePair("Content-Type", contentType)); return new WebResponseData(data, HttpStatus.SC_OK, "OK", compiledHeaders); }
WebResponseData asWebResponseData() { final byte[] content; if (byteContent_ != null) { content = byteContent_; } else if (stringContent_ == null) { content = new byte[] {}; } else { content = TextUtil.stringToByteArray(stringContent_, charset_); } return new WebResponseData(content, statusCode_, statusMessage_, headers_); }
/** * Helper method for constructors. Converts the specified string into {@link WebResponseData} * with other defaults specified. * * @param contentString the string to be converted to a <tt>WebResponseData</tt> * @return a simple <tt>WebResponseData</tt> with defaults specified */ private static WebResponseData getWebResponseData(final String contentString, final Charset charset) { final byte[] content = TextUtil.stringToByteArray(contentString, charset); final List<NameValuePair> compiledHeaders = new ArrayList<>(); compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, "text/html; charset=" + charset)); return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders); }
/** * Helper method for constructors. Converts the specified string into {@link WebResponseData} * with other defaults specified. * * @param contentString the string to be converted to a <tt>WebResponseData</tt> * @return a simple <tt>WebResponseData</tt> with defaults specified */ private static WebResponseData getWebResponseData(final String contentString, final String charset) { final byte[] content = TextUtil.stringToByteArray(contentString, charset); final List<NameValuePair> compiledHeaders = new ArrayList<NameValuePair>(); compiledHeaders.add(new NameValuePair("Content-Type", "text/html")); return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders); }
/** * Helper method for constructors. Converts the specified string into {@link WebResponseData} * with other defaults specified. * * @param contentString the string to be converted to a <tt>WebResponseData</tt> * @return a simple <tt>WebResponseData</tt> with defaults specified */ private static WebResponseData getWebResponseData(final String contentString, final Charset charset) { final byte[] content = TextUtil.stringToByteArray(contentString, charset); final List<NameValuePair> compiledHeaders = new ArrayList<>(); compiledHeaders.add(new NameValuePair(HttpHeader.CONTENT_TYPE, "text/html; charset=" + charset)); return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders); }
/** * Helper method for constructors. Converts the specified string into {@link WebResponseData} * with other defaults specified. * * @param contentString the string to be converted to a <tt>WebResponseData</tt> * @return a simple <tt>WebResponseData</tt> with defaults specified */ private static WebResponseData getWebResponseData(final String contentString, final String charset) { final byte[] content = TextUtil.stringToByteArray(contentString, charset); final List<NameValuePair> compiledHeaders = new ArrayList<NameValuePair>(); compiledHeaders.add(new NameValuePair("Content-Type", "text/html")); return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders); }
/** * Helper method for constructors. Converts the specified string into {@link WebResponseData} * with other defaults specified. * * @param contentString the string to be converted to a <tt>WebResponseData</tt> * @return a simple <tt>WebResponseData</tt> with defaults specified */ private static WebResponseData getWebResponseData(final String contentString, final String charset) { final byte[] content = TextUtil.stringToByteArray(contentString, charset); final List<NameValuePair> compiledHeaders = new ArrayList<NameValuePair>(); compiledHeaders.add(new NameValuePair("Content-Type", "text/html")); return new WebResponseData(content, HttpStatus.SC_OK, "OK", compiledHeaders); }
static WebResponseData adaptResponse(InProcResponse inProcResponse) throws IOException { final List<NameValuePair> headers = new ArrayList<NameValuePair>(); Set<String> headerNames = inProcResponse.getHeaderNames(); for (String headerName : headerNames) { String headerValue = inProcResponse.getHeader(headerName); headers.add(new NameValuePair(headerName, headerValue)); } String content = inProcResponse.getContent(); if (content == null) content = ""; return new WebResponseData(content.getBytes(inProcResponse.getCharacterEncoding()), inProcResponse.getStatus(), inProcResponse.getReason(), headers); }
static WebResponseData adaptResponse(InProcResponse inProcResponse) { final List<NameValuePair> headers = new ArrayList<>(); Collection<String> headerNames = inProcResponse.getHeaderNames(); for (String headerName : headerNames) { String headerValue = inProcResponse.getHeader(headerName); headers.add(new NameValuePair(headerName, headerValue)); } return new WebResponseData(inProcResponse.getContentBytes(), inProcResponse.getStatus(), inProcResponse.getReason(), headers); }
private WebResponseData webResponseData() throws IOException { List<NameValuePair> responseHeaders = responseHeaders(); int statusCode = (this.response.getRedirectedUrl() != null ? HttpStatus.MOVED_PERMANENTLY.value() : this.response.getStatus()); String statusMessage = statusMessage(statusCode); return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage, responseHeaders); }
private WebResponseData webResponseData() throws IOException { List<NameValuePair> responseHeaders = responseHeaders(); int statusCode = (this.response.getRedirectedUrl() != null ? HttpStatus.MOVED_PERMANENTLY.value() : this.response.getStatus()); String statusMessage = statusMessage(statusCode); return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage, responseHeaders); }
/** * Builds a WebResponse with new content, preserving all other information. * @param wr the web response to adapt * @param newContent the new content to place in the response * @return a web response with the new content * @throws IOException if an encoding problem occurred */ protected WebResponse replaceContent(final WebResponse wr, final String newContent) throws IOException { final byte[] body = newContent.getBytes(wr.getContentCharset()); final WebResponseData wrd = new WebResponseData(body, wr.getStatusCode(), wr.getStatusMessage(), wr.getResponseHeaders()); return new WebResponse(wrd, wr.getWebRequest().getUrl(), wr.getWebRequest().getHttpMethod(), wr.getLoadTime()); }
/** * Builds a WebResponse with new content, preserving all other information. * @param wr the web response to adapt * @param newContent the new content to place in the response * @return a web response with the new content * @throws IOException if an encoding problem occurred */ protected WebResponse replaceContent(final WebResponse wr, final String newContent) throws IOException { final byte[] body = newContent.getBytes(wr.getContentCharset()); final WebResponseData wrd = new WebResponseData(body, wr.getStatusCode(), wr.getStatusMessage(), wr.getResponseHeaders()); return new WebResponseImpl(wrd, wr.getRequestSettings().getUrl(), wr.getRequestSettings().getHttpMethod(), wr.getLoadTime()); }
/** * Builds a WebResponse with new content, preserving all other information. * @param wr the web response to adapt * @param newContent the new content to place in the response * @return a web response with the new content * @throws IOException if an encoding problem occurred */ protected WebResponse replaceContent(final WebResponse wr, final String newContent) throws IOException { final byte[] body = newContent.getBytes(wr.getContentCharset()); final WebResponseData wrd = new WebResponseData(body, wr.getStatusCode(), wr.getStatusMessage(), wr.getResponseHeaders()); return new WebResponseImpl(wrd, wr.getRequestSettings().getUrl(), wr.getRequestSettings().getHttpMethod(), wr.getLoadTime()); }