Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@WebMethod rules

 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Those who are preparing for SCDJWS 5.0 Beta can help me out here :

I am trying to put together the rules which are there for @WebMethod

Scenario 1 : No WebMethod in any method


This would create a wsdl which has two operations <operation name="addNumbers"> and <operation name="addNumbers2">

Scenario 2 : WebMethod annotation in only one of the method


This would have only one operation <operation name="addNumbers">

Scenario 3 : One method with @WebMethod(exclude=true)


This would give only one operation <operation name="addNumbers2">

Any more rules for @WebMethod ?
 
Christian Nicoll
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread is a bit old, but still very valuable. I think that there miss just one scenario which put all the four possibilities together:
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Nicoll wrote:This thread is a bit old, but still very valuable. I think that there miss just one scenario which put all the four possibilities together:



Please help me understand this annotation.

My initial understanding was, there is no explicit need to mention @WebMethod, in SEI, if we want to expose all the public methods as webservice methods. There is no need to use @WebMethod, if we are intending to use the default values.

How come the fourth method defined above not exposed as the service. Should the fourth method is logically same as exclude=false.
 
Mikalai Zaikin
Ranch Hand
Posts: 3332
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Nicoll wrote:This thread is a bit old, but still very valuable. I think that there miss just one scenario which put all the four possibilities together:


How about inheritance?

@WebMethod can exist also in superclass...

Which specification describes the behaviour?

Because JAX-WS runtimes behave inconsistently....
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently the JSR-181 specification went through some changes as we can see at WebService / WebMethod rules changed in latest spec -

The JSR-181 specification has a change that defines the rules for when a method should be exposed as a Web method.

--- JSR-181 v0.9.2 (Dec '04)
If the implementation bean does not implement a service endpoint
interface, it must include @WebMethod annotations on each method that is
to be exposed as a Web Service operation. More information on the
@WebMethod annotation may be found in section 5.2.

--- JSR-181 v1.0 (June '05)
If the implementation bean does not implement a service endpoint
interface, all public methods other than those inherited from
java.lang.Object will be exposed as Web Service operations. This
behavior can be overridden by using the WebMethod annotation to specify
explicitly those public methods that are to be exposed. If a WebMethod
annotation is present, only the methods to which it is applied are
exposed.



Regards,
Dan
 
Mikalai Zaikin
Ranch Hand
Posts: 3332
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Drillich wrote:Apparently the JSR-181 specification went through some changes as we can see at WebService / WebMethod rules changed in latest spec -

The JSR-181 specification has a change that defines the rules for when a method should be exposed as a Web method.

--- JSR-181 v0.9.2 (Dec '04)
If the implementation bean does not implement a service endpoint
interface, it must include @WebMethod annotations on each method that is
to be exposed as a Web Service operation. More information on the
@WebMethod annotation may be found in section 5.2.

--- JSR-181 v1.0 (June '05)
If the implementation bean does not implement a service endpoint
interface, all public methods other than those inherited from
java.lang.Object will be exposed as Web Service operations. This
behavior can be overridden by using the WebMethod annotation to specify
explicitly those public methods that are to be exposed. If a WebMethod
annotation is present, only the methods to which it is applied are
exposed.




Regards,
Dan


Well, I'm concerning that highlighted in red not true any more: With JAX-WS 2.2 implementation, all public methods are always exposed (unless attribute 'exclude=false'), even if I put @WebMethod on some public method.

Before, AFAK, there was a behaviour:
a) by default all public methods are exposed
b) if at least one @WebMethod annotation present, then only those methods exposed which have @WebMethod, and other public methods are not exposed.

New rule also violates JSR-250:


In addition to affecting the annotated class, class-level annotations may act as a
shorthand for member-level annotations. If a member carries a specific member-
level annotation, any annotations of the same type implied by a class-level
annotation are ignored. In other words, explicit member-level annotations have
priority over member-level annotations implied by a class-level annotation. For
example, a @WebService annotation on a class implies that all the public
method in the class that it is applied on are annotated with @WebMethod if there
is no @WebMethod annotation on any of the methods. However if there is a
@WebMethod annotation on any method then the @WebService does not imply
the presence of @WebMethod on the other public methods in the class.


Any comments ?

Best regards,
MZ
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I would say that the best practice would be to place the @WebMethod annotation for all methods we would like to expose.

Any thoughts?

Regards,
Dan
 
Tim Uhrmann
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The quote from the JSR-181:


All of the methods on the service endpoint interface are mapped to WSDL operations,
regardless of whether they include a @WebMethod annotation.
A method MAY include a @WebMethod annotation to customize the mapping to WSDL,
but is not REQUIRED to do so.


JSR-181

Paragraph 3.2 Service Endpoint Interface
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic