WSO2Con 2013 CFP Banner

How can I easily deploy and start a service within Apache Axis2, programmatically?

Discuss this article on Stack Overflow
By Eran Chinthaka
  • 16 Jul, 2007
  • Level:  Introductory
  • Reads: 3299

Axis2 comes with a cool feature that enables you to deploy your simple service implementation class.

chinthaka's picture
Eran Chinthaka
Software Engineer
WSO2 Inc.

Step - 1 : Write your service implementation.

 public class StockQuoteService {

public String sayHello(){
return "Hello World";
}

public String getQuote(String quoteName){
// write your business logic here.
return "SomeQuote";
}
}

Step 2 : Compile the service implementation class with debug options on (-g) and use the following code to Deploy it programatically using AxisServer.

  (new AxisServer()).deployService(StockQuoteService.class.getName());

That's it. Your service will be available over port 6060. Try the following URL in the browser : http://localhost:6060/axis2/services/StockQuoteService/sayHello. You will see the following output.

<ns:sayHelloResponse>
<return>Hello World</return>
</ns:sayHelloResponse>

Do you also want to pass parameters to a method when you invoke it using the browser? Try invoking getQuote method using the browser, with the following URL : http://localhost:6060/axis2/services/StockQuoteService/getQuote?quoteName=ABC. Notice the quote name ABC that you have passed inside the browser URL. Check your output in the browser.

  <ns:getQuoteResponse>
<return>SomeQuote</return>
</ns:getQuoteResponse>
 

Applies To

Axis2/Java Latest SVN version as of 18-06-2007 or Axis2 1.3
WSO2Con 2014 USA