0

I have created simple 3 files in Java, and used mvn clean package wildfly:deploy command to run it. It all deployed successfully (at least thats what is written in console). However, when I go to

http://localhost:8080/lab-rest-api/library/book

I get 404 error. My project is located in module lab-rest-api (its just a part of a project, other modules are for web consume - ejb, ear etc)

I did web service and simple web consuming and it worked out fine. However, REST API is not working.

Here is my pom.xml:

 <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.6.3.Final</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>3.6.3.Final</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>3.6.3.Final</version>
        <scope>provided</scope>
    </dependency>

My extend Application:

@ApplicationPath("/")
public class RESTMain extends Application {
    public RESTMain() {
        System.out.println("whatever");
    }

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

And my service:

@Path("/library")
@Consumes({"application/json"})
@Produces({"application/json"})
public class ServicesInterface {

    Book booky = new Book();

    @GET
    @Path("/book/{title}")
    public Book getBook(@PathParam("title") String title){
        return booky;
    }

    @PUT
    @Path("/book/{title}")
    public Book addBook(@PathParam("title") String title, @QueryParam("author") String author){
        return booky;
    }

    @POST
    @Path("/book/{title}")
    public Book updateBook(@PathParam("title") String title, String author){
        return booky;
    }


    @DELETE
    @Path("/book/{title}")
    public Book removeBook(@PathParam("title") String title){
        return booky;
    }

}

"Book" is a simple class with 2 Strings (author and title) and getters and setters for it.

LauraAlice
  • 33
  • 6

2 Answers2

0

You seems didn't implement the Get for \book. You only implemented \book\{title}

for your current implementation, try \book\{meaningful title in your database}

Qingfei Yuan
  • 1,196
  • 1
  • 8
  • 12
0

Okay so,

Steps to fix this :

1) Packaging a war

Add <packaging>war</packaging> to your pom file. Also add

<plugin> 
  <artifactId>maven-war-plugin</artifactId> 
  <version>2.4</version> 
  <configuration> 
    <failOnMissingWebXml>false</failOnMissingWebXml> 
    </configuration> 
</plugin>

2) Upgrade wildfly maven plugin

<version.wildfly.maven.plugin>2.0.1.Final</version.wildfly.maven.plugin>

3) Remove duplicate dependency

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
    <scope>compile</scope>
</dependency>

4) Remove this extra stuff from wildfly-maven-plugin configuration

<inherited>true</inherited>
<configuration>
    <skip>true</skip>
</configuration>

5) Run your mvn clean package wildfly:deploy

6) Browse to http://localhost:8080/lab-rest-api-1.0-SNAPSHOT/library/book/asd

BONUS : Accepted answer of this shows how to remove -1.0-SNAPSHOT from the URL.

Ali Ben Zarrouk
  • 1,891
  • 16
  • 24