java - RESTEasy 404 not found -
i'm trying create api using resteasy, i've been looking hours on differents topics none resolve issues.
i spent 1 hour trying different url's, none worked, project used work when using jersey fact i'm on wildfly 10 it's bit complicated deal without runtime (or maybe not lost time configuring i'm exhausted such steps).
here 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 - 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 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 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 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 , i'm not able catch get. far can remember on topics i've been through, there 10 differents possibles url send request. think tried them all.
could tell me what's wrong in , url should use send damn request ?
thanksfully yours,
there few things must pay attention to:
in container implements servelt api 3.x, such wildfly 10, don't need
web.xml
deployment descriptor when deploying simple web application. in situation, can safely remove it. keep things simple start.in
pom.xml
, ensure have same version of resteasy artifacts.register
apiuserapi
class injaxrsactivator
class using following lines:
@override public set<class<?>> getclasses() { set<class<?>> classes = new hashset<class<?>>(); classes.add(apiuserapi.class); return classes; }
- the url should
http://[host]:[port]/[context]/api/apiuser
.
Comments
Post a Comment