Deploying the RESTful Jersey 1.11 web service in the final of JBoss 6.1 (RestEasy is no longer deployed)

Sorry in advance for the wall with the text, but I wanted to be thorough, so as not to waste time, kind StackOverflowers. :-)

I successfully deployed and tested the RESTful web service in Tomcat 7 as a war file, since JBoss uses Tomcat as a component, I (mistakenly) thought the deployment would be as simple as deleting the war file in my JBoss 6.1 server / default / deploy, no! At first I received a message stating that only one JAX-RS application class is allowed, this was easily fixed by removing resteasy.deployer from deployers / dir in Jboss (all standard and standard servers are only for thorough checking).

Now the bottom line is that when I start Jboss, I get the following messages:



    10:38:07,431 INFO  [PackagesResourceConfig] Scanning for root resource and provider classes in the packages:
    net.ussouth.incomm.SPIL.resource
    10:38:07,486 INFO  [WebApplicationImpl] Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
    10:38:07,718 SEVERE [RootResourceUriRules] The ResourceConfig instance does not contain any root resource classes.
    10:38:07,719 ERROR [[/SPIL]] 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.(RootResourceUriRules.java:99) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771) [:1.11]

, WEB-INF/classes:



    package net.ussouth.incomm.SPIL.resource;

    import javax.ws.rs.Path;
    import javax.ws.rs.POST;
    import javax.ws.rs.Consumes;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.Produces;
    import javax.ws.rs.FormParam;

    import org.apache.log4j.Logger;

    @Path("/message")
    public class MessageResource {
      private static Logger log = Logger.getLogger(MessageResource.class);


      @POST
      @Path("/Search")
      @Produces(MediaType.APPLICATION_XML)
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      public String search(@FormParam("message") String _msgToProvider, @FormParam("provider") String _provData) {
        log.info("MesageResource.search method called");
        String outVal = null;

        try{
          ProviderHandler hnd = new ProviderHandler();
          outVal = hnd.getOffers(_msgToProvider);

        } catch(JAXBException ex) {
          ...
        } catch (SearchException ex) {
          ...
        }

        return outVal;
      }     
    }

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID" 
  version="2.5">

  <display-name>Spil</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>SpilMessageService</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>net.ussouth.incomm.SPIL.resource</param-value>
    </init-param>

    <init-param>
      <param-name>log4j-properties-location</param-name>
      <param-value>classes/log4j.xml</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpilMessageService</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

</web-app>

, jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
    <context-root>SPIL</context-root>
</jboss-web>

. 1,5 , .

+1
2

, , JAX-RS, . javax.ws.rs.core.Application

import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;

public class MyApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<Class<?>>();
        // register resources
        classes.add(MessageResource.class);
        return classes;
    }
}

web.xml, . , .

<?xml version="1.0" encoding="UTF-8"?>
    <web-app
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID"
        version="2.5">

    <display-name>Spil</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>SpilMessageService</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>net.ussouth.incomm.SPIL.resource.MyApplication</param-value>
        </init-param>

        <init-param>
            <param-name>log4j-properties-location</param-name>
            <param-value>classes/log4j.xml</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan.providers</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan.resources</param-name>
        <param-value>false</param-value>
    </context-param>

    <servlet-mapping>
        <servlet-name>SpilMessageService</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>
+4

Orf

(Jersey 1.11 + tomcat 7). , tomcat 6, !

, , .

0

All Articles