How do I test RestFul web service with Tomcat?
I created a WebService and chose Web Application > Web Services > Restful Web Services. The project was created with the HelloWorld class.
@Path("/helloworld")
...
public static void main(String[] args) throws IOException {
HttpServer server = HttpServerFactory.create("http://localhost:9998/");
server.start();
System.out.println("Server running");
System.out.println("Visit: http://localhost:9998/helloworld");
System.out.println("Hit return to stop...");
System.in.read();
System.out.println("Stopping server");
server.stop(0);
System.out.println("Server stopped");
}
}
How do I run this? The Run > Run isn't visibile even after I compile the project? I want to view it at http://localhost:9998.
My second question is how do I make it work with Tomcat on my local machine? I wen to Run > Edit Configuration and specified Tomcat but I can't make it run there either ;(
Please help. The Web services guide for IDEA is very brief and I am a beginner with IDEA. I really appreociate your help. I have been trying to make it work for over 3 hours now.
请先登录再写评论。
Hello Flank!
Do you want just to run RESTful web service? Or deploy it under Tomcat? These are two different tasks. I guess you just want to play with your RESTful WS and ensure it works. All you need is just to right-click where is your method main and select Run or Debug in a popup. That's it.
Look at the method main:
public static void main(String[] args) throws IOException {
//Here we define end-point (root) of our application
HttpServer server = HttpServerFactory.create("http://localhost:9998/");
//And now we start our WS
server.start();
//...
}
After you've started your service, you can use Tools -> WebServices -> RESTful Web Services -> Test RESTful Web Service
It allows you to easily call methods marked with @GET, @POST, @DELETE etc..