Reputation: 138
I have made a barebones hello world webservice using netbeans and jersey. My problem is when I deploy my webservice to the server (I'm using glass fish) It takes me to the index page, but I cannot invoke the method I created in the java class.
The domain my glass fish service is using is
http://localhost:8080/HelloWorldApp/
To invoke my method (from what ive read) this is the way to do it:
http://localhost:8080/HelloWorldApp/helloworld
However this gives me a 404. Ive followed many examples but cant seem to invoke the method in my web browser.
I can however invoke the method when I click test RESTful Webservices in netbeans.
Here is how I Defined the Method:
package HelloWorldResource;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/helloworld")
public class Hellworld {
@Context
private UriInfo context;
/**
* Creates a new instance of Hellworld
*/
public Hellworld() {
}
/**
* Retrieves representation of an instance of HelloWorldResource.Hellworld
* @return an instance of java.lang.String
*/
@GET
@Produces(MediaType.TEXT_HTML)
public String getHtml() {
//TODO return proper representation object
return "<HTML>Hello</HTML>";
}
/**
* PUT method for updating or creating an instance of Hellworld
* @param content representation for the resource
*/
@PUT
@Consumes(MediaType.TEXT_HTML)
public void putHtml(String content) {
}
Upvotes: 0
Views: 575
Reputation: 331
Please share you web.xml and resource config implementation. If you have any custom resource config implementation, then your resource file has to be registered in the resource config implementation. For details please refer http://cloudskol.com/index.php/2015/09/22/simple-get-method-implementation-in-restful-java/
Upvotes: 0
Reputation: 138
I looked up another tutorial and found some information. Theres a java class that's created called "ApplicationConfig.java" that has this tag: @javax.ws.rs.ApplicationPath("webresources")
so I had to invoke the method using this uri http://localhost:8080/HelloWorldApp/webresources/helloworld
Upvotes: 1