User Manual

public class TemperatureConverterClient {
public static void main(String[] args) throws AxisFault {
ServiceClient client = new ServiceClient();
// create option object
Options opts = new Options();
// setting target EPR
opts
.setTo(new EndpointReference(
"http://<IP address of iTP WebServer>:<Port#>
/<servlet directory>/axis2/services/TemperatureConverter"));
// Setting action ,and which can be found from the wsdl of the service
opts.setAction("urn:c2fConversion");
opts.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
// setting created option into service client
client.setOptions(opts);
OMElement res1 = client.sendReceive(createPayLoad1());
opts.setAction("urn:f2cConversion");
OMElement res2 = client.sendReceive(createPayLoad2());
System.out.println(res1);
System.out.println(res2);
}
public static OMElement createPayLoad1() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.
createOMNamespace("http://ws.apache.org/axis2","axis2");
OMElement method = fac.createOMElement("c2fConversion", omNs);
OMElement element = fac.createOMElement("value", omNs);
element.setText("4");
method.addChild(element);
return method;
}
public static OMElement createPayLoad2() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.
createOMNamespace("http://ws.apache.org/axis2","axis2");
OMElement method = fac.createOMElement("f2cConversion", omNs);
OMElement element = fac.createOMElement("value", omNs);
element.setText("4");
method.addChild(element);
return method;
}
}
NOTE: Starting Axis2/Java version 1.1.1, the REST feature is enabled by default. You can
configure the REST option using the disableREST flag in the <Axis2
Home>\config\axis2.xml . Setting this flag disables REST handling in all the endpoints.
When sending a message, whether the message is RESTful or not, is decided by the value set for
the ENABLE_REST property in the client.
Adding Dependency JAR Files
Add the following Axis2/Java dependency JAR files in the Java Build Path of the AxisClient
project to compile and link the project.
332 Getting Started with Axis2/Java