Skip to content
Snippets Groups Projects
Commit 9c213b1a authored by Martin Lowe's avatar Martin Lowe :flag_ca: Committed by Christopher Guindon
Browse files

Added proper 404 routing using already existing error page


Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent 75b3538a
No related branches found
No related tags found
No related merge requests found
package org.eclipsefoundation.adopters.resource.mappers;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.enterprise.inject.Instance;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.apache.commons.io.IOUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Return the compiled 404 page when a URL mapping is not found.
*
* @author Martin Lowe
*/
@Provider
public class NotFoundMapper implements ExceptionMapper<NotFoundException> {
private static final Logger LOGGER = LoggerFactory.getLogger(NotFoundMapper.class);
@ConfigProperty(name = "eclipse.error.location", defaultValue = "/META-INF/resources/404.html")
Instance<String> errorPageLoc;
@Override
public Response toResponse(NotFoundException exception) {
try (InputStream is = this.getClass().getResourceAsStream(errorPageLoc.get())) {
return Response.status(404).entity(IOUtils.toString(is, StandardCharsets.UTF_8)).build();
} catch (IOException e) {
LOGGER.error("Unable to read in error page at location {}", errorPageLoc.get(), e);
}
return Response.status(404).build();
}
}
......@@ -5,4 +5,5 @@ quarkus.http.port=8080
quarkus.http.root-path=/adopters
## Adopters raw location
eclipse.adopters.path.json=/config/adopters.json
\ No newline at end of file
eclipse.adopters.path.json=/config/adopters.json
%dev.eclipse.adopters.path.json=/tmp/config/adopters.json
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment