0

I've developed a server application using Jersey 1.19 in order to expose some REST web services. The application is deployed in JBoss 7.1.1 as a WAR file. During deployment, I'm getting the following exception:

12:23:37,497 INFO  [com.sun.jersey.api.core.PackagesResourceConfig] (MSC service thread 1-6) Scanning for root resource and provider classes in the packages:
  com.link.frontend.webservices.v2
12:23:37,507 INFO  [com.sun.jersey.server.impl.application.WebApplicationImpl] (MSC service thread 1-6) Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
12:23:37,609 SEVERE [com.sun.jersey.server.impl.application.RootResourceUriRules] (MSC service thread 1-6) The ResourceConfig instance does not contain any root resource classes.
12:23:37,612 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Link]] (MSC service thread 1-6) StandardWrapper.Throwable: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
        at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) [jersey-core-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) [jersey-servlet-1.19.jar:1.19]
        at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]

12:23:37,647 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Link]] (MSC service thread 1-6) Servlet /Link threw load() exception: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
        at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) [jersey-core-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) [jersey-server-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) [jersey-servlet-1.19.jar:1.19]
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) [jersey-servlet-1.19.jar:1.19]
        at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]

My resource class is as follows:

package com.link.frontend.webservices.v2;

import java.sql.Connection;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import org.apache.log4j.MDC;

import com.sun.jersey.api.core.HttpContext;
import com.sun.jersey.oauth.server.OAuthServerRequest;
import com.sun.jersey.oauth.signature.OAuthParameters;
import com.link.frontend.controllers.DBManager;
import com.link.frontend.controllers.DeviceManager;
import com.link.frontend.controllers.OAuthenticationManager;
import com.link.frontend.exceptions.DeviceAuthenticationException;
import com.link.frontend.exceptions.ExcessiveCallsException;
import com.link.frontend.exceptions.InactiveDeviceException;
import com.link.frontend.exceptions.InvalidInputException;
import com.link.frontend.model.ExposedErrorCodes;
import com.link.frontend.model.exposed.DeviceList;

@Path("/devices")
public class DeviceWS
{

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getAllDevices(@Context HttpContext httpContext)
    {
      //Business logic here
    }

}

My web.xml file is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more 
    contributor license agreements. See the NOTICE file ~ distributed with this 
    work for additional information ~ regarding copyright ownership. The ASF 
    licenses this file ~ to you under the Apache License, Version 2.0 (the ~ 
    "License"); you may not use this file except in compliance ~ with the License. 
    You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 
    ~ ~ Unless required by applicable law or agreed to in writing, ~ software 
    distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT 
    WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the 
    License for the ~ specific language governing permissions and limitations 
    ~ under the License. -->

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

<web-app>
    <display-name>Link</display-name>
    <servlet>
        <servlet-name>V2</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.link.frontend.webservices.v2</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>V2</servlet-name>
        <url-pattern>/api/v2/*</url-pattern>
    </servlet-mapping>

</web-app>

Since I'm using JBoss 7.1.1, I cannot exclude a subsystem using the following in a jboss-deployment-structure.xml:

  <exclude-subsystems>  
      <subsystem name="jaxrs" />  
      <subsystem name="webservices" />  
    </exclude-subsystems>  

So instead, I deleted the reference to "jaxrs" from my standalone.xml

The twist to the above exception is that if I use an exploded version of the same WAR file (As a folder that sits in the deployments directory), everything works flawlessly.

What do you think is the problem?

Mouhammed Soueidane
  • 1,056
  • 2
  • 24
  • 42
  • getAllDevices() has no Path annotation. That makes it a sub-resource locator. https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e2464 – Gimby Feb 09 '16 at 13:03
  • But why would my project work in its exploded form, and not work when everything is inside a compressed WAR? – Mouhammed Soueidane Feb 09 '16 at 13:09
  • No idea. I only call out what I can see and that is a documented reason for getting that exception. Do note that your web.xml is absolutely not correct, it is defining a servlet 2.3 spec compliance while you want at least servlet 2.5 spec or higher. This question shows a better web.xml root node: http://stackoverflow.com/questions/15985378/what-exactly-is-the-web-app-version-what-does-it-affect – Gimby Feb 09 '16 at 14:12
  • It seems that this is unrelated. My web.xml is perfectly understood by JBoss 7, and it's picking up the Jersey resources pretty well when my archive file is working in "exploded" mode. – Mouhammed Soueidane Feb 12 '16 at 14:07

0 Answers0