[01] WebService-Based authorization system

Source: Internet
Author: User
Tags wsdl

There are many general-purpose rights management systems based on BS, but the privilege management system invoked through the WebService interface is rare. Plus I have done a period of time before the development, feel that a good set of API interface for the call, with the development of mobile terminals is more important.

The following, is I do a cxf based on the webservice, if there is insufficient, please give correct.


This is the directory structure of this project, the client package holds the WebService program for testing the deployment, the DAO holds the relevant database operations, the model is the encapsulation of an object, the server package holds the code snippet for deploying WebService, The service stores an abstract interface, Serviceimpl is a concrete implementation, util the specific toolkit, such as the C3P0 database connection pool.

Today, I'll say how to deploy the simplest, CXF framework-based WebService without database validation

1. The first is related to the import of the package, specifically, you can go to CXF official website to download

2. Writing an abstract interface in MyService

@WebService public interface MyService {//@WebParam give the parameter a name, which improves code readability. This optional public      

3. Writing specific implementation classes

@WebService public class Myserviceimpl implements MyService {//Test Webservicepublic string Sayhi (string name) {    System.out.println ("SayHello is called by" + name);    Return "Hello" + Name;     }

4. Next is the preparation of the server-side program, start the service side, if you can successfully accesshttp://localhost:9000/MyService?wsdlIndicates that the deployment was successful.

public class Server {/** * Privatization construction method, the benefits are not much to say, is the benefits of encapsulation * In the browser, if you can access http://localhost:9000/MyService?wsdl, the deployment is successful */private Server () {Myserviceimpl ms = new Myserviceimpl ();//Create WebService Service Factory Jaxwsserverfactorybean factory = new Jaxwsserverfactorybean ();//Register WebService Interface Factory.setserviceclass (Myservice.class);//Publish Interface Factory.setaddress (" Http://localhost:9000/MyService "); Factory.setservicebean (ms);//create webservicefactory.create ();}; public static void Main (string[] args) throws Interruptedexception {//Start service-side new Server (); SYSTEM.OUT.PRINTLN ("Server Ready ...");//hibernate for one minute, easy to test//thread.sleep (+),//system.out.println ("Server exit ...") ;//system.exit (0);}}

5. The ability to access the WSDL means that the deployment was successful, and now we are using the client program to invoke webservice to implement the simplest interactive process.

public class Client {private Client () {};p ublic static void Main (string[] args) throws Exception {//Create WebService Client Agent Factory JA Xwsproxyfactorybean factory = new Jaxwsproxyfactorybean ();//Register WebService Interface Factory.setserviceclass (Myservice.class) ;//Set WebService address Factory.setaddress ("Http://localhost:9000/MyService"); MyService service = (MyService) factory.create (); System.out.println ("Simple cxf:" + service.sayhi ("Qzp"));}

The console will output

Simple CXF:HELLOQZP.

Explanation of the relevant concepts:

The above is one of the simplest webservice processes, the following we have a common concept in the WebService to do the relevant explanation and explanation

1. The naming of services (service) shall be governed by the following principles:

(1) The service is named in English;

(2) The first English word of the service is lowercase, the first letter of each English word is capitalized (often said Hump method);

The service name in this project is Myserviceimpl

2. Operation is the service name under all the specific methods, so Sayhi ();

3.WSDL provides a description of the service, which includes the following two parts

(1) Data type definition XML schema file, the type of namespace is "http://ip:port/qxkz/service/schema/", referred to as "St";

(2) The service defines a WSDL file whose service namespace is "http://www." Ip:port/qxkz/service/cswebservice ", referred to as" SNS ".

4. Data protocol

The WebService SOAP protocol is used. The client and server use XML-formatted strings to interact with the business data, the client organizes the business data into an XML-formatted string as an input to the service-side interface, and the server parses the XML-formatted string to get the business data processing business and returns the result to the client in an XML-formatted string.

In this case, the XML part is not involved, but this is explained in detail later.
OK, today first simple introduction WebService and simple use, below, I will do in-depth introduction, as well as the entire Rights management system source code introduction.

[01] WebService-Based authorization system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.