Lably
Skip to content

Apache Axis

  • 3 min read
  • 2 chapters

Related on Lably

Through Open-source software, Web service and Java (programming language)

Axis for Java

When using the Java version of Axis, there are two ways to expose Java code as Web service. The easiest one is to use Axis native JWS (Java Web Service) files. Another way is to use custom deployment. Custom deployment enables you to customize resources that should be exposed as Web services.

See also Apache Axis2.

JWS Web service creation

JWS files contain Java class source code that should be exposed as Web service. The main difference between an ordinary java file and jws file is the file extension. Another difference is that jws files are deployed as source code and not compiled class files.

The following example will expose methods add and subtract of class Calculator.

<span id="mwJg"></span><span class="w" id="mwJw"> </span><span class="kd" id="mwKA">public</span><span class="w" id="mwKQ"> </span><span class="kd" id="mwKg">class</span> <span class="nc" id="mwKw">Calculator</span><span class="w" id="mwLA"> </span> <span class="w" id="mwLQ"> </span><span class="p" id="mwLg">{</span> <span class="w" id="mwLw"> </span><span class="kd" id="mwMA">public</span><span class="w" id="mwMQ"> </span><span class="kt" id="mwMg">int</span><span class="w" id="mwMw"> </span><span class="nf" id="mwNA">add</span><span class="p" id="mwNQ">(</span><span class="kt" id="mwNg">int</span><span class="w" id="mwNw"> </span><span class="n" id="mwOA">i1</span><span class="p" id="mwOQ">,</span><span class="w" id="mwOg"> </span><span class="kt" id="mwOw">int</span><span class="w" id="mwPA"> </span><span class="n" id="mwPQ">i2</span><span class="p" id="mwPg">)</span><span class="w" id="mwPw"> </span> <span class="w" id="mwQA"> </span><span class="p" id="mwQQ">{</span> <span class="w" id="mwQg"> </span><span class="k" id="mwQw">return</span><span class="w" id="mwRA"> </span><span class="n" id="mwRQ">i1</span><span class="w" id="mwRg"> </span><span class="o" id="mwRw">+</span><span class="w" id="mwSA"> </span><span class="n" id="mwSQ">i2</span><span class="p" id="mwSg">;</span><span class="w" id="mwSw"> </span> <span class="w" id="mwTA"> </span><span class="p" id="mwTQ">}</span> <span class="w" id="mwTg"> </span> <span class="w" id="mwTw"> </span><span class="kd" id="mwUA">public</span><span class="w" id="mwUQ"> </span><span class="kt" id="mwUg">int</span><span class="w" id="mwUw"> </span><span class="nf" id="mwVA">subtract</span><span class="p" id="mwVQ">(</span><span class="kt" id="mwVg">int</span><span class="w" id="mwVw"> </span><span class="n" id="mwWA">i1</span><span class="p" id="mwWQ">,</span><span class="w" id="mwWg"> </span><span class="kt" id="mwWw">int</span><span class="w" id="mwXA"> </span><span class="n" id="mwXQ">i2</span><span class="p" id="mwXg">)</span><span class="w" id="mwXw"> </span> <span class="w" id="mwYA"> </span><span class="p" id="mwYQ">{</span> <span class="w" id="mwYg"> </span><span class="k" id="mwYw">return</span><span class="w" id="mwZA"> </span><span class="n" id="mwZQ">i1</span><span class="w" id="mwZg"> </span><span class="o" id="mwZw">-</span><span class="w" id="mwaA"> </span><span class="n" id="mwaQ">i2</span><span class="p" id="mwag">;</span> <span class="w" id="mwaw"> </span><span class="p" id="mwbA">}</span> <span class="w" id="mwbQ"> </span><span class="p" id="mwbg">}</span>

JWS Web service deployment

Once the Axis servlet is deployed, you need only to copy the jws file to the Axis directory on the server. This will work if you are using an Apache Tomcat container. In the case that you are using another web container, custom WAR archive creation will be required.

JWS Web service access

JWS Web service is accessible using the URL http://localhost:8080/axis/Calculator.jws. If you are running a custom configuration of Apache Tomcat or a different container, the URL might be different.

Custom deployed Web service

Custom Web service deployment requires a specific deployment descriptor called WSDD (Web Service Deployment Descriptor) syntax. It can be used to specify resources that should be exposed as Web services. Current version (1.3) supports

  • RPC services
  • EJB - stateless (Enterprise Java Bean)

Automated generation of WSDL

When a Web service is exposed using Axis, it will generate a WSDL file automatically when accessing the Web service URL with ?WSDL appended to it.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and information technology