Getting Started with RESTful WebServiceRESTful WebService is a much simpler, more lightweight Web service than SOAP message-based webservice, and restful webservice is stateless, and it's easy to publish and invoke. Here is the simplest example of Hello world to have a perceptual knowledge of restful webservice. Because a very professional and theoretical description of restful webservice is a painful thing to understand. Look at the example to know a general, and then see the theory is much easier to understand./**
* Getting Started with RESTful WebService
* @author leizhimin 2009-11-18 16:42:43
*/
PackageExample
ImportCom.sun.jersey.api.container.httpserver.HttpServerFactory;
ImportCom.sun.net.httpserver.HttpServer;
ImportJavax.ws.rs.GET;
ImportJavax.ws.rs.Path;
ImportJavax.ws.rs.Produces;
ImportJava.io.IOException;
//Specify URI
@Path ("/helloworld")
PublicclassHelloWorld {
//Handling Get requests for HTTP
@GET
//The content format for processing request feedback is "Text/plain"
@Produces ("Text/plain")
PublicString Getclichedmessage () {
return"Hello world!";
}
PublicStaticvoidMain (string[] args)throwsIOException {
//Create RESTful WebService service
Httpserver Server = Httpserverfactory.create ("http://192.168.14.117:9999/");
//Start the service, which will cause a new thread to open
Server.start ();
//Output Some information about the service to the console
System.out.println ("RESTful WebService service has been started");
System.out.println ("Service Access address: http://192.168.14.117:9999/helloworld");
}
}Run this class, console input: 2009-11-18 17:25:37 com.sun.jersey.api.core.ClasspathResourceConfig Init
Information: Scanning forRoot resource and provider classes in the paths:
D:\jdk16\jre\lib\alt-rt.jar
D:\jdk16\jre\lib\charsets.jar
D:\jdk16\jre\lib\deploy.jar
D:\jdk16\jre\lib\javaws.jar
D:\jdk16\jre\lib\jce.jar
D:\jdk16\jre\lib\jsse.jar
D:\jdk16\jre\lib\management-agent.jar
D:\jdk16\jre\lib\plugin.jar
D:\jdk16\jre\lib\resources.jar
D:\jdk16\jre\lib\rt.jar
D:\jdk16\jre\lib\ext\dnsns.jar
D:\jdk16\jre\lib\ext\localedata.jar
D:\jdk16\jre\lib\ext\sunjce_provider.jar
D:\jdk16\jre\lib\ext\sunmscapi.jar
D:\jdk16\jre\lib\ext\sunpkcs11.jar
D:\netwideo\restws\out\production\restws
D:\IDEA8\lib\javaee.jar
D:\netwideo\restws\lib\mail-1.4.jar
D:\netwideo\restws\lib\asm-3.1.jar
D:\netwideo\restws\lib\wadl2java.jar
D:\netwideo\restws\lib\jettison-1.0.1.jar
D:\netwideo\restws\lib\grizzly-servlet-webserver-1.8.6.4.jar
D:\netwideo\restws\lib\wadl-core.jar
D:\netwideo\restws\lib\localizer.jar
D:\netwideo\restws\lib\jdom-1.0.jar
D:\netwideo\restws\lib\jsr311-api-1.0.jar
D:\netwideo\restws\lib\stax-api-1.0-2.jar
D:\netwideo\restws\lib\persistence-api-1.0.2.jar
D:\netwideo\restws\lib\jaxb-api-2.1.jar
D:\netwideo\restws\lib\wadl-cmdline.jar
D:\netwideo\restws\lib\http-20070405.jar
D:\netwideo\restws\lib\rome-0.9.jar
D:\netwideo\restws\lib\activation-1.1.jar
D:\netwideo\restws\lib\jaxb-impl-2.1.10.jar
D:\netwideo\restws\lib\jersey-bundle-1.0.3.jar
D:\netwideo\restws\lib\jackson-lgpl-0.9.4.jar
D:\netwideo\restws\lib\FastInfoset-1.2.2.jar
D:\netwideo\restws\lib\jaxb-xjc.jar
D:\IDEA8\lib\idea_rt.jar
2009-11-18 17:25:46 com.sun.jersey.api.core.ClasspathResourceConfig Init
Info: Root Resource classes found:
classExample. HelloWorld
2009-11-18 17:25:46 com.sun.jersey.api.core.ClasspathResourceConfig Init
Information: Provider classes found:
RESTful WebService Service has been started
Service Access address: http://192.168.14.117:9999/helloworldVisible, the service started successfully, down is to access the service from the browser, input Http://192.168.14.117:9999/helloworld, will send an HTTP GET request to see the result: the test was successful! --------------------This project since a lot of packages, some things sun, some not, here I put all out, the whole project put in the attachment, in Jdk5, 6 under the operation can be. Unfortunately, the attachment can upload the largest 6M of things, this more than 6M, can only wait for 51cto to relax the size of the upload file. Each limit is best within 10M. ----hope:), here I list the use of the package bar: Activation-1.1.jar
Asm-3.1.jar
Fastinfoset-1.2.2.jar
Grizzly-servlet-webserver-1.8.6.4.jar
Http-20070405.jar
Jackson-lgpl-0.9.4.jar
Jaxb-api-2.1.jar
Jaxb-impl-2.1.10.jar
Jaxb-xjc.jar
Jdom-1.0.jar
Jersey-bundle-1.0.3.jar
Jettison-1.0.1.jar
Jsr311-api-1.0.jar
Mail-1.4.jar
Localizer.jar
Persistence-api-1.0.2.jar
Rome-0.9.jar
Stax-api-1.0-2.jar
Wadl-core.jar
Wadl-cmdline.jar
Wadl2java.jar
This article is from the lava blog, so be sure to keep this source http://lavasoft.blog.51cto.com/62575/229206
Getting Started with RESTful WebService