I am new to webservices and i want to implement webservices by using java in my eclipse project.
So can anyone tel me how to implement and creating a project please
Thanks
As defined by W3C web service is a software system to support interoperable machine-to-machine interaction over a network. More elaborately a system consumes service from other software system.
Web services has two major classes:
To implement web service one need to choose one category on the basis of his/her requirement. Java has bunch APIS to implement web services on both category.
Requirements before implementing web service is :
REST based is bit easy to implement compare to other category. So it's better to start with REST complaint web services.
How web service works :
WS works as request-response paradigm , there is an entity which will request for some service to it's specific counterpart namely service provider entity. Upon request, service provider will respond with a response message. So there are two message involved hear one Request message (XML)and one Response message (XML). There are bunch of ways to achieve these. Detail can be found at web service architecture
Beginner can start with JERSEY jsr311 standard reference implementation to build RESTful web services.
Example (jersey specific):
Step One : Creating root resources
// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {
@GET
@Produces("text/plain")
public String getClichedMessage() {
return "Hello World";
}
}
Step Two : Deploying
public class Main {
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(8080).build();
}
public static final URI BASE_URI = getBaseURI();
protected static HttpServer startServer() throws IOException {
System.out.println("Starting ...");
ResourceConfig resourceConfig = new PackagesResourceConfig("com.sun.jersey.samples.helloworld.resources");
return GrizzlyServerFactory.createHttpServer(BASE_URI, resourceConfig);
}
public static void main(String[] args) throws IOException {
HttpServer httpServer = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...",
BASE_URI, BASE_URI));
System.in.read();
httpServer.stop();
}
}
REST REFERENCE - by Roy T . Fielding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With