Reputation: 173
Trying to configure a JAX-RS resource with @Path("/"), however, the resource is ignored and the first file found in resources is loaded.
Any idea how to prevent this and allow the resource to work? When clearing META-INF/resources, the JAX-RS resource loads correctly.
Using: Quarkus 1.4.2.Final
openjdk version "11.0.6" 2020-01-14 LTS OpenJDK Runtime Environment Zulu11.37+52-SA (build 11.0.6+10-LTS) OpenJDK 64-Bit Server VM Zulu11.37+52-SA (build 11.0.6+10-LTS, mixed mode)
Resource:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/")
public class LandingResource {
@GET
@Produces(MediaType.TEXT_HTML)
public String getLandingPage() {
return "<html><head><title>Hello World</title></head><body>Hello!</body></html>";
}
}
Testing:
curl --location --request GET 'http://localhost:8080/'
Response:
<!doctype html>
<html lang="en">
<head>
<title>Internal Server Error - Error handling cee4cff3-551d-44e1-9102-5c9ada9d8fb2-7, java.nio.file.InvalidPathException: Illegal char &lt;:&gt; at index 97: <tempdir>\vertx-cache\file-cache-71fbfca9-5ba3-4a3e-8020-8501379cbf2b\<project dir>\src\main\resources\META-INF\resources\assets\icons\icon-128x128.png</title>
<meta charset="utf-8">
<style>
html, body {
margin: 0;
padding: 0;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 100%;
font-weight: 100;
line-height: 1.4;
}
...
Upvotes: 6
Views: 3914
Reputation: 3002
To add on Pieterjan's answer, you can know (since version 2.16) use the dedicated application property for setting the index page of the static files
quarkus.http.static-resources.index-page
https://quarkus.io/guides/http-reference
Note: for me using quarkus-undertow dependency was blocking the property. So I had to remove it.
Upvotes: 0
Reputation: 173
Achieved the desired outcome by adding a vertx web route:
import io.quarkus.vertx.web.Route;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.RoutingContext;
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class LandingRoute {
@Route(path = "/", methods = HttpMethod.GET)
public void landing(RoutingContext rc) {
rc.response().end("hello ");
}
}
In order to use @Route annotation you need to add quarkus-reactive-routes extension (io.quarkus:quarkus-reactive-routes
) to project.
You can find more information about reactive routes in Quarkus documentation at: https://quarkus.io/guides/reactive-routes
Upvotes: 2
Reputation: 552
By default Quarkus will serve static resources from the root context.
That means that the resources inside src/main/resources/META-INF/resources/
are already mapped to root (http://localhost:8080/). This means that you can not map a standard JAX-RS on the root easily.
See the documentation for further information: https://quarkus.io/guides/http-reference
In your case you are returning a fixed HTML landing page. As a solution you could remove the LandingResource class and serve the landing page from the static resources.
This can be achieved by placing the HTML snippet in src/main/resources/META-INF/resources/index.html
.
This is also how the default Quarkus default landing page is served.
Upvotes: 0