Skip to content

Commit

Permalink
Merge pull request quarkus-qe#685 from fedinskiy/backport/2.7
Browse files Browse the repository at this point in the history
Coverage for 2.7.6 backports
  • Loading branch information
Pablo Gonzalez Granados authored Jun 14, 2022
2 parents b669966 + ca19203 commit e3250cf
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ interface AuthorClient {
@Produces(MediaType.TEXT_PLAIN)
interface ProfessionClient {
@GET
@Path("/name")
Uni<String> getName();
@Path("/title")
Uni<String> getTitle();

@Path("/wage")
WageClient getWage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Uni<String> getSubResource(@QueryParam("author") String author) {
@GET
@Path("/profession")
public Uni<String> getSubSubResource() {
return bookInterface.getAuthor().getProfession().getName();
return bookInterface.getAuthor().getProfession().getTitle();
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface FileClient {
@GET
@Path("/hash")
@Produces(MediaType.TEXT_PLAIN)
Uni<String> hash();
String hash();

@GET
@Path("/download")
Expand All @@ -33,7 +33,12 @@ public interface FileClient {
@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-multipart")
FileWrapper downloadMultipart();
Uni<FileWrapper> downloadMultipart();

@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-broken-multipart")
Uni<FileWrapper> brokenMultipart();

@POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
Expand All @@ -45,6 +50,6 @@ public interface FileClient {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@Path("/upload-multipart")
Uni<String> sendMultipart(@MultipartForm FileWrapper data);
String sendMultipart(@MultipartForm FileWrapper data);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,114 @@

import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.RestResponse;

import io.quarkus.logging.Log;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;

@Path("/file-client")
public class FileClientResource {
private static final String BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;
private final java.nio.file.Path FILE = Files.createTempFile("upload", ".txt").toAbsolutePath();
private static final long BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;

private final java.nio.file.Path file;
private final List<java.nio.file.Path> deathRow = new LinkedList<>();
private final FileClient client;
private final OsUtils utils;

@Inject
public FileClientResource(@RestClient FileClient client) throws IOException {
public FileClientResource(@RestClient FileClient client,
@ConfigProperty(name = "client.filepath") Optional<String> folder) {
utils = OsUtils.get();
utils.createFile(FILE.toString(), BIGGER_THAN_TWO_GIGABYTES);
file = folder
.stream()
.map(existing -> java.nio.file.Path.of(existing).resolve("upload.txt").toAbsolutePath())
.peek(path -> utils.createFile(path, BIGGER_THAN_TWO_GIGABYTES))
.findFirst().orElse(null);
this.client = client;
}

@GET
@Path("/client-hash")
@Blocking
public Uni<String> calculateHash() {
return utils.getSum(FILE.toString());
return Uni.createFrom().item(() -> utils.getSum(file));
}

@GET
@Path("/hash")
public Uni<String> hash() {
public String hash() {
return client.hash();
}

@GET
@Path("/download")
public Uni<String> download() {
return client.download().onItem().transformToUni(file -> utils.getSum(file.getAbsolutePath()));
return client.download()
.map(file -> {
java.nio.file.Path path = file.toPath().toAbsolutePath();
deathRow.add(path);
return path;
})
.map(utils::getSum);
}

@GET
@Path("/download-multipart")
public Uni<String> downloadMultipart() {
FileWrapper wrapper = client.downloadMultipart();
String path = wrapper.file.getAbsolutePath();
return utils.getSum(path);
return client.downloadMultipart()
.map(wrapper -> wrapper.file.toPath())
.map(java.nio.file.Path::toAbsolutePath)
.invoke(deathRow::add)
.map(utils::getSum);
}

@GET
@Path("/download-broken-multipart")
public Uni<String> downloadMultipartResponse() {
return client.brokenMultipart()
.map(wrapper -> wrapper.file.toPath().toAbsolutePath())
.map(utils::getSum);
}

@POST
@Path("/multipart")
public Uni<String> uploadMultipart() {
@Blocking
public String uploadMultipart() {
FileWrapper wrapper = new FileWrapper();
wrapper.file = FILE.toFile();
wrapper.file = file.toFile();
wrapper.name = file.toString();
return client.sendMultipart(wrapper);
}

@POST
@Path("/upload-file")
public Uni<String> upload() {
return client.sendFile(FILE.toFile());
return client.sendFile(file.toFile());
}

@DELETE
@Path("/")
public RestResponse removeTemporaryFiles() {
for (java.nio.file.Path path : deathRow) {
try {
Files.delete(path);
} catch (IOException e) {
Log.warn(e);
}
}
return RestResponse.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,105 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.resteasy.reactive.MultipartForm;
import org.jboss.resteasy.reactive.RestResponse;

import io.quarkus.logging.Log;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;

@Path("/file")
public class FileResource {
private static final String BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;
private final File FILE = Files.createTempFile("server", ".txt").toAbsolutePath().toFile();
private static final long BIGGER_THAN_TWO_GIGABYTES = OsUtils.SIZE_2049MiB;
private final File file;
private final OsUtils utils;
private final List<File> deathRow = new LinkedList<>();

public FileResource() throws IOException {
public FileResource(@ConfigProperty(name = "client.filepath") Optional<String> folder) {
utils = OsUtils.get();
utils.createFile(FILE.getAbsolutePath(), BIGGER_THAN_TWO_GIGABYTES);
file = folder
.stream()
.map(existing -> java.nio.file.Path.of(existing).resolve("server.txt").toAbsolutePath())
.peek(path -> utils.createFile(path, BIGGER_THAN_TWO_GIGABYTES))
.map(java.nio.file.Path::toFile)
.findFirst().orElse(null);
}

@GET
@Path("/download")
public Uni<File> download() {
return Uni.createFrom().item(FILE);
return Uni.createFrom().item(file);
}

@POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
@Path("/upload")
public Uni<String> upload(File body) {
return utils.getSum(body.getAbsolutePath());
deathRow.add(body);
return Uni.createFrom().item(() -> utils.getSum(body.getAbsoluteFile().toPath()));
}

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@Path("/upload-multipart")
public Uni<String> uploadMultipart(@MultipartForm FileWrapper body) {
return utils.getSum(body.file.getAbsolutePath());
@Blocking
public String uploadMultipart(@MultipartForm FileWrapper body) {
deathRow.add(body.file);
return utils.getSum(body.file.getAbsoluteFile().toPath());
}

@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-multipart")
public RestResponse<FileWrapper> downloadMultipart() {
@Blocking //https://github.com/quarkusio/quarkus/issues/25909
public Uni<FileWrapper> downloadMultipart() {
FileWrapper wrapper = new FileWrapper();
wrapper.file = FILE;
return RestResponse.ok(wrapper);
wrapper.file = file;
wrapper.name = file.getName();
return Uni.createFrom().item(() -> wrapper);
}

@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
@Path("/download-broken-multipart")
@Blocking //https://github.com/quarkusio/quarkus/issues/25909
public Uni<RestResponse> brokenMultipart() {
return Uni.createFrom().item(() -> RestResponse.ok("Not a multipart message"));
}

@GET
@Path("/hash")
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> hash() {
Log.info("Hashing path " + FILE.getAbsolutePath());
return utils.getSum(FILE.getAbsolutePath());
public String getHashSum() {
Log.info("Hashing path " + file.getAbsolutePath());
return utils.getSum(file.getAbsoluteFile().toPath());
}

@DELETE
@Path("/")
public RestResponse removeTemporaryFiles() {
for (File path : deathRow) {
try {
Files.delete(path.toPath().toAbsolutePath());
} catch (IOException e) {
Log.warn(e);
}
}
return RestResponse.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import java.io.File;

import javax.ws.rs.FormParam;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.PartType;
import org.jboss.resteasy.reactive.RestForm;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public class FileWrapper {
@FormParam("file")
@RestForm("file")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public File file;

@RestForm("name")
@PartType(MediaType.TEXT_PLAIN)
public String name;
}
Loading

0 comments on commit e3250cf

Please sign in to comment.