Reputation: 33
i'm trying to create an API using RESTEasy, i've been looking for hours on differents topics but none could resolve my issues.
I spent one hour trying different url's, none worked, the project used to work when i was using jersey but the fact is that i'm on wildfly 10 so it's a bit complicated to deal without runtime (or maybe not but i already lost so much time configuring everything that i'm exhausted with such steps).
Here is my WEB.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>api</display-name>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>RestEasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>api</param-name>
<param-value>api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestEasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Here is my Application class
@ApplicationPath("/api")
public class JaxRSActivator extends Application {
public JaxRSActivator() {
// TODO Auto-generated constructor stub
System.out.println("Je passe dans le constructeur de l'application");
}
}
Here is an exposed service :
package api;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import entities.ApiUser;
@Path("ApiUser")
public class ApiUserAPI {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createUser(ApiUser user) {
System.out.println("JE PASSE DANS LE POST");
if (user.getUsername() == null && user.getPwd() == null)
return Response.status(404).build();
return Response.status(200).build();
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response findUser() {
System.out.println("JE PASSE DANS LE GET");
return Response.status(200).build();
}
}
Here is the pom
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.2.Final</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson-provider -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.19.Final</version>
</dependency>
I've been working 3 hours on this and i'm not even able to catch a GET. As far as i can remember on all topics i've been through, there were almost 10 differents possibles URL to send this request. I think i tried them all.
Could someone tell me what's wrong in it and eventually the url i should use to send this damn GET request ?
ThanksFully yours,
Upvotes: 2
Views: 7187
Reputation: 130867
There are a few things you must pay attention to:
In a container that implements the Servelt API 3.x, such as WildFly 10, you don't need the web.xml
deployment descriptor when deploying a simple web application. In your situation, you can safely remove it. Keep the things simple to start.
In your pom.xml
, ensure you have the same version of all RESTEasy artifacts.
Register the ApiUserAPI
class in your JaxRSActivator
class by using the following lines:
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(ApiUserAPI.class);
return classes;
}
http://[host]:[port]/[context]/api/ApiUser
.Upvotes: 4