Java – how Web services work

I am new to web services. I want to use java to implement web services in my eclipse project

So anyone can tell me how to implement and create a project

thank you

Solution

As defined by W3C, web service is a software system that supports interoperable machine to machine interaction

There are two broad categories of Web Services:

>Rest compatibility > any network service

To implement a web service, you need to select a category according to his / her requirements Java has a bunch of APIs to implement these two categories of Web services

The requirements before implementing web services are:

>XML > WSDL (Web service description language) > SOAP Protocol, etc

Compared with other categories, rest - based implementation is a little easier to implement Therefore, it is best to start with rest web services

How Web services work:

Ws works as a request - response paradigm, where an entity will request certain services from its specific counterpart (service provider entity) Upon request, the service provider will reply with a response message Therefore, there are two messages involving a request message (XML) and a response message (XML) There are many ways to achieve these goals Details can be found in the web service architecture

Beginners can build restful web services from the Jersey jsr311 standard reference implementation

Example (Sweatshirt specific):

Step 1: create a root resource

// 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 2: deploy

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>