/** * The exact string body to match on such as "this is an exact string body" * * @param body the body on such as "this is an exact string body" */ public HttpRequest withBody(String body) { this.body = new StringBody(body); return this; }
/** * Set response body to return a string response body with the specified encoding. <b>Note:</b> The character set of the * response will be forced to the specified charset, even if the Content-Type header specifies otherwise. * * @param body a string * @param contentType media type, if charset is included this will be used for encoding string */ public HttpResponse withBody(String body, MediaType contentType) { if (body != null) { this.body = new StringBody(body, contentType); } return this; }
/** * The exact string body to match on such as "this is an exact string body" * * @param body the body on such as "this is an exact string body" * @param charset character set the string will be encoded in */ public HttpRequest withBody(String body, Charset charset) { if (body != null) { this.body = new StringBody(body, charset); } return this; }
/** * Set response body to return as a string response body. The character set will be determined by the Content-Type header * on the response. To force the character set, use {@link #withBody(String, Charset)}. * * @param body a string */ public HttpResponse withBody(String body) { if (body != null) { this.body = new StringBody(body); } return this; }
public static StringBody exact(String body, MediaType contentType) { return new StringBody(body, contentType); }
public static StringBody subString(String body, MediaType contentType) { return new StringBody(body, true, contentType); }
/** * Set response body to return a string response body with the specified encoding. <b>Note:</b> The character set of the * response will be forced to the specified charset, even if the Content-Type header specifies otherwise. * * @param body a string * @param charset character set the string will be encoded in */ public HttpResponse withBody(String body, Charset charset) { if (body != null) { this.body = new StringBody(body, charset); } return this; }
public static StringBody exact(String body) { return new StringBody(body); }
public static StringBody subString(String body) { return new StringBody(body, true); }
public static StringBody exact(String body, Charset charset) { return new StringBody(body, charset); }
public static StringBody subString(String body, Charset charset) { return new StringBody(body, true, charset); }
public StringBody buildObject() { return new StringBody(string, subString, getMediaType()); } }
private void setBody(HttpRequest httpRequest, HttpServletRequest httpServletRequest) { byte[] bodyBytes = IOStreamUtils.readInputStreamToByteArray(httpServletRequest); if (bodyBytes.length > 0) { if (ContentTypeMapper.isBinary(httpServletRequest.getHeader(CONTENT_TYPE.toString()))) { httpRequest.withBody(new BinaryBody(bodyBytes)); } else { Charset requestCharset = ContentTypeMapper.getCharsetFromContentTypeHeader(httpServletRequest.getHeader(CONTENT_TYPE.toString())); httpRequest.withBody(new StringBody(new String(bodyBytes, requestCharset), DEFAULT_HTTP_CHARACTER_SET.equals(requestCharset) ? null : requestCharset)); } } }
private void setBody(HttpRequest httpRequest, FullHttpRequest fullHttpRequest) { if (fullHttpRequest.content() != null && fullHttpRequest.content().readableBytes() > 0) { byte[] bodyBytes = new byte[fullHttpRequest.content().readableBytes()]; fullHttpRequest.content().readBytes(bodyBytes); if (bodyBytes.length > 0) { if (ContentTypeMapper.isBinary(fullHttpRequest.headers().get(CONTENT_TYPE))) { httpRequest.withBody(new BinaryBody(bodyBytes)); } else { Charset requestCharset = ContentTypeMapper.getCharsetFromContentTypeHeader(fullHttpRequest.headers().get(CONTENT_TYPE)); httpRequest.withBody(new StringBody(new String(bodyBytes, requestCharset), DEFAULT_HTTP_CHARACTER_SET.equals(requestCharset) ? null : requestCharset)); } } } } }
.withPath(calculatePath("some_path")) .withMethod("POST") .withBody(new StringBody("" + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + NEW_LINE + "<bookstore>" + NEW_LINE + .withPath(calculatePath("some_path")) .withMethod("POST") .withBody(new StringBody("" + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + NEW_LINE + "<bookstore>" + NEW_LINE +
.withPath(calculatePath("some_path")) .withMethod("POST") .withBody(new StringBody("" + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + NEW_LINE + "<bookstore>" + NEW_LINE + .withPath(calculatePath("some_path")) .withMethod("POST") .withBody(new StringBody("" + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + NEW_LINE + "<bookstore>" + NEW_LINE +
.withPath(calculatePath("some_path")) .withMethod("POST") .withBody(new StringBody("" + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + NEW_LINE + "<bookstore>" + NEW_LINE + .withPath(calculatePath("some_path")) .withMethod("POST") .withBody(new StringBody("" + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + NEW_LINE + "<bookstore>" + NEW_LINE +
.withMethod("POST") .withPath(calculatePath("some_pathRequest")) .withBody(new StringBody("OTHERBodyParameterOneName=Parameter+One+Value+One" + "&bodyParameterOneName=Parameter+One+Value+Two" + "&bodyParameterTwoName=Parameter+Two"))
.withMethod("POST") .withPath(calculatePath("some_pathRequest")) .withBody(new StringBody("OTHERBodyParameterOneName=Parameter+One+Value+One" + "&OTHERBodyParameterOneName=Parameter+One+Value+Two" + "&bodyParameterTwoName=Parameter+Two"))
.withMethod("POST") .withPath(calculatePath("some_pathRequest")) .withBody(new StringBody("bodyParameterOneName=OTHER Parameter+One+Value+One" + "&bodyParameterOneName=OTHER Parameter+One+Value+Two" + "&bodyParameterTwoName=Parameter+Two"))