aspose file tools*
The moose likes Web Services and the fly likes Regarding 'annotations' in webservice eg. @WebService Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Regarding Watch "Regarding New topic
Author

Regarding 'annotations' in webservice eg. @WebService

Rohit Kumar
Ranch Hand

Joined: Sep 20, 2007
Posts: 53
Hi,

Currently i am working on web services in CXF framework.
And I have seen many web services with annotations.
I am bit confused with the use of annotations in web services.
For what i have read, I feel that these annotations are for the other tools, for examples to generate WSDL file from java class file or to create client stubs etc.

If i have web services and i am writing my client, so do I require these annotations in my web service?

Please correct me if something is not correct.

If possible please provide me any link which will describe it in deatil.

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
The annotations are part of the JAX-WS API, and are used for implementing the service. If you're implementing the client then you needn't be concerned about them (in fact, you needn't even look at the source code of the service).
Rohit Kumar
Ranch Hand

Joined: Sep 20, 2007
Posts: 53
Could you please tell me how exactly annotations are "used for implementing the service" ?

How they distinguishes from a web service without annotations?

Again same Q. Is it ONLY useful for other tools to generate client stubs or wsdl etc?

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
From a client perspective, there is no difference, because to a client it doesn't matter how a WS is implemented.

If you want to learn about JAX-WS, start at its home page: https://jax-ws.dev.java.net/ It points to articles, user guides etc.
Jeffy Gupta
Greenhorn

Joined: Jul 12, 2008
Posts: 5
The webservice "without using Annotations", are implemented using JAX-RPC.
There developer need to develop configuration file, run wscompile for WSDL & mapping, modify web.xml and implement webservices.xml (if not generating thru WSDL2Java). Also develop SEI. Although this all is simple but redundant for a webservice.

With JAX-WS "webervie using Annotations", you just need to give annotations in your implementation bean and deploy. Thats it!. All your deployment descriptors, WSDL etc will get automatically generated.

Please let me know if I answered your question..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
Originally posted by Jeffy Gupta:
The webservice "without using Annotations", are implemented using JAX-RPC.

Not necessarily. There are any number of WS APIs that don't use annotations (e.g. SAAJ).
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
For an interesting example of using annotations to create a RESTful web service, take a look at the Jersey project. (an implementation of JSR-311)

Bill
Rohit Kumar
Ranch Hand

Joined: Sep 20, 2007
Posts: 53
What is exact difference between JAX-RPC and JAX-WS?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
What is exact difference between JAX-RPC and JAX-WS?

See this article for a high-level overview.
Rohit Kumar
Ranch Hand

Joined: Sep 20, 2007
Posts: 53
Annotations doesn't change the meaning of the semantics of the program, but they just tell to the other tools or libraries to process the element in special way.

Could any one tell me what exactly happends at background, when any toll or any framewrok enconters web service's annotations? (@WebService or handler etc)

Even any link to such article woud be helpful.

Thanks in advance.
Rabin Rath
Greenhorn

Joined: Jul 17, 2008
Posts: 4
See the annotations are not the mandatory to follow you can do it through xml configuration also. But annotation will help you as below:
1. no need to write xml files.
2. no need to write xtra coding or java files.
3. reduce code size
4. increase code clarity.
5. decrease development time
etc..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
See the annotations are not the mandatory to follow you can do it through xml configuration also.

I don't think that's true for JAX-WS. Some deployment options may be specified external to the class via XML, but you can't do without the @WebService annotation at the very least.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
Annotations doesn't change the meaning of the semantics of the program, but they just tell to the other tools or libraries to process the element in special way.

I guess we could argue what the "semantics of the program" are, but I'd say that statement is incorrect both generally, and specifically for JAX-WS.

As regards JAX-WS, if a regular POJO is annotated with @WebService, it suddenly gets exposed to whatever machine can get reach the host server (possibly the whole world). That has the potential to alter the characteristics of the code executing in that JVM dramatically.

More generally I could annotate a method with something that causes the method always to add 1 to the result it returns. That is a definite change in semantics. It's not just outside tools/frameworks that have access to annotations - code is free to inspect its own annotations. That goes with the trend to use annotations for domain-specific functionality (as opposed to code-specific functionality, which is what we are talking about here).
[ July 18, 2008: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding 'annotations' in webservice eg. @WebService