Detailed explanation and simple example of Jax WS handler

Detailed explanation and simple example of Jax WS handler

AOP technology is generally used for logging and authentication of function calls of an object.

WebService is a remote function call and requires similar AOP methods. For example, Jax WS WebService and handler are equivalent to AOP.

Take Jax WS handler as an example

Write a web service first

The only special thing about the super fool's WebService is the @ handlerchain annotation, in which handlers XML is an XML file describing the handler chain of Jax WS. This file can be placed in the same directory as the source file.

Take a look at handlers XML content

The handler chain is defined. There is only one handler in the chain, and multiple handlers can also be included

Let's look at the specific implementation of handler:

A handler must implement the soaphandler or logicalhandler interface. For the difference between them, the relationship with the handler interface, and the meaning of xxxcontext in < >, please refer to the spec of jaxws. Here is only an example of HelloWorld.

In fact, I have implemented one of the methods defined by all interfaces. I print the name of the called WebService. In fact, I can do many things here, such as modifying the content in soap, adding or deleting XML tags, adding or deleting soap attachments, and obtaining soap Related words. More vivid functions can include encryption and decryption, logging, etc.

Finally, some related configuration file modifications should be made:

On the web Add to XML:

In fact, when a class is marked with @ WebService, the container will automatically turn it into a WebService, but I have tried to use the above method, that is, use jaxws runtime to match the request with wsservlet, and specify to load a class as WebService in the initial context through wsservletcontextlistener, The listener will automatically detect the file named sun-jaxws.xml under Webroot (the same directory as web.xml), which contains the description of the specific implementation of web service.

Here sun jaxws The contents of XML are:

The specified implementation can be a class with @ WebService or a class that implements the provider interface. Related providers can view the official spec, which is the basis of Jax rs.

Packaging and deployment. I deployed it in GlassFish and found a WebService testing tool. The eclipse Jee package has its own WebService client testing.

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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