1

I am following this tutorial: https://openliberty.io/guides/microprofile-config-intro.html

I have the following servlet :

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(urlPatterns="/car-types")
public class InventoryServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        System.out.println("Inside the /cat-types servlet preparing to respond with carInventory.html");
        RequestDispatcher view = request.getRequestDispatcher("carInventory.html");
        view.forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}

My webapp folder contains inside the file carInventory.html, however when I access in the browser the link I get the following message: RESTEASY003210: Could not find resource for full path: http://localhost:9080/OpenLibertyExperiments/carInventory.html

The system.out message from the doGet message is seen in the server logs, so the servlet is reached corectly, but the html file is not found...this is what I understand from the error.

This is what features i defined to use:

  <featureManager>
        <feature>servlet-5.0</feature>
        <feature>restfulWS-3.0</feature>
        <feature>jsonp-2.0</feature>
        <feature>jsonb-2.0</feature>
        <feature>cdi-3.0</feature>

        <feature>mpConfig-3.0</feature>
        <feature>mpRestClient-3.0</feature>

        <feature>mpOpenAPI-3.0</feature>
    </featureManager>

enter image description here

Any ideas on what could it be ?

Teshte
  • 624
  • 1
  • 7
  • 26
  • @ScottKurz basically (and maybe this is my mistake) I am going through a series of tutorials on openLiberty. And this is like my 7th. Hence yes, in other packages i do have and use RESTful and `jakarta.ws.rs.core.Application`. The tutorial also has REST and the servlet..see for example `@ApplicationPath("/") public class CarApplication extends Application {}`. – Teshte Nov 30 '22 at 14:36
  • I deleted my comment ... I was looking at the wrong sample/guide. I actually see a different problem with the sample you mentioned... I get an empty page in the browser, but no error. – Scott Kurz Nov 30 '22 at 16:48

2 Answers2

0

So I tried Scott's idea, and commented out all @ApplicationPath annotations that I had in my codebase, with the exception of 1, which was needed, because the js part of the example needed to access an endpoint for data. After doing these changes all seems to be ok.

Bottom line is be careful not to have more than 1 @ApplicationPath in your codebase when using servlets ?

Teshte
  • 624
  • 1
  • 7
  • 26
0

I tried this from the pure servlet perspective to see if it work.

A simple JSP_Forward starting page to a static file (should be the same as your servlet landing page).

starting page is at the root of the application (/). index.html is also at the root /html/500.html is a sub folder with 500.html

request.getRequestDispatcher("/index.html").forward(request,response); request.getRequestDispatcher("index.html").forward(request,response);

request.getRequestDispatcher("/html/500.html").forward(request,response);

I get 200 with the correct content for all the above request.

Can you directly request to /carInventory.html or any static file in your app? If you get 404 for the static request, verify that file-serving-enable configure is allowed.

pmdinh
  • 146
  • 1