I'm trying to build a webapp with plain JavaEE. I'm rendering the frontend using FTL. For this I used jax-rs endpoints like the following:
@RequestScoped
@Path("/{lang}")
public class MarkupResource {
@GET
@Produces(MediaType.TEXT_HTML)
public Response index(@PathParam("lang") String lang) {
try (Writer stringWriter = new StringWriter()) {
markupBuildService.buildIndex(stringWriter, lang);
return Response.ok(stringWriter.toString()).type(MediaType.TEXT_HTML).build();
} catch (IOException ioException){
System.out.println(ioException.getMessage());
//return 404 page
return Response.serverError().entity(ioException.getMessage()).build();
} catch (Exception e) {
System.out.println(e.getMessage());
//return 500 page
return Response.serverError().entity(e.getMessage()).build();
}
}
my static content (css, js ...) is located in the webapp folder.
now my problem kicks in: I have to use the generated JAXRSConfiguration
@ApplicationPath("/fe")
public class JAXRSConfiguration extends Application {
}
because when i'm not, it doesnt resolve my static content because it's looking for a jaxrs endpoint.
when forwarding my user via a webserver (nginx e.g) it pushes me to the correct domain (e.g. http:mypage.com/ pointing to localhost:8080/shop/fe/lang ) but then it's unable to resolve the path to my css & js.
I'm getting the contextPath via
public class FW {
String contextPath0;
String contextPath;
FW(HttpServletRequest request) {
contextPath0 = request.getContextPath();
contextPath = contextPath0 + "/";
}
public String getContextPath() {
return contextPath0;
}
public String url(String path) {
if (path.startsWith("/")) return contextPath0 + path;
return contextPath + path;
}
}
and using it like this:
<link rel="stylesheet" type="text/css" href="${fw.contextPath}/css/style.css" />
Do you have an idea how to resolve this issue?
Thanks in advance!