Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey JAX-RS REST 404 in Openshift, working well in local Tomcat

I am pretty new to Jersey REST. I follow the tutorial http://javapapers.com/java/restful-web-services-with-java-jax-rs-using-jersey/. It works well locally on Tomcat 7. But when I deploy it into Openshift, I simply got 404 not found.

This is my web.xml

  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.market.ws</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

And this is my resource

@Path("/api")
public class TicketsResource {
    // Allows to insert contextual objects into the class,
    // e.g. ServletContext, Request, Response, UriInfo
    @Context
    UriInfo uriInfo;
    @Context
    Request request;

    // Return the list of todos to the user in the browser
    // With the browser you can only issue HTTP GET requests\
    @Path("/query")
    @GET
    @Produces(MediaType.TEXT_XML)
    public List<Ticket> getTicketsBrowser() {
        List<Ticket> tickets = new ArrayList<Ticket>();
        tickets.addAll(TicketDao.instance.getModel().values());
        return tickets;
    }

    // Return the list of todos for applications
    // Default for browser GET
    @Path("/query")
    @GET
    @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
    public List<Ticket> getTickets() {
        List<Ticket> tickets = new ArrayList<Ticket>();
        try {
            tickets.addAll(TicketDao.instance.getModel().values());
        } catch(Exception e) {
            e.printStackTrace();
        }
        return tickets;
    }
}

I use http://localhost:8080/myproject/api/query and it works fine. But in openshift I use http://market-domain.rhcloud.com/myproject/api/query or http://market-domain.rhcloud.com/api/query it doesn't work. I tried to deploy using Tomcat 7 or JBoss AS 7 but they both gave me the same error. I didn't find any error in log file. Looks like the resource simply doesn't exist. I am wondering is my url wrong or anything else? I should be able to query this rest ws immediately after deploy, right? Thanks in advance.

like image 663
He Zhang Avatar asked Apr 16 '15 15:04

He Zhang


1 Answers

Finally I found out it's my war file problem. I used maven build for 3 projects but it doesn't work. Then I just use export war in Eclipse to generate war file. Then resource can be found after deploying.

like image 174
He Zhang Avatar answered Nov 11 '22 17:11

He Zhang