WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS

First and foremost, we need to install Axis1.1 for Windows, in our system. The January 2004 issue of DeveloperIQ dealt with Apache and the CD also carried a lot of Apache software.

WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS

WEBSERVICE USING APACHE AXIS  TUTORIAL-2   UNDERSTANDING APACHE AXIS  
(part-3) (published in DeveloperIQ..April,2004)(www.developeriq.com) R.S.RAMASWAMY([email protected])

DROP-IN DEPLOYMENT IN AXIS 

First and foremost, we need to install Axis1.1 for Windows, in our system.  The January 2004 issue of DeveloperIQ dealt with Apache and the CD also carried a lot of Apache software.  But ?Axis1.1 for windows? was missing there.  So, we have to download it from the Apache website (http://xml.apache.org).It has been installed as c:\axis11. (The unzipped folder is about 30MB.). 

 Secondly, we need tomcat4.1, for deploying axis.  (It has been given in the March-2003 CD of DeveloperIQ.) It has been installed as d:\tomcat41.

We will find a folder, named ?axis? in ?c:\axis11\webapps? directory.Copy this ?axis? folder to:  ?d:\tomcat41\webapps? directory.

We need ?activation.jar?.  Copy activation.jar to:

d:\tomcat41\webapps\axis\web-inf\lib?

(tomcat4.1\common\lib)

 After completing these preliminary steps, we create ?sqlaxisbean.java? in c:\sam folder, as given. (If we carefully study the code for the ConsoleClient, jsp and this bean, we will find that all of them are similar.) 

//  sqlaxisbean.java

import java.sql.*;

import java.util.*;

import javax.ejb.*;

import javax.naming.*;

import java.rmi.*; 

public class  sqlaxisbean

{ 

String   a;

  public   sqlaxisbean()

  { 

  a=""; 

  } 

  public String callejb(String s)

  {    

     try

    {

    Properties       props=new Properties();

    props.put

    (Context.INITIAL_CONTEXT_FACTORY,

             "weblogic.jndi.WLInitialContextFactory"); 0

    String url="t3://127.0.0.1:7001";

    props.put(Context.PROVIDER_URL,url); 

    Context context=new InitialContext(props); 1

System.out.println("context ok..");

    sqlhome home=(sqlhome)context.lookup("sqlejbJndi");

System.out.println("home ok..");  2

    sqlremote remote=home.create();

System.out.println("remote ok.."); 

    a=remote.showdata(s); 3

    System.out.println(a);

        }catch(Exception e1)

        {System.out.println(" "+e1);}  4

     return a;

  } 

 As we are now studying ?Drop-in Deployment?, we just copy this source file? into: ?d:\tomcat41\webapps\axis? folder as ?sqlaxisClient.jws? Carefully note that we have changed the file extension from *.java to   *.jws. 5

Let us now start tomcat4.1 as follows:

d:\tomcat41\bin>set JAVA_HOME=D:\JDK141

d:\tomcat41\bin> 6

set path=c:\windows\command;d:\jdk141\bin; 

d:\tomcat41\bin>startup

After the tomcat server is fully started (you get the messages as ?jk running?) we can test out Axis installation over tomcat as follows: Start the browser and type the URL as:?http://localhost:8080/axis/index.html?.We get the Axis welcome page: 7

If we type the URL as:?http://localhost:8080/axis/AxisServlet?, we get another page saying:    ?there is a webservice here?.After satisfying ourselves that things are alright, we type the URL as: ?http://localhost:8080/axis/sqlaxisbean.jws?.  We get a link and when we click on this link, we get a wsdl file automatically generated. This is an XML file.  Search this file to checkup whether the name of our method, namely ?callejb? occurs there.  It will be there! So, our ejb axis service is up and running. It is now time to create a simple Console-Client in java to satisfy ourselves that our ejb is really available to be accessed by using the wsdl file.

 So, we now create the Console-Client for the webservice as shown.

//  sqlaxisbeanClient.java 8

import java.net.*;

import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Service; 9

import org.apache.axis.client.Call;

import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;  0

public class sqlaxisbeanClient

{ 

   public static void main(String args[]) 1

   {

     try

     { 2

     System.out.println("Start"); 

     Service   service=        new Service(); 

     System.out.println("Service ready");  3

     Call      call= (Call)service.createCall(); 

     System.out.println("call ready"); 

     URL       url=new  URL("http://localhost:8080/axis/sqlaxisbean.jws"); 4

     call.setTargetEndpointAddress(url); 

     call.setOperationName("callejb");   

     call.addParameter("something", XMLType.XSD_STRING,ParameterMode.IN);  5

     call.setReturnType(XMLType.XSD_STRING); 

     String   r   =  (String)call.invoke(new Object[]{args[0]}); 

     System.out.println(r);   6

     }

    catch(Exception e1){System.out.println(""+e1);}

   } 7

} 

 

We have to set correct classpath for the window to include a number of files required for Axis.As it will be tedious to type it every time, we have created a batch file named ?setcpath.bat?. Please note that it should be typed in a single line continuously as given.            8

//   setcpath.bat

 set  classpath=c:\sam;   d:\bea\weblogic700\lib\weblogic.jar;

c:\axis11\lib\axis.jar; 9

c:\axis11\lib\jaxrpc.jar;

c:\axis11\lib\saaj.jar;

c:\axis11\lib\commons-logging.jar; 0

c:\axis11\lib\commons-discovery.jar;

c:\axis11\lib\wsdl4j.jar;

c:\tomcat4.1\common\lib\activation.jar; 1

c:\tomcat4.1\common\lib\xerces.jar 

After creating this file, we can simply type at the prompt,sam> setcpath. This will create the correct classpath for the working window.  We will now be able to compile jwsclient.java. After compiling, we can execute the program:>java jwsclient ?select * from table1?. We will get names and numbers.  This was tested and found to be ok.Thus, we have developed and ejb, and accessed it as an xml webservice!

 In the next article of this seven-part tutorial, we will take up the wsdd method.  Continued in axis2d.htm  2

visit  http://in.geocities.com/rsramsam

Tutorials

  1. Apache Axis2 - Apache Axis2 Tutorial
  2. Why Web Services?
  3. Java Building a Simple Web Service ? A Tutorial Tutorial
  4. Apache Geronimo Application server Tutorial
  5. Apache Axis2 Tutorial, Develop the Next Generation of Apache Web Services using Apache Axis2
  6. SOA and Web Services
  7. Web Services Examples in NetBeans
  8. SOA and Web Services
  9. J2EE Web Service Development with Attachments Using Axis
  10. J2EE Web Service Development with Attachments Using Axis
  11. WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
  12. Web Services - Web Services Tutorials
  13. Developing Axis Web services with XML Schemas.
  14. What is Service-Oriented Architecture?
  15. WEBSERVICE USING APACHE AXIS -TUTORIAL-2 UNDERSTANDING APACHE AXIS
  16. WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2)
  17. WEBSERVICE USING APACHE AXIS TUTORIAL-1
  18. WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
  19. WEBSERVICE USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE (part-5)
  20. Web Services Tutorials and Links
  21. WEBSERVICE USING APACHE AXIS TUTORIAL-2
  22. WEBSERVICE USING APACHE AXIS- TUTORIAL-2 J2ME CLIENT FOR EJB & EJB-WEBSERVICE
  23. Web Service
  24. Java Client webservice
  25. Ejb Webservice
  26. SOAP with Attachments API for Java
  27. SOAP Header
  28. WSDL program
  29. Application Using JAX-RPC
  30. Security in Web Service
  31. JAX-RPC Advance Concepts
  32. Database driven webservices
  33. Apache Axis2 - Apache Axis2 Tutorial
  34. Apache Axis2 Introduction
  35. Downloading and Installing Apache Axis2
  36. Apache Axis2 Hello World Example
  37. Axis2 client - Axis2 Client example
  38. Axis2 ant wsdl2java - Learn WSDL2java utility of Axis2 with example
  39. Axis2 Eclipse plugin Tutorial
  40. Installing axis2 eclipse plugin