Skip to content

Commit

Permalink
Merge pull request #7764 from OpenLiberty/7610-MicroProfile-7.0-ID
Browse files Browse the repository at this point in the history
7610-MicroProfile 7.0 ID-012
  • Loading branch information
dmuelle authored Nov 27, 2024
2 parents cad8ed8 + 08a0312 commit a91491b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
57 changes: 0 additions & 57 deletions modules/ROOT/pages/send-receive-multipart-jaxrs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,6 @@ buildscript {
}
----

[#multipart]
== Processing multipart data

The `multipart/form-data` media type enables requests to send multiple entities (parts) as a single entity using `jakarta.ws.rs.core.EntityPart` objects.

For example, MicroProfile Multipart Rest Clients are defined as Java interfaces.

[source,java]
----
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/test-app")
public interface MultiPartClient extends AutoCloseable {
@POST
@Path("upload/")
void uploadFile(List<EntityPart> entityParts) throws IOException;
}
----

The example code utilizing this ingerface

source,java]
----
public void uploadMultipleFiles() throws Exception {
try (MultiPartClient client = RestClientBuilder.newBuilder()
.baseUri(uri)
.build(MultiPartClient.class)) {
final Map<String, byte[]> entityPartContent = new LinkedHashMap<>(2);
try (InputStream in = MultiPartClientTest.class
.getResourceAsStream("/multipart/test-file1.txt")) {
entityPartContent.put("test-file1.txt", in.readAllBytes());
}
try (InputStream in = MultiPartClientTest.class
.getResourceAsStream("/multipart/test-file2.txt")) {
entityPartContent.put("test-file2.txt", in.readAllBytes());
}
final List<EntityPart> files = entityPartContent.entrySet()
.stream()
.map((entry) -> {
try {
return EntityPart.withName(entry.getKey())
.fileName(entry.getKey())
.content(entry.getValue())
.mediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE)
.build();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
})
.collect(Collectors.toList());
client.uploadFile(files);
}
}
----


== Send multipart/form-data parts from Jakarta Restful Web Services resources

Expand Down
2 changes: 1 addition & 1 deletion modules/reference/pages/diff/mp-61-70-diff.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ RestClientBuilder.newBuilder()

=== Processing multipart data

Information and example code are added to the xref:ROOT:send-receive-multipart-jaxrs.adoc#multipart[send and receive multipart/form-data parts in Jakarta Restful Web Services] for processing multipart data, introduced as part of RESTful Web Services version 3.1 in EE10.
The link:https://download.eclipse.org/microprofile/microprofile-rest-client-4.0/microprofile-rest-client-spec-4.0.html#_processing_multipart_data[MicroProfile Rest Client 4.0 specification] includes information and example code for processing multipart data, introduced as part of RESTful Web Services version 3.1 in EE10.


[#openapi]
Expand Down

0 comments on commit a91491b

Please sign in to comment.