Java programming WebService specifies timeout code details

Web service is a remote calling technology across programming languages and operating system platforms

The so-called remote call is a method by which a program on one computer a can call an object on another computer B. for example, the POS card swiping system provided by UnionPay to the mall (interactive questions are used to deepen everyone's understanding of this technology).

What's the use of remote call technology? Is the code of the transfer method called by the POS machine of the shopping mall on the bank server or the POS machine of the shopping mall? Under what circumstances may remote call technology be used? For example, Amazon, weather forecast system, Taobao, Xiaonei, Baidu, etc. expose their own system services in the form of WebService services, so that third-party websites and programs can call these service functions, which expands the market share of their own system. In a big sense, it is the so-called SOA application.

The so-called cross programming language and cross operating platform means that the server program is written in Java, while the client program can be written in other programming languages, and vice versa! Cross operating system platform means that server programs and client programs can run on different operating systems.

In addition to WebService, common remote call technologies include RMI (remote method invoke) and CORBA. Due to the cross platform and cross programming language characteristics of WebService, it is more widely used than the other two technologies, but the performance is slightly lower.

The usual operation steps for calling WebService using JDK to support WebService are as follows:

In step 1 above, while building the service instance, an object of servicedelegate type will be built inside the service, assigned to the attribute delegate, and held internally. Then, in the second step, you will create a proxy object of the service interface by using delegate, and also proxy the bindingprovider and closeable interfaces. Then in the third step, when the interface request is actually initiated, an HTTP request will be initiated internally. When the HTTP request is initiated, the timeout parameters will be obtained from the results returned by getrequestcontext() of bindingprovider, corresponding to com sun. xml. internal. ws. connection. Timeout and com sun. xml. internal. ws. request. Timeout parameter. The former is the timeout for establishing a connection, and the latter is the timeout for obtaining a request response. The unit is milliseconds. If no corresponding timeout time is specified or the specified timeout time is 0, it means never timeout. Therefore, in order to specify the timeout time, we can start from bindingprovider. For example:

A complete example is as follows:

Service interface:

Service interface implementation:

Server code:

In the above server code, you sleep randomly for 5-25 seconds, while the timeout specified by the client is 15 seconds, so during the test, you will see that sometimes the service call will timeout and sometimes respond normally.

summary

The above is all about the detailed explanation of the code for specifying the timeout time of Java programming WebService in this article. I hope it will be helpful to you. If there are deficiencies, please leave a message to point out. Thank you for your support!

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
分享
二维码
< <上一篇
下一篇>>