@Test(expected = IllegalStateException.class) public void testMultipleBodies() { requestBuilder.body(body -> body.string("body1", HttpConstants.CONTENT_TEXT_PLAIN)); requestBuilder.body(body -> body.string("body12", HttpConstants.CONTENT_TEXT_PLAIN)); }
@Override public RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer) { if (multipartBuilder != null) { throw new IllegalStateException("A normal body cannot be added to a multipart request"); } if (getBody() != null) { throw new IllegalStateException("A request can only have a single body"); } RequestBodyBuilderImpl bodyBuilder = new RequestBodyBuilderImpl(mapper); bodyProducer.accept(bodyBuilder); body = bodyBuilder.getBody(); return this; }
RequestBuilderImpl implements RequestBuilder { @Override public RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer) { if (multipartBuilder != null) { throw new IllegalStateException("A normal body cannot be added to a multipart request"); } if (getBody() != null) { throw new IllegalStateException("A request can only have a single body"); } RequestBodyBuilderImpl bodyBuilder = new RequestBodyBuilderImpl(mapper); bodyProducer.accept(bodyBuilder); body = bodyBuilder.getBody(); return this; } }
RequestBuilderImpl implements RequestBuilder { @Override public RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer) { if (multipartBuilder != null) { throw new IllegalStateException("A normal body cannot be added to a multipart request"); } if (getBody() != null) { throw new IllegalStateException("A request can only have a single body"); } RequestBodyBuilderImpl bodyBuilder = new RequestBodyBuilderImpl(mapper); bodyProducer.accept(bodyBuilder); body = bodyBuilder.getBody(); return this; } RequestBuilderImpl(ObjectMapper mapper); }
RequestBuilderImpl implements RequestBuilder { @Override public RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer) { if (multipartBuilder != null) { throw new IllegalStateException("A normal body cannot be added to a multipart request"); } if (getBody() != null) { throw new IllegalStateException("A request can only have a single body"); } RequestBodyBuilderImpl bodyBuilder = new RequestBodyBuilderImpl(mapper); bodyProducer.accept(bodyBuilder); body = bodyBuilder.getBody(); return this; } RequestBuilderImpl(ObjectMapper mapper); @Override RequestBuilder method(Method method); @Override RequestBuilder uri(String uri); @Override RequestBuilder header(String name, String value); @Override RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer); @Override RequestBuilder multiPart(String name, Consumer<RequestBodyBuilder> partProducer); Request build(); }
RequestBuilderImpl implements RequestBuilder { @Override public RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer) { if (multipartBuilder != null) { throw new IllegalStateException("A normal body cannot be added to a multipart request"); } if (getBody() != null) { throw new IllegalStateException("A request can only have a single body"); } RequestBodyBuilderImpl bodyBuilder = new RequestBodyBuilderImpl(mapper); bodyProducer.accept(bodyBuilder); body = bodyBuilder.getBody(); return this; } RequestBuilderImpl(ObjectMapper mapper); @Override RequestBuilder method(Method method); @Override RequestBuilder uri(String uri); @Override RequestBuilder header(String name, String value); @Override RequestBuilder body(Consumer<RequestBodyBuilder> bodyProducer); @Override RequestBuilder multiPart(String name, Consumer<RequestBodyBuilder> partProducer); Request build();  }