Skip to content

Commit

Permalink
Take into account quarkus.resteasy.gzip.max-input in REST Client
Browse files Browse the repository at this point in the history
Fix #12941
  • Loading branch information
Sgitario committed Mar 29, 2023
1 parent 34da513 commit 52aa9b7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.quarkus.restclient.compression;

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.WebApplicationException;

import org.apache.http.HttpStatus;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.annotations.GZIP;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class ClientUsingGzipCompressionTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyResource.class, MyClient.class))
.withConfigurationResource("client-using-gzip-application.properties");

@RestClient
MyClient client;

/**
* Test that covers the property `quarkus.resteasy.gzip.max-input`.
* Larger payloads than 10 bytes should return HTTP Request Too Large.
*/
@Test
public void testGzipMaxInput() {
WebApplicationException ex = Assertions.assertThrows(WebApplicationException.class, () -> client.gzip(new byte[11]));
assertEquals(HttpStatus.SC_REQUEST_TOO_LONG, ex.getResponse().getStatus());

// verify shorter message works fine
Assertions.assertEquals("Worked!", client.gzip(new byte[10]));
}

@Path("/client")
@RegisterRestClient(configKey = "my-client")
public interface MyClient {

@POST
@Path("/gzip")
String gzip(@GZIP byte[] message);

}

@Path("/client")
public class MyResource {

@POST
@Path("/gzip")
public String gzip(@GZIP String message) {
return "Worked!";
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkus.resteasy.gzip.enabled=true
quarkus.resteasy.gzip.max-input=10

quarkus.rest-client.my-client.url=http://localhost:${quarkus.http.test-port:8081}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
import org.jboss.resteasy.spi.ResteasyConfiguration;

/**
* Some resteasy components use this class for configuration. This bridges MP Config to ResteasyConfiguration
*
*/
public class ResteasyConfigurationMPConfig implements ResteasyConfiguration {

private static final Map<String, String> RESTEASY_QUARKUS_MAPPING_PARAMS = Map.of(
ResteasyContextParameters.RESTEASY_GZIP_MAX_INPUT, "quarkus.resteasy.gzip.max-input");

@Override
public String getParameter(String name) {
Config config = ConfigProvider.getConfig();
if (config == null)
return null;
return config.getOptionalValue(name, String.class).orElse(null);
return config.getOptionalValue(RESTEASY_QUARKUS_MAPPING_PARAMS.getOrDefault(name, name), String.class)
.orElse(null);
}

@Override
Expand All @@ -29,6 +36,7 @@ public Set<String> getParameterNames() {
HashSet<String> set = new HashSet<>();
for (String name : config.getPropertyNames())
set.add(name);
set.addAll(RESTEASY_QUARKUS_MAPPING_PARAMS.keySet());
return set;
}

Expand Down

0 comments on commit 52aa9b7

Please sign in to comment.