0

I have a rest service implemented as follows

@Stateless
@Path("/Person")
@Produces(MediaType.APPLICATION_XML)
public class RestService {

    @PersistenceContext(unitName = "mysqlPU")
    EntityManager em;

    @GET
    @Path("{id}")
    public Response Book(@PathParam("id") Long id) {
        Person person = em.find(Person.class, id);
        if(person == null) {
            return Response.status(Response.Status.FORBIDDEN).build();
        }
        return Response.ok(person).build();
    }
}

@ApplicationPath("/rs")
public class ApplicationConfig extends Application {

    private final Set<Class<?>> classes;

    public ApplicationConfig() {
        HashSet<Class<?>> c = new HashSet<Class<?>>();

        c.add(RestService.class);

        classes = Collections.unmodifiableSet(c);
    }

    @Override
    public Set<Class<?>> getClasses() {
        return classes;
    }

}

It is packaged in a jar file with other ejbs, outside of any .war. I'm am only able to access the service if I happen to have a war package inside the ear. I can access it with the context root of the war such as localhost:8080/warContextRoot/rs/. Is there any way to deploy a rest service without also deploying a war and still access it?

rubixibuc
  • 7,111
  • 18
  • 59
  • 98

1 Answers1

0

I think the reason is that you implemented the REST web service within an EJB session bean and EJBs are typically bundled in EAR files.

An alternative is that you can implement the REST web service as a regular Servlet, which serves requests through its standard GET/POST methods, then it can be deployed in a WAR. And you can invoke the REST web service through an URL defined in servlet mapping of web.xml.

Hope this helps.

shuang
  • 246
  • 2
  • 5