Java Code Examples for org.springframework.http.client.MultipartBodyBuilder#part()
The following examples show how to use
org.springframework.http.client.MultipartBodyBuilder#part() .
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: RestSteps.java From cucumber-rest-steps with MIT License | 6 votes |
private void callWithFile(String httpMethodString, String path, String file, Resource resource) { HttpMethod httpMethod = HttpMethod.valueOf(httpMethodString.toUpperCase()); if (httpMethod.equals(HttpMethod.GET)) { throw new IllegalArgumentException("You can't submit a file in a GET call"); } MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part(file, resource); responseSpec = webClient.method(httpMethod) .uri(path) .syncBody(builder.build()) .exchange(); expectBody = null; }
Example 2
Source File: SynchronossPartHttpMessageReaderTests.java From spring-analysis-note with MIT License | 5 votes |
private ServerHttpRequest generateMultipartRequest() { MultipartBodyBuilder partsBuilder = new MultipartBodyBuilder(); partsBuilder.part("fooPart", new ClassPathResource("org/springframework/http/codec/multipart/foo.txt")); partsBuilder.part("barPart", "bar"); MockClientHttpRequest outputMessage = new MockClientHttpRequest(HttpMethod.POST, "/"); new MultipartHttpMessageWriter() .write(Mono.just(partsBuilder.build()), null, MediaType.MULTIPART_FORM_DATA, outputMessage, null) .block(Duration.ofSeconds(5)); return MockServerHttpRequest.post("/") .contentType(outputMessage.getHeaders().getContentType()) .body(outputMessage.getBody()); }
Example 3
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void fluxPart() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Flux.class, Part.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); bodyBuilder.part("name", new Person("James")); Flux<Part> actual = resolveArgument(param, bodyBuilder); List<Part> parts = actual.collectList().block(); assertEquals("{\"name\":\"Jones\"}", partToUtf8String(parts.get(0))); assertEquals("{\"name\":\"James\"}", partToUtf8String(parts.get(1))); }
Example 4
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void listPart() { MethodParameter param = this.testMethod.annot(requestPart()).arg(List.class, Part.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); bodyBuilder.part("name", new Person("James")); List<Part> actual = resolveArgument(param, bodyBuilder); assertEquals("{\"name\":\"Jones\"}", partToUtf8String(actual.get(0))); assertEquals("{\"name\":\"James\"}", partToUtf8String(actual.get(1))); }
Example 5
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void part() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Part.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); Part actual = resolveArgument(param, bodyBuilder); DataBuffer buffer = DataBufferUtils.join(actual.content()).block(); assertEquals("{\"name\":\"Jones\"}", DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8)); }
Example 6
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void fluxPerson() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Flux.class, Person.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); bodyBuilder.part("name", new Person("James")); Flux<Person> actual = resolveArgument(param, bodyBuilder); List<Person> persons = actual.collectList().block(); assertEquals("Jones", persons.get(0).getName()); assertEquals("James", persons.get(1).getName()); }
Example 7
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void listPerson() { MethodParameter param = this.testMethod.annot(requestPart()).arg(List.class, Person.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); bodyBuilder.part("name", new Person("James")); List<Person> actual = resolveArgument(param, bodyBuilder); assertEquals("Jones", actual.get(0).getName()); assertEquals("James", actual.get(1).getName()); }
Example 8
Source File: RequestPartMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void person() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Person.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); Person actual = resolveArgument(param, bodyBuilder); assertEquals("Jones", actual.getName()); }
Example 9
Source File: GraphIntegrationTest.java From kafka-graphs with Apache License 2.0 | 5 votes |
private MultiValueMap<String, HttpEntity<?>> generateCCBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("verticesTopic", "initial-cc-vertices"); builder.part("edgesTopic", "initial-cc-edges"); builder.part("vertexFile", new ClassPathResource("vertices_simple.txt")); builder.part("edgeFile", new ClassPathResource("edges_simple.txt")); builder.part("vertexParser", VertexLongIdLongValueParser.class.getName()); builder.part("edgeParser", EdgeLongIdLongValueParser.class.getName()); builder.part("keySerializer", LongSerializer.class.getName()); builder.part("vertexValueSerializer", LongSerializer.class.getName()); builder.part("edgeValueSerializer", LongSerializer.class.getName()); builder.part("numPartitions", "50"); builder.part("replicationFactor", "1"); return builder.build(); }
Example 10
Source File: CancelWithoutDemandCodecTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // gh-22107 public void cancelWithMultipartContent() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("part1", "value1"); builder.part("part2", "value2"); List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters(); MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(writers); CancellingOutputMessage outputMessage = new CancellingOutputMessage(this.bufferFactory); writer.write(Mono.just(builder.build()), null, MediaType.MULTIPART_FORM_DATA, outputMessage, Collections.emptyMap()).block(Duration.ofSeconds(5)); }
Example 11
Source File: GraphIntegrationTest.java From kafka-graphs with Apache License 2.0 | 5 votes |
private MultiValueMap<String, HttpEntity<?>> generateSvdppBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("edgesTopic", "initial-svdpp-edges"); builder.part("edgeFile", new ClassPathResource("ratings_simple.txt")); builder.part("edgeParser", EdgeCfLongIdFloatValueParser.class.getName()); builder.part("edgeValueSerializer", FloatSerializer.class.getName()); builder.part("numPartitions", "50"); builder.part("replicationFactor", "1"); return builder.build(); }
Example 12
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void part() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Part.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); Part actual = resolveArgument(param, bodyBuilder); DataBuffer buffer = DataBufferUtils.join(actual.content()).block(); assertEquals("{\"name\":\"Jones\"}", DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8)); }
Example 13
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void fluxPerson() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Flux.class, Person.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); bodyBuilder.part("name", new Person("James")); Flux<Person> actual = resolveArgument(param, bodyBuilder); List<Person> persons = actual.collectList().block(); assertEquals("Jones", persons.get(0).getName()); assertEquals("James", persons.get(1).getName()); }
Example 14
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void person() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Person.class); MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder(); bodyBuilder.part("name", new Person("Jones")); Person actual = resolveArgument(param, bodyBuilder); assertEquals("Jones", actual.getName()); }
Example 15
Source File: MultipartIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
private MultiValueMap<String, HttpEntity<?>> generateBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("fieldPart", "fieldValue"); builder.part("fileParts", new ClassPathResource("foo.txt", MultipartHttpMessageReader.class)); builder.part("fileParts", new ClassPathResource("logo.png", getClass())); builder.part("jsonPart", new Person("Jason")); return builder.build(); }
Example 16
Source File: MultipartIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
private MultiValueMap<String, HttpEntity<?>> generateBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("fooPart", new ClassPathResource("org/springframework/http/codec/multipart/foo.txt")); builder.part("barPart", "bar"); return builder.build(); }
Example 17
Source File: MultipartIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
private MultiValueMap<String, HttpEntity<?>> generateBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("fooPart", new ClassPathResource("org/springframework/http/codec/multipart/foo.txt")); builder.part("barPart", "bar"); return builder.build(); }
Example 18
Source File: ReactiveIT.java From errors-spring-boot-starter with Apache License 2.0 | 4 votes |
private MultiValueMap<String, HttpEntity<?>> generateBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("fieldPart", "fieldValue"); builder.part("fileParts", new ByteArrayResource("data".getBytes())); return builder.build(); }
Example 19
Source File: FormIntegrationTests.java From spring-cloud-gateway with Apache License 2.0 | 4 votes |
private MultiValueMap<String, HttpEntity<?>> createMultipartData() { ClassPathResource part = new ClassPathResource("1x1.png"); MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("imgpart", part, MediaType.IMAGE_PNG); return builder.build(); }
Example 20
Source File: DemoApplicationTests.java From spring-reactive-sample with GNU General Public License v3.0 | 4 votes |
private MultiValueMap<String, HttpEntity<?>> generateBody() { MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("fileParts", new ClassPathResource("/foo.txt", DemoApplicationTests.class)); return builder.build(); }