jlanza
jlanza

Reputation: 1258

Wildfly service deployed but resource not found

I have just started a webapp project in Wildfly, resteasy using maven. It seems from the logs that the service is correctly deployed, but I don't know what is wrong that I cannot access the resources.

I have tried using the autoscan functionality, defining the @Application, etc. but none of them worked.

The outcome from the server log for the final code I post is:

20:57:25,781 INFO  [stdout] (ServerService Thread Pool -- 66) ************ Constructor **********

20:57:25,781 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 66) RESTEASY002225: Deploying javax.ws.rs.core.Application: class es.domain.prj.rest.JaxRsActivator
20:57:25,781 INFO  [stdout] (ServerService Thread Pool -- 66) ************ Initializing **********

20:58:03,634 INFO  [stdout] (ServerService Thread Pool -- 66) *** REST SERVICE ****

20:58:09,600 INFO  [stdout] (ServerService Thread Pool -- 66) ************ Initializing **********

20:58:11,113 INFO  [stdout] (ServerService Thread Pool -- 66) *** REST SERVICE****

20:58:13,440 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 66) RESTEASY002220: Adding singleton resource es.domain.prj.rest.RestService from Application class es.domain.prj.rest.JaxRsActivator
20:58:13,633 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 66) WFLYUT0021: Registered web context: /prj

I have tried to access to:

http://localhost:8080/prj/jlanza/resource --> Not found

http://localhost:8080/prj/jlanza --> Not found

http://localhost:8080/prj/resource --> Not found

Could you please give me some hints? Where are the resources registered? I know it has to be a quite silly thing, but I'm not able to identify it.

Find below the source code, pom.xml and web.xml files.

Thanks in advance.

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>MyFirstProject</display-name>

  <!-- Auto scan REST service -->
  <context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
  </context-param>

  <context-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>es.domain.prj.rest.JaxRsActivator</param-value>
  </context-param>

  <!-- this needs to be the same as servlet-mapping url-pattern -->
  <!-- set this if you map the Resteasy servlet to something other than /* -->
  <!-- 
  <context-param>
      <param-name>resteasy.servlet.mapping.prefix</param-name>
      <param-value>/resteasy</param-value>
   </context-param>
   -->

  <listener>
    <listener-class>
      org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
  </listener>

  <servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
      org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
  </servlet>

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

</web-app>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>es.domain</groupId>
  <artifactId>prj</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <slf4j.version>1.7.21</slf4j.version>
    <!-- current log4j 2 release -->
    <log4j.version>2.5</log4j.version> 
    <jena.version>3.0.1</jena.version>
    <jboss.resteasy.version>3.0.16.Final</jboss.resteasy.version>
    <javax.cdi-api.version>1.2</javax.cdi-api.version>
    <javax.servlet.version>3.0-alpha-1</javax.servlet.version>

    <maven.plugin.version>3.5.1</maven.plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- Binding for Log4J -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${log4j.version}</version>
        <exclusions>
          <exclusion>
            <artifactId>slf4j-api</artifactId>
            <groupId>org.slf4j</groupId>
          </exclusion>
        </exclusions>
    </dependency>
    <!-- Log4j API and Core implementation required for binding -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>${log4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>${log4j.version}</version>
    </dependency>

    <!-- Import the JAX-RS API, we use provided scope as the API is included 
        in JBoss WildFly -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>${jboss.resteasy.version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <version>${javax.cdi-api.version}</version>
    </dependency>

<!-- 
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>${javax.servlet.version}</version>
      <scope>provided</scope>
    </dependency>
-->     
    <!-- Jena library -->
    <dependency>
       <groupId>org.apache.jena</groupId>
       <artifactId>apache-jena-libs</artifactId>
       <type>pom</type>
       <version>${jena.version}</version>
       <exclusions>
        <exclusion>
          <artifactId>log4j</artifactId>
          <groupId>log4j</groupId>
        </exclusion>
        <exclusion>
          <artifactId>slf4j-log4j12</artifactId>
          <groupId>org.slf4j</groupId>
        </exclusion>
       </exclusions>
    </dependency> 
  </dependencies>

  <build>
    <finalName>prj</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven.plugin.version}</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
     </plugins>
   </build>
</project>

JaxRsActivator.java

package es.domain.prj.rest;

import java.util.HashSet;
import java.util.Set;

//import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

//@ApplicationPath("/api")
public class JaxRsActivator extends Application {

    public JaxRsActivator() {
      System.out.println("************ Constructor **********");
    }

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

    @Override
    public Set<Object> getSingletons() {
  System.out.println("************ Initializing **********");
        Set<Object> singletons = new HashSet<Object>();
        singletons.add(new RestService());
        return singletons;
    }
}

RestService.java

package es.domain.prj.rest;

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

@Path("/jlanza")
public class RestService {

    public RestService() {
      System.out.println("*** REST SERVICE ****");
    }

    @GET
    @Path("resource")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getResource() {
      System.out.println("***Calling function****");
      return Response.status(Status.OK).entity("working").build();
    }
}

Upvotes: 3

Views: 8667

Answers (3)

I don't know if this is going to help someone but, in my case, the problem was the server not being updated on synchronization. And the cause of the problem was the change of the server targeted runtime.

It is something related to this thread: https://developer.jboss.org/thread/276899

The solution was to delete and recreate the runtime and the server.

Upvotes: 1

jlanza
jlanza

Reputation: 1258

The problem is that under the <servlet-name> for <servlet> and <servlet-mapping> I used two different names. That leads to make it impossible to link how to start the service.

Besides I included in my pom file:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-servlet-initializer</artifactId>
        <version>${jboss.resteasy.version}</version>
    </dependency>

Upvotes: 0

Jachk E
Jachk E

Reputation: 530

you app should be accessible at :

http://localhost:8080/prj/jlanza/resource

Try testing your wildfly by checking the port 8080. Then try testing your app by using some extensions available in firefox like Resteasy. You will get http responses wich may help you find the problem.

Upvotes: 1

Related Questions