WSO2Con 2013 CFP Banner

How do I avoid exposing all public methods as operations when deploying plain java class in Axis2?

Discuss this article on Stack Overflow
By Deepal Jayasingha
  • 4 Aug, 2006
  • Level: 
  • Reads: 3413

Q: When I deploy a service archive file, the deployment module initializes service implementation class using Java reflection. Next it loads all the public methods of the service implementation class and exposes them as Web services. For example, if I deploy the following service implementation class it will expose three operations namely add, deduct and echo. How Can I avoid exposing all public methods as operations when i deploy a plain java class in Axis2?

Deepal Jayasingha

WSO2 Inc.
package org;

public class MyService {
public int add(int a , int b){
return a + b;
}
public int deduct(int a , int b){
return a - b;
}
public String echo(String str){
return str;
}
}

A: By default, all the above three public methods will be exposed as operations. So if you only want to expose two methods and exclude the third, you can just add a excludeOperations xml element in services.xml. For example, if you do not want to expose 'deduct' method then add following to your services.xml

<service name="MyService">
.........................................
<parameter name="ServiceClass">org.Myservice</parameter>
....................................
<excludeOperations>
<operation>deduct</operation>
</excludeOperations>
</service>

Applies To:

Apache Axis2/Java 1.0
WSO2Con 2014 USA