What is the purpose of CXF servlet

New2Java :

I was going through a demo project setup for Restful webservice using Apache CXF, where I happened to come by a piece of code inside web.xml:

    <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

I did not really understand the use of a servlet class in this web.xml. I googled for org.apache.cxf.transport.servlet.CXFServlet and found:

The CXFServlet class, which is defined by Apache CXF, is generated and registered to handle incoming requests.

Now, I really do not understand what that line means

  1. Does this servlet pose as a front-controller, like in Spring MVC flow?
  2. What is the actual purpose of using this servlet class?
  3. How does CXF use Spring to provide XML configuration of services defined in the project?
  4. Does org.glassfish.jersey.servlet.ServletContainer serve the same purpose in Jersey Implementation as org.apache.cxf.transport.servlet.CXFServlet with Apache CXF?

Help me clarify these questions.

Paul Samsotha :

The JAX-RS specification is built on top of the Servlet specification. Each implementation should have a Servlet as an entry point to the application. When a request comes in, it gets processed by that Servlet. CXFServlet is CXF's implementation of that entry point Servlet.

Does this servlet pose as a front-controller, like in Spring MVC flow?

Pretty much. It's analogous to Spring MVC's DispatcherServlet

What is the actual purpose of using this servlet class?

As mentioned above, it's the entry point to the JAX-RS (CXF) application.

How does CXF use Spring to provide XML configuration of services defined in the project?

It uses Spring to wire up components; connect all of them together. But it's not required (see also).

Does org.glassfish.jersey.servlet.ServletContainer serve the same purpose in Jersey Implementation as org.apache.cxf.transport.servlet.CXFServlet with Apache CXF?

Pretty much.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=108542&siteId=1