Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enabling auto scanning using resteasy 3.0.10 with wildfly 8.2

I am trying to figure out what is my problem while setting up new Wildfly 8.2 server with simple restEasy 3.0.10 application.

my web application is supre easy.

src/main/
   java/my-package/
      RootApplication.java
      HomePageResource.java
   webapp/
      index.html
      WEB-INF/
         beans.xml
         web.xml

web.xml and beans.xml look like this

---- web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         metadata-complete="false">
</web-app>
---- beans.xml
<beans 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/beans_1_0.xsd">
</beans>

in RootApplication.java I have

@ApplicationPath("/app")
public class RootApplication extends Application
{
    private Set<Object> singletons = new HashSet<>();

    public RootApplication()
    {
        singletons.add(new HomePageResource());
    }

    @Override
    public Set<Object> getSingletons()
    {
        return singletons;
    }
}

// ResourceProvider is a simple class hiding getResource and createStreamer
@Path("/")
public class HomePageResource extends ResourceProvider
{
    private final static Logger logger = LoggerFactory.getLogger(HomePageResource.class);

    @GET
    @Produces(MediaType.TEXT_HTML)
    public Response getHomePage()
    {
        final InputStream homePageResource = getResource("/static/view/home/home.html");
        return Response.ok(createStreamer(homePageResource)).build();
    }
}

which works but I have never specified any resource classes inside Application and RestEasy was always able to scan WAR content. And if I remove everything from RootApplication, like this.

@ApplicationPath("/app")
public class RootApplication extends Application
{
}

Anyway documentation also says (https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/)

Since we're not using a jax-rs servlet mapping, we must define an Application class that is annotated with the @ApplicationPath annotation. If you return any empty set for by classes and singletons, your WAR will be scanned for JAX-RS annotation resource and provider classes.

any hints what I may do wrong with this simple setup??? and another question can I remove beans.xml to use guice DI, I understand this problem has nothing to do with CDI/WELD.

my pom.xml looks like this

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-bom</artifactId>
            <version>3.0.10</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
    </dependency>
</dependencies>
like image 959
kamiseq Avatar asked Dec 16 '14 20:12

kamiseq


1 Answers

There is a good tutorial by mkyong which provides you examples on how to configure your web service application with or without resteasy.scan.

Based on your question your web.xml is empty? That would mean resteasy.scan is set to false as per documentation:

resteasy.scan - Default value: false - Automatically scan WEB-INF/lib jars and WEB-INF/classes directory for both @Provider and JAX-RS resource classes (@Path, @GET, @POST etc..) and register them

I usually set resteasy.scan to false and register my resources manually, because sometimes my WEB-INF/lib jars were containing providers/resources and they broke my application. Here is the configuration I am using:

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_3_0.xsd" 
    id="WebApp_ID" version="3.0">
    <display-name>My application name</display-name>

    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>false</param-value>
    </context-param>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.foo.bar.Configuration</param-value>
    </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

Configuration.java

package com.foo.bar;

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

public class Configuration extends Application {

    public Configuration() {
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(EntryPoint.class);
        return classes;
    }

}
like image 81
Daniel Szalay Avatar answered Nov 18 '22 20:11

Daniel Szalay