Home Webservices WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS

Advertisement
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  
(part-3) (published in DeveloperIQ..April,2004)(www.developeriq.com) R.S.RAMASWAMY(rs.ramaswamy@gmail.com)

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");

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

    props.put(Context.PROVIDER_URL,url); 

    Context context=new InitialContext(props);

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

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

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

    sqlremote remote=home.create();

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

    a=remote.showdata(s);

    System.out.println(a);

        }catch(Exception e1)

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

     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.

Let us now start tomcat4.1 as follows:

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

d:\tomcat41\bin>

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:

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

import java.net.*;

import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Service;

import org.apache.axis.client.Call;

import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName; 

public class sqlaxisbeanClient

{ 

   public static void main(String args[])

   {

     try

     {

     System.out.println("Start"); 

     Service   service=        new Service(); 

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

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

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

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

     call.setTargetEndpointAddress(url); 

     call.setOperationName("callejb");   

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

     call.setReturnType(XMLType.XSD_STRING); 

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

     System.out.println(r);  

     }

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

   }

} 

 

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.           

//   setcpath.bat

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

c:\axis11\lib\axis.jar;

c:\axis11\lib\jaxrpc.jar;

c:\axis11\lib\saaj.jar;

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

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

c:\axis11\lib\wsdl4j.jar;

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

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 

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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 26, 2008

Related Tutorials

Ask Questions?    Discuss: WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com