WebService (Pers)

Source: Internet
Author: User
Tags nginx reverse proxy

1. Java Remote Method invocation

Java remote method Invocation, Java invocation, is an application programming interface for implementing remote procedure calls in the Java programming language.

1.1 Remote invocation Scenario Comparison

1. Java RMI (Remote Method invocation)

2. EJB Remote Interface Call

3, WebService, such as Jax-ws axis Xfire CFX

4, Hessian and spring Httpinvoker

5. Direct dynamic request to return JSON data

6, etc...

This paper makes a simple comparative analysis from the aspects of configuration complexity, coding difficulty, execution efficiency, cross-language, compatibility, security, protocol type, binding specific framework and so on.

Javarmi is the JDK embedded in the bottom of the solution, it applies the most lightweight, and the simplest, it does not need any Web server, directly in the code to bind the IP address and the corresponding port, if it is very simple small micro-application more suitable, because the bottom of its efficiency should be good, The next few calls are made based on this extension. Its shortcomings are also obvious, if the business is very many and complex, the interface calls very frequently need to be distributed across multiple servers, then its coding is not elegant, it is difficult to achieve distributed, and all the things are concentrated in the code, readability and maintainability are not ideal, not with cross-language calls.

The EJB remote interface invocation, whose most essential underlying is still javarmi, invokes the service through Jndi. However, the advantage of EJB remote interface invocation is that it can be very easy to implement distributed, some versions of the client-side encoding is more complex, but most of the code can be automatically completed with the help of the IDE, EJB3.0 later version encoding and configuration is simpler. The disadvantage is that EJB is a heavyweight framework that requires the support of the EJB container, many Web servers do not have this function, such as resin, tomcat, etc., if the business code is not using EJBS, remote invocation naturally does not apply. At present, EJB in Internet development is very rare, it may be the rise of spring and the very famous book "Expert One-on-one development without EJB", the Chinese version.

WebService is a common method of remote invocation, and its greatest advantage is the cross-platform language, which can be easily invoked whether the client is Java or. Net. It uses the soap (simple Object Access Protocol) protocol to encapsulate serialized messages, essentially forming an XML file that can be transmitted over HTTP over the network. The WebService client call is actually a way to use the makefile, as long as you know the URL of the publishing interface, without the need to pass in the jar or class file. Common WebService implementations are jax-ws2.0, axis, Xfire, and CFX, The jax-ws2.0 is packaged in the JDK and has some flexibility, but this kind of embedding the framework into the JVM actually greatly reduces its controllability; axis has 1.0 and 2.0 two versions, this is not too familiar; Xfire and CFX are actually a source, Xfire stopped developing in 07, and another framework merged becomes CFX and is a more popular webservice implementation.

Hessian is another very common remote invocation scenario, which is based on the BINARY-RPC protocol, which encapsulates the request and response data in a standard binary format, so it also has the ability to transmit data across language platforms, and it has its own efficient serialization and deserialization mechanism. However, Hessian in version control often appear incompatible with each other, the server side and the client is usually to maintain a consistent version, otherwise there will be inexplicable problems, there are common errors, such as the use of Nginx reverse proxy returned 411 error and so on. Spring provides good support for Hessian, usually in conjunction with it, and Spring has its own remote calling method, Httpinvoker. If you have used Hessian and httpinvoker, you will find that the two configurations are almost identical, including the interface name, class name, field name, calling and publishing code ... And can not be used at the same time, will conflict with each other. They are all request processing through the servlet, which requires servlet container support and is very efficient.

A direct dynamic request to return JSON data is an intuitive way to strictly not be a call to a remote method. In this way, the encapsulated JSON data is returned directly from the container through a servlet request, the data structure is not flexible enough, and the security is insufficient. However, the implementation is simple, and the business code is written by the passing, almost do not need the concept of the client, as long as the request data is simple enough, security can be used.

1.2 Remote Call Technology examples

Dubbo, RMI, Webservice, Hessian, Netty and so on.

1.3 Fundamentals

At the bottom level, it is the transfer of a stream from one computer to another, based on the Transport Protocol (HTTP, TCP, UDP, and so on) and network io (bio, NIO, AIO).

1.4 Key Technology points

1. Communication protocol: Transport Layer: Socket (TCP,UDP) Application layer: HTTP

2. Application-level protocol (Dubbo, Jrmp,soap, Xml-rpc (xml+http), BINARY-RPC (binary +http))

2.1. Provide a more easy-to-use standard transmission format to avoid direct stream operation.

2.2. Implementing network communication mechanisms

Convert the transfer format to a stream

Transfer to a remote computer via some kind of transport protocol

The remote computer will flow to the transfer format

3. Network IO

Bio (blocking),

NIO (non-blocking),

AIO (asynchronous, jdk7 new feature).

4. multithread, enable one thread per request on the server

5. Transparent scheme for local invocation and remote invocation

Java ClassLoader, Dynamic Proxy

6. Network communication processing mechanism

Automatic re-connect, broadcast, exception, pool processing, and more

7. Serialization

Serialization mechanisms for various protocols

2. What is WebService?

Web service is Web services, which is a cross-platform remote invocation technology that is a remote invocation technology across programming languages and cross-operating system platforms.

Using SAOP (Simple Object Access Protocol) protocol transmission, SAOP belongs to the standard. The SAOP protocol is an HTTP-based application-layer protocol, and the SAOP protocol transfer is XML data. SAOP is an application-layer protocol that is based on HTTP two-times encapsulation (and a set of protocols defined on the HTTP basis). Simple comprehension: saop= (Http+xml)

Using WSDL as the description language is the WebService instruction manual, WSDL belongs to the standard.

XML is the foundation of WebService's cross-platform, the main advantage of XML is that it is not only platform-independent, but also vendor-independent.

XSD,W3C developed a set of transport data types for webservice, which is described using XML, XSD (XML Schema datatypes). The WebService interface written in any programming language is converted to the WebService standard XSD send when data is sent.

The webservice of the current non-SAOP protocol is the primary goal of lightweight, such as HTTP rest mode is also a way of webservice, or directly using HTTP custom data protocol, such as HTTP transmission JSON data, HTTP transport XML data and so on.

3. Three elements of WebService  3.1 SAOP (Communication protocol)

SAOP is Simple object accessprotocol, which is simply the access Protocol for objects.

SAOP is the WebService transmission protocol, Saop=http+xml.

Because SAOP is based on XML and HTTP, it implements message descriptions through XML and then transmits messages over HTTP.

SAOP currently has two versions of SAOP1.1. and SAOP1.2.

The SAOP protocol is not a proprietary protocol to WebService.

For example, the SMTP, tr069 protocol defines a new protocol on the basis of the SAOP protocol, and so on.

3.2 WSDL (operating instructions)

WSDL is the Web Services Description language, which is the Web Service Description language.

is an XML-based language that describes Web services and how to access Web services.

XML-based descriptions of Web service and its functions, parameters, and return values. The popular understanding of WSDL is the instruction manual of WebService.

How to use:

After the server has published a WebService interface, the interface content is queried through the WSDL specification (XML format).

WSDL describes the three basic properties of a Web service:

(1) Operation provided by the service

(2) How to access the service

(3) Where the service is located (ok by URL)

3.3 UDDI (directory)

UDDI is Universal description,discovery and integration, which is generic description, discovery, and integration.

UDDI is a directory service that enables enterprises to register and search for WEB services through UDDI.

In simple words, UDDI is a directory, but in this directory there are some information about WEB services.

and UDDI communicates through soap, built in. Net.

4. WebService development specifications in Java?

4  

4.1 Jax-WS (Master)

JAX-WS is all called the Java API for xml-based WebServices, and the WebService is developed by the Java API for object-oriented development.

JAX-WS uses the SAOP protocol.

4.2 Jaxm&saaj

JAXM (JAVA API for XML message) primarily defines the APIs required to send and receive messages, SAOP protocol details by JAXM more operations.

The Jaxm&saaj transmits the attachment when communicating with the webservice.

4.3 Jax-rs (Master)

Jax-rs is a set of Java Web Service specifications for the rest (representation state Transfer) style, which was not released with JDK1.6 because of the late launch of the specification (JSR 311, currently Jax-rs version 1.0).

Jax-rs can be developed directly on an HTTP basis.

The interface is lighter in weight.

Use CXF to implement rest mode.

Transport Layer TCP protocol

TCP: Connection-oriented protocol, this protocol is stable, the client after three handshake can and the server to establish a channel to communicate in this channel.

UDP: Datagram protocol, unstable, the client can only send data to the service, the server may not receive.

Summarize:

The underlying protocols used for interface development include TCP and UDP.

5. Using JAXWS to call the public network weather query 4.1 server

The public network has provided weather enquiry services.

4.2 Client

Generate the calling code using Wsimport.

1, find the public Network Weather query WSDL specification.

2. Generate code.

3, the client code.

PackageCn.com.client;

Importcn.com.webxml.ArrayOfString;
ImportCn.com.webxml.WeatherWebService;
ImportCn.com.webxml.WeatherWebServiceSAOP;

ImportJava.util.List;

/**
* Created by Yadongliang on 2017/7/18.
*/
Public classQueryweather {
Public static voidMain (string[] args) {
// Create a service view
Weatherwebservice WebService =NewWeatherwebservice ();

// Create a porttype from a service view
WEATHERWEBSERVICESAOP WEBSERVICESAOP = WEBSERVICE.GETWEATHERWEBSERVICESAOP ();

// calling methods via PortType
Arrayofstring arrayofstring = Webservicesaop.getweatherbycityname ("Tianjin City ");
list<string> resultlist = arrayofstring.getstring ();

for(String Result:
Resultlist) {
System. out. println (Result);
}
}
}

6. Socket advantages and disadvantages?

Advantages:

The socket is a transport layer that encapsulates an interface specification based on TCP/IP.

Can be cross-platform (client operating system, and programming language and service side not the same).

Transmission speed is very fast, to transfer some big data can be used socket.

Disadvantages:

The socket needs to be manually parsed by the stream at development time, followed by a custom protocol.

Custom protocol: Client and server communication content is required in the code to manually special parsing, such as: client and server to send XML data, XML data content is customized, client and server programming needs in the code to the XML data parsing special processing.

7. WebService Advantages and disadvantages?

Advantages:

Use XML to support cross-platform remote invocation.

HTTP-based SAOP protocol that can span firewalls.

Using the WebService service program based on the SAOP protocol can be deployed in Tocmat with 80 external services.

Supports object-oriented development.

facilitates software and data reuse and enables loose coupling.

Disadvantages:

The SAOP protocol is based on XML transmission, and the transmission efficiency is not high.

Java

WebService

The data sent is serialized

C++

WebService

Received data to be deserialized by SAOP protocol

SAOP to support object-oriented development, both ends have a serialization process.

Suggestions:

If the interface speed requirements are not high, for protocol standards, it is recommended to use SAOP.

8. What is the difference between WebService and sockets? 7.1 Relationship

The underlying is based on the TCP/IP protocol, using sockets for communication.

The upper Jaxws uses the SAOP protocol, SAOP transmits XML data based on HTTP.

JAXWS communication is realized by socket programming method.

Conclusion:

WebService is a cross-platform object-oriented remote call technology, which uses SAOP protocol to communicate, the bottom based on socket communication, and the WebService does not need to be processed specifically for data stream sending and receiving.

7.2 Differences

The Network Seven layer protocol is: physical layer, Data link layer, network layer, transport layer, Session layer, presentation layer, application layer.

The socket is just a class defined by Java in the network layer to implement the network layer. The above layers need our own implementation in the program. For example, the port can define itself, the definition of the packet, the encryption and decryption of the packet, etc.

And WebService Java implements the application layer of the tool, he based on the service is the HTTP protocol, through the server can be published. So the definition of the internal port, the definition of the packet, and the encryption and decryption of the packet are all done, so we can use it directly.

The WebService internal data format is XML format and is not affected by firewalls because of HTTP-based protocols. Because his communication agreement is the same as the one we browse the Web.

9. Webservice Technology Selection 9.1 Protocol Agreement

What protocol is used by the server and what protocol is used by the client.

9.2 Versatility (openness)

For a webservice mainly considering the commonality of the interface, the SAOP protocol can be used without the requirement of performance.

If there is a performance requirement, versatility is also required: which interface technology is high-performance and also common, preferably HTTP-recommended.

9.3 High Performance

Several technical performance from high to Low are:

Socket>rmi (both client and server are Java) >HESSIAN>HTTP>SAOP

9.4 Enterprise Development Code

If the enterprise defines the development specification, which includes the interface specification, has determined the interface using the technology and what protocol to use.

For example: Some companies are unified to determine the use of Http+json way.

WebService Technology Implementation Method

Blog: Several webservice technology implementations commonly used in Java development

http://blog.csdn.net/zolalad/article/details/25158995

Blog: Several popular WebService frame performance comparison (reprint, splicing)

http://blog.csdn.net/chenleixing/article/details/44958549

There are three main ways to implement Web services:

REST (new): Representational state transitions (software architecture style) Resteasy, Wink, CXF, Axis2 ...

SOAP (relatively mature): Simple Object Access Protocol Xfire, Axis2, CXF, Axis1

XML-RPC (OBSOLETE): Remote Procedure Call protocol (slowly replaced by soap)

How to choose?

Apache CXF is the second-generation product of Codehausxfire, currently the best performance in different frameworks, should be a good choice for developers, which is not related to its own architectural design. Compared to other frameworks, CXF has several outstanding features: Support for Jax-WS, Spring integration, AEGI data binding, support Restfulservices, support for WS-*, Apache protocol, and code simplicity.

Apache Axis2 is the second-generation product of Apache Axis1, and is also very well architected, with key features: support for multiple languages (c/s + +), support for various specifications, pluggable modular design, and support for hot deployment. Performance is also excellent compared to CXF.

Resteasy may also be a good frame! (personal view)

WebService (Pers)

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.