Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#28325 upping quarkus platform #28383

Merged
merged 15 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.specimpl.BuiltResponse;
import picocli.CommandLine;
import picocli.CommandLine.Help.ColorScheme;
import picocli.CommandLine.Model.CommandSpec;
Expand Down Expand Up @@ -279,8 +282,12 @@ public int handleCommandException(final Exception ex, final String message,
*/
private String getMessage(final Exception originalException, final Exception handledEx) {

var message = abbreviate(handledEx.getMessage(), "...", 200);

var message = abbreviate(handledEx.getMessage(), "...", 200);

if(handledEx instanceof WebApplicationException){
message = getWebApplicationExceptionMessage((WebApplicationException) handledEx);
}

if (originalException instanceof PushException ||
originalException instanceof PullException ||
originalException instanceof TraversalTaskException) {
Expand All @@ -300,6 +307,23 @@ private String getMessage(final Exception originalException, final Exception han
+ " Occurred With no error message provided.";
}

/**
* On recent versions of RESTEasy, the custom message is stored in the reasonPhrase
* The WebApplicationException message is immutable and can't be changed 404 is always "Not Found"
* @param ex The exception that was thrown
* @return The message to display
*/
String getWebApplicationExceptionMessage(final WebApplicationException ex) {
final Response response = ex.getResponse();
if (response instanceof BuiltResponse) {
final String reasonPhrase = ((BuiltResponse) response).getReasonPhrase();
if (null != reasonPhrase) {
return reasonPhrase;
}
}
return ex.getMessage();
}

@Override
public String toString() {
return "OutputOptions [testMode=" + cliTestMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void Test_Command_Login_With_Params_Expect_Login_Reject() {
final String output = writer.toString();
Assertions.assertTrue(output.contains("[ERROR]"));
Assertions.assertTrue(output.contains(
"HTTP 401 Forbidden: You don't have permission to access this resource."));
"Forbidden: You don't have permission to access this resource."));
}
}

Expand All @@ -165,7 +165,7 @@ void Test_Command_Login_With_Invalid_Token() {
final String output = writer.toString();
Assertions.assertTrue(output.contains("[ERROR]"));
Assertions.assertTrue(output.contains(
"HTTP 401 Forbidden: You don't have permission to access this resource."));
"Forbidden: You don't have permission to access this resource."));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import javax.ws.rs.NotAllowedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.WebApplicationException;
import org.jboss.resteasy.specimpl.BuiltResponse;
import org.junit.Ignore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -44,32 +46,42 @@ void Test_Handle_WebApplication_Exception() {
NotFoundException noise = new NotFoundException("No pineapple Flavor today");
Exception handled = exceptionHandler.handle(noise);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(404)));
// On recent versions of Quarkus, the custom message is set as the reason phrase of the response
//WebApplications have an immutable message so we can't change it. 404 will always be Not Found etc...
BuiltResponse response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
//Therefore the custom message needs to be extracted from the response
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(404)));
//Assertions.assertTrue(handled.getMessage().contains(config.messages().get(404)));
fabrizzio-dotCMS marked this conversation as resolved.
Show resolved Hide resolved

BadRequestException badRequestException = new BadRequestException("LOL");
handled = exceptionHandler.handle(badRequestException);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(400)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(400)));

ForbiddenException forbiddenException = new ForbiddenException("LOL");
handled = exceptionHandler.handle(forbiddenException);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(403)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(403)));

WebApplicationException unauthorized = new WebApplicationException(401);
handled = exceptionHandler.handle(unauthorized);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(401)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(401)));

WebApplicationException internalServerError = new WebApplicationException(500);
handled = exceptionHandler.handle(internalServerError);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.messages().get(500)));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.messages().get(500)));

NotAllowedException moreNoise = new NotAllowedException("Not Allowed");
handled = exceptionHandler.handle(moreNoise);
Assertions.assertTrue(handled instanceof WebApplicationException);
Assertions.assertTrue(handled.getMessage().contains(config.fallback()));
response = (BuiltResponse) ((WebApplicationException) handled).getResponse();
Assertions.assertTrue(response.getReasonPhrase().contains(config.fallback()));

}

Expand Down
2 changes: 1 addition & 1 deletion tools/dotcms-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<properties>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.9.1.Final</quarkus.platform.version>
<quarkus.platform.version>2.16.12.Final</quarkus.platform.version>
<jreleaser-plugin.version>1.8.0</jreleaser-plugin.version>
<google.findbugs.version>3.0.2</google.findbugs.version>
</properties>
Expand Down
Loading