Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RESTful service with EJB 3.1 endpoint cannot be found (404)

asarkarJul 24 2011 — edited Jul 24 2011
Hi,
I have a Resource configured as a EJB 3.1 Stateless Bean. I also have an overridden Application class to customize the context root. However, the client just cannot seem to find the Resource. What am I doing wrong? The Resource is packaged and deployed as a war.

Cross posted: http://www.coderanch.com/t/546565/java-Web-Services-SCDJWS/certification/RESTful-service-EJB-endpoint-cannot#2480046
Tests in error: 
  testSendRequestAndGetGreeting(name.app.abhi.helloworld.ejb.restful.client.HelloWorldEjbRestfulClientTest): GET http://localhost:9090/practice/helloworld?name=Duke returned a response status of 404 Not Found
Resource:
@Path("helloworld")
@Stateless
public class HelloWorldBean {

    @GET
    @Produces("text/plain")
    public String getQuintessentialGreeting(@QueryParam("name") String name) {
	if (name == null) {
	    throw new WebApplicationException(Response.Status.BAD_REQUEST);
	}

	return "Say hello to the world, " + name;
    }
}
Application class:
@ApplicationPath("practice")
public class ApplicationConfig extends Application {

    @Override
    public Set<Class<?>> getClasses() {
	Set<Class<?>> clazzez = super.getClasses();

	if (clazzez == null) {
	    clazzez = new HashSet<Class<?>>();
	}

	clazzez.add(name.app.abhi.helloworld.ejb.restful.service.HelloWorldBean.class);

	return clazzez;
    }
}
Client:
public class HelloWorldEjbRestfulClient {
    private final static String ENDPOINT_URI = "http://localhost:9090/"
	    + "practice/helloworld";

    public String sendRequestAndGetGreeting(String name) {
	Client client = Client.create();
	WebResource webResource = client.resource(ENDPOINT_URI);
	webResource.accept(MediaType.TEXT_PLAIN);
	return webResource.queryParam("name", name).get(java.lang.String.class);
    }
}
Edited by: asarkar on Jul 24, 2011 12:20 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2011
Added on Jul 24 2011
1 comment
240 views