-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for improvement multipart encoded mode in rest-client
- Loading branch information
1 parent
4b1a5cf
commit 650cd90
Showing
12 changed files
with
435 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...src/main/java/io/quarkus/ts/http/restclient/reactive/multipart/EncoderModeRestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.ts.http.restclient.reactive.multipart; | ||
|
||
import static jakarta.ws.rs.core.MediaType.MULTIPART_FORM_DATA; | ||
|
||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.FormParam; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.reactive.PartType; | ||
import org.jboss.resteasy.reactive.RestForm; | ||
|
||
@Path("/encoder-mode") | ||
public interface EncoderModeRestClient { | ||
|
||
@POST | ||
@Consumes(MULTIPART_FORM_DATA) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
MyMultipartDTO doAPostRequestToThisResource( | ||
@PartType(MediaType.TEXT_PLAIN) @FormParam("file1") java.nio.file.Path file1, | ||
@PartType(MediaType.TEXT_PLAIN) @FormParam("file2") java.nio.file.Path file2, | ||
@RestForm String otherField); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ain/java/io/quarkus/ts/http/restclient/reactive/multipart/Html5EncoderModeRestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.ts.http.restclient.reactive.multipart; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(configKey = "encoder-mode-html5") | ||
public interface Html5EncoderModeRestClient extends EncoderModeRestClient { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...-client-reactive/src/main/java/io/quarkus/ts/http/restclient/reactive/multipart/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.quarkus.ts.http.restclient.reactive.multipart; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Item { | ||
public final String name; | ||
public final long size; | ||
public final String charset; | ||
public final String fileContent; | ||
|
||
public String getFileContent() { | ||
return fileContent; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public long getSize() { | ||
return size; | ||
} | ||
|
||
public String getCharset() { | ||
return charset; | ||
} | ||
|
||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
public boolean isFileItem() { | ||
return isFileItem; | ||
} | ||
|
||
public Map<String, List<String>> getHeaders() { | ||
return headers; | ||
} | ||
|
||
public final String fileName; | ||
public final boolean isFileItem; | ||
public final Map<String, List<String>> headers; | ||
public boolean fileItem; | ||
|
||
public Item(String name, long size, String charset, String fileName, boolean isFileItem, | ||
Map<String, List<String>> headers, boolean fileItem, String fileContent) { | ||
this.name = name; | ||
this.size = size; | ||
this.charset = charset; | ||
this.fileName = fileName; | ||
this.isFileItem = isFileItem; | ||
this.headers = headers; | ||
this.fileItem = fileItem; | ||
this.fileContent = fileContent; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...active/src/main/java/io/quarkus/ts/http/restclient/reactive/multipart/MyMultipartDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.ts.http.restclient.reactive.multipart; | ||
|
||
import java.util.List; | ||
|
||
public class MyMultipartDTO { | ||
private List<Item> items; | ||
|
||
public MyMultipartDTO() { | ||
} | ||
|
||
public MyMultipartDTO(List<Item> items) { | ||
this.items = items; | ||
} | ||
|
||
public List<Item> getItems() { | ||
return items; | ||
} | ||
|
||
public void setItems(List<Item> items) { | ||
this.items = items; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...n/java/io/quarkus/ts/http/restclient/reactive/multipart/Rfc1738EncoderModeRestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.ts.http.restclient.reactive.multipart; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(configKey = "encoder-mode-rfc1738") | ||
public interface Rfc1738EncoderModeRestClient extends EncoderModeRestClient { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...n/java/io/quarkus/ts/http/restclient/reactive/multipart/Rfc3986EncoderModeRestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.ts.http.restclient.reactive.multipart; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(configKey = "encoder-mode-rfc3986") | ||
public interface Rfc3986EncoderModeRestClient extends EncoderModeRestClient { | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...va/io/quarkus/ts/http/restclient/reactive/resources/MultipartPostEncoderModeResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.quarkus.ts.http.restclient.reactive.resources; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.reactive.server.multipart.FormValue; | ||
import org.jboss.resteasy.reactive.server.multipart.MultipartFormDataInput; | ||
|
||
import io.quarkus.ts.http.restclient.reactive.multipart.EncoderModeRestClient; | ||
import io.quarkus.ts.http.restclient.reactive.multipart.Html5EncoderModeRestClient; | ||
import io.quarkus.ts.http.restclient.reactive.multipart.Item; | ||
import io.quarkus.ts.http.restclient.reactive.multipart.MyMultipartDTO; | ||
import io.quarkus.ts.http.restclient.reactive.multipart.Rfc1738EncoderModeRestClient; | ||
import io.quarkus.ts.http.restclient.reactive.multipart.Rfc3986EncoderModeRestClient; | ||
|
||
@Path("/encode") | ||
public class MultipartPostEncoderModeResource { | ||
|
||
private final Map<String, EncoderModeRestClient> modeToRestClient; | ||
|
||
public MultipartPostEncoderModeResource(@RestClient Html5EncoderModeRestClient html5Client, | ||
@RestClient Rfc1738EncoderModeRestClient rfc1738Client, | ||
@RestClient Rfc3986EncoderModeRestClient rfc3986Client) { | ||
this.modeToRestClient = Map.of("HTML5", html5Client, "RFC1738", rfc1738Client, "RFC3986", rfc3986Client); | ||
} | ||
|
||
@Path("{encoder-mode}") | ||
@POST | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public MyMultipartDTO doAPostRequestToSimpleEncodeResource(MultipartFormDataInput input, | ||
@PathParam("encoder-mode") String encoderMode) { | ||
|
||
EncoderModeRestClient client = modeToRestClient.get(encoderMode); | ||
if (!modeToRestClient.containsKey(encoderMode)) { | ||
throw new WebApplicationException("Unsupported encoder mode" + encoderMode, Response.Status.BAD_REQUEST); | ||
} | ||
|
||
Map<String, Collection<FormValue>> formValues = input.getValues(); | ||
|
||
if (!formValues.containsKey("file1") || !formValues.containsKey("file2") || !formValues.containsKey("otherField")) { | ||
throw new IllegalArgumentException("Missing mandatory fields!"); | ||
} | ||
|
||
java.nio.file.Path file1 = formValues.get("file1").stream().findFirst().get().getFileItem().getFile(); | ||
java.nio.file.Path file2 = formValues.get("file2").stream().findFirst().get().getFileItem().getFile(); | ||
String otherField = formValues.get("otherField").stream().findFirst().get().getValue(); | ||
|
||
MyMultipartDTO response = client.doAPostRequestToThisResource(file1, file2, otherField); | ||
|
||
List<Item> items = response.getItems(); | ||
|
||
return new MyMultipartDTO(items); | ||
} | ||
|
||
} |
9 changes: 8 additions & 1 deletion
9
http/rest-client-reactive/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
quarkus.tls.trust-all=true | ||
quarkus.http.ssl.certificate.key-store-file=META-INF/keystore.jks | ||
quarkus.http.ssl.certificate.key-store-password=password | ||
quarkus.http.ssl.certificate.key-store-password=password | ||
vertx-server-url=http://${quarkus.http.host:localhost}:${vertx-server-port}/ | ||
quarkus.rest-client.encoder-mode-html5.url=${vertx-server-url} | ||
quarkus.rest-client.encoder-mode-html5.multipart-post-encoder-mode=HTML5 | ||
quarkus.rest-client.encoder-mode-rfc1738.url=${vertx-server-url} | ||
quarkus.rest-client.encoder-mode-rfc1738.multipart-post-encoder-mode=RFC1738 | ||
quarkus.rest-client.encoder-mode-rfc3986.url=${vertx-server-url} | ||
quarkus.rest-client.encoder-mode-rfc3986.multipart-post-encoder-mode=RFC3986 |
Oops, something went wrong.