0

I am trying to catch OData call in Java with WebServlet.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/someservice/UserSet")
public class UserSetServlet extends HttpServlet {

@Override
    protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {

        //some functionality
   }
}

When I call simply "http://somdomain.com/someservice/UserSet", then I get to service, but when I call "http://somdomain.com/someservice/UserSet("SOME_ID")", then I receive 404, that service is not found

Does someone know how I can configure Servlet for catching entire OData Request?

Thanks a lot!

D.K.
  • 1,315
  • 2
  • 11
  • 20
  • 1
    Can't you pass `SOME_ID` as a query parameter e.g. `http://somdomain.com/someservice/UserSet?id=SOME_ID` – Arvind Kumar Avinash Nov 16 '20 at 14:06
  • No, this is standart OData filtering Format for selecting by ID – D.K. Nov 16 '20 at 14:07
  • 1
    The servlet spec and its derivatives, e.g. JAX-RS, do not support this kind of URLs. JAX-RS accepts regular expressions in the paths, but I do not know to what extent does it cover the OData URL specs. You can do several things: (a) forego the URL spec of OData and use "normal" query/path params (b) write a servlet (or JAX-RS) filter that translates the URI and internally forwards to a resource that uses "normal" query/path params (c) search for an existing framework that does this for you. – Nikos Paraskevopoulos Nov 16 '20 at 15:31

1 Answers1

0

Thanks to all answers. Solution - nohow. I starting migration to Spring Framework.

D.K.
  • 1,315
  • 2
  • 11
  • 20