Hi

You have /categoryservice specified twice at both jaxrs:server/@address & CategoryService.

Set "/" at either of those.

For ex, you can have multiple jaxrs:endpoints routing to the same CategoryService, with each endpoint having its own configuration

HTH, Sergey
On 01/07/16 11:06, Dinesh Babu wrote:
Hi,

I can see that my rest webservice is deployed in tomcat+cxf environment when I 
fire the URL http://localhost:8080/cxftutorial/categoryservice?_wadl

But when I try to access one of the we service end points 
http://localhost:8080/cxftutorial/categoryservice/category/001/books , I get 
the following error in the console.


WARNING: No root resource matching request path 
/cxftutorial/categoryservice/category/001/books has been found, Relative Path: 
/category/001/books. Please enable FINE/TRACE log level for more details.
Jul 01, 2016 10:55:41 AM 
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.NotFoundException
        at 
org.apache.cxf.jaxrs.utils.SpecExceptions.toNotFoundException(SpecExceptions.java:87)
        at 
org.apache.cxf.jaxrs.utils.ExceptionUtils.toNotFoundException(ExceptionUtils.java:117)
        at 
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:184)
        at 
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:88)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
        at 
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at 
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:241)
        at 
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)
        at 
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)
        at 
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)
        at 
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
        at 
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
        at 
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:211)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
        at 
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



web.xml:

<!-- <!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.5//EN"
"http://java.sun.com/dtd/web-app_2_5.dtd"; > -->

<web-app xmlns="http://java.sun.com/xml/ns/javaee";
                                        
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                                        
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
                                        version="2.5">
<!--<web-app>-->
   <display-name>Archetype Created Web Application</display-name>
     <context-param>
         <param-name>contextConfiglocation</param-name>
         <param-value>/WEB-INF/applicationContext.xml</param-value>
         
<!--<param-value>/WEB-INF/bean.xml,/WEB-INF/applicationContext.xml</param-value>-->
     </context-param>
     <listener>
         
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
     <servlet>
         <servlet-name>CXFServlet</servlet-name>
         
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
         <servlet-name>CXFServlet</servlet-name>
         <url-pattern>/*</url-pattern>
     </servlet-mapping>
</web-app>


applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xmlns:context="http://www.springframework.org/schema/context";
        xmlns:jaxws="http://cxf.apache.org/jaxws";
        xmlns:jaxrs="http://cxf.apache.org/jaxrs";
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
       http://cxf.apache.org/jaxrs
       http://cxf.apache.org/schemas/jaxrs.xsd
       http://cxf.apache.org/jaxws
       http://cxf.apache.org/schemas/jaxws.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.1.xsd";>

     <import resource="classpath:META-INF/cxf/cxf.xml" />
     <context:component-scan base-package="com.dinesh.tutorial.*" />


     <jaxrs:server id="categoryservice" address="/categoryservice">
         <jaxrs:serviceBeans>
             <ref bean="categoryService" />
         </jaxrs:serviceBeans>
     </jaxrs:server>

     <bean id="categoryService" 
class="com.dinesh.tutorial.cxf.book.CategoryService">
         <property name="categoryDAO">
             <ref bean="categoryDAO" />
         </property>
     </bean>
     <bean id="categoryDAO" class="com.dinesh.tutorial.cxf.book.CategoryDAO">
         <!--  wire dependency-->
     </bean>

</beans>


categoryService.java

package com.dinesh.tutorial.cxf.book;

//JAX-RS Imports
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;

/*
* CategoryService class - Add/Removes category for books
  */

@Path("/categoryservice")
@Produces("application/xml")
public class CategoryService {

        public CategoryDAO categoryDAO;
//     private CategoryDAO categoryDAO = new CategoryDAO();

        public CategoryDAO getCategoryDAO() {
              return categoryDAO;
        }

        public void setCategoryDAO(CategoryDAO categoryDAO) {
              this.categoryDAO = categoryDAO;
        }

        @POST
        @Path("/category")
        @Consumes("application/xml")
        public Response addCategory(Category category) {

              System.out.println("addCategory called");

              Category cat = (Category) getCategoryDAO().getCategory(
                            category.getCategoryId());

              if (cat != null) {
                     return Response.status(Status.BAD_REQUEST).build();
              } else {
                     getCategoryDAO().addCategory(category);
                     return Response.ok(category).build();
              }

        }

        @GET
        @Path("/category/{id}")
        public Category getCategory(@PathParam("id") String id) {

              System.out.println("getCategory called with category id: " + id);

              Category cat = (Category) getCategoryDAO().getCategory(id);
              if (cat == null) {
                     ResponseBuilder builder = 
Response.status(Status.BAD_REQUEST);
                     builder.type("application/xml");
                     builder.entity("<error>Category Not Found</error>");
                     throw new WebApplicationException(builder.build());
              } else {
                     return cat;
              }
        }

        @DELETE
        @Path("/category/{id}")
        public Response deleteCategory(@PathParam("id") String id) {

              System.out.println("deleteCategory with category id : " + id);

              Category cat = (Category) getCategoryDAO().getCategory(id);
              if (cat == null) {
                     return Response.status(Status.BAD_REQUEST).build();
              } else {
                     getCategoryDAO().deleteCategory(id);
                     return Response.ok().build();
              }
        }

        @PUT
        @Path("/category")
        public Response updateCategory(Category category) {

              System.out.println("updateCategory with category id : "
                            + category.getCategoryId());

              Category cat = (Category) getCategoryDAO().getCategory(
                            category.getCategoryId());
              if (cat == null) {
                     return Response.status(Status.BAD_REQUEST).build();
              } else {
                     getCategoryDAO().updateCategory(category);
                     return Response.ok(category).build();
              }
        }

        @POST
        @Path("/category/book")
        @Consumes("application/xml")
        public Response addBooks(Category category) {

              System.out.println("addBooks with category id : "
                            + category.getCategoryId());

              Category cat = (Category) getCategoryDAO().getCategory(
                            category.getCategoryId());
              if (cat == null) {
                     return Response.status(Status.NOT_FOUND).build();
              } else {
                     getCategoryDAO().addBook(category);
                     return Response.ok(category).build();
              }
        }

        @GET
        @Path("/category/{id}/books")
        @Consumes("application/xml")
        public Response getBooks(@PathParam("id") String id) {

              System.out.println("getBooks called with category id : " + id);

              Category cat = (Category) getCategoryDAO().getCategory(id);

              if (cat == null) {
                     return Response.status(Status.NOT_FOUND).build();
              } else {
                     cat.setBooks(getCategoryDAO().getBooks(id));
                     return Response.ok(cat).build();

              }
        }

}


Thanks,
Dinesh


________________________________




--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to