April 12, 2011

Apache Axis 1.4 - Hello World Example JWS web service

1) Download the following resources:
Apache Axis Jar Files - Click here
WebContent Files - Click here
Resources Files - Click here

2) Unzip the Axis_jars.zip file and copy the Axis jars to the WebContent/WEB-INF/lib folder of the Web Application.
Unzip the web_content_files.zip file and copy the contents to the WebContent folder of the Web Application.
In the src folder create a new package named 'resources'. Unzip the resources_files.zip file and copy the contents to the src folder within the package 'resources'.

3) Add the following configuration to the WebContent/WEB-INF/web.xml file of the Web Application


<listener>
   <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
</listener>



<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>


<servlet>
    <servlet-name>AdminServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
</servlet>


<servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <servlet-class>org.apache.axis.monitor.SOAPMonitorService</servlet-class>
    <init-param>
      <param-name>SOAPMonitorPort</param-name>
      <param-value>5001</param-value>
    </init-param>
    <load-on-startup>100</load-on-startup>
</servlet>



<servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
</servlet-mapping>


<servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
</servlet-mapping>


<servlet-mapping>
    <servlet-name>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>


<mime-mapping>
    <extension>wsdl</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>


<mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
</mime-mapping>

4) Test the Axis setup by typing the following URL in the browser:

http://localhost:8080/WebAppName/happyaxis.jsp

5) To deploy a JWS Web Service, create a file, HelloWorld.jws, in the WebContent folder of the web application with the following code

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


6) Deploy the Web Application and access the following URL in the browser:

http://localhost:8080/WebAppName/HelloWorld.jws

To access the WSDL for the web service, type the following URL in the browser:

http://localhost:8080/WebAppName/HelloWorld.jws?wsdl


Resolution to the Error:




java.lang.RuntimeException: No compiler found in your classpath! (you may need to add 'tools.jar')

Copy the tools.jar file from the JDK/lib folder into the %JBOSS HOME%\server\default\lib folder.

No comments:

Post a Comment