aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes @WebMethod rules Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "@WebMethod rules" Watch "@WebMethod rules" New topic
Author

@WebMethod rules

Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
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

Joined: Mar 09, 2008
Posts: 106
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:


SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

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.


Regards
KumarRaja

Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
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....


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
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

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
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

Joined: Jul 09, 2001
Posts: 1180
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

Joined: Jun 14, 2013
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @WebMethod rules