WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS

In this part, we will follow the WSDD method. We have already created sqlaxisbean.java as explained in the last article. We used it as sqlaxisbean.jws (drop-in method).

WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS

WEBSERVICE USING APACHE AXIS TUTORIAL-2
UNDERSTANDING APACHE AXIS

(part-4)(published in DeveloperIQ..April,2004) (www.developeriq.com)
R.S.RAMASWAMY ([email protected])

APACHE AXIS-DEPLOYMENT USING WSDD FILE

In this part, we will follow the WSDD method.  We have already created sqlaxisbean.java as explained in the last article.  We used it as sqlaxisbean.jws (drop-in method).  There was no necessity to compile this file.But in WSDD method (web-service deployment descriptor), we should compile this file.Next, we create the WSDD file.  Then, we deploy this bean to tomcat.  We may have to restart the tomcat4.1 webserver.

We can then create a java-console client and test the webservice.  So, this is the step-by-step procedure.  We will now go into the details involved here.We are now in c:\sam.

We  give correct path, classpath etc. as in   part-3.

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

style='border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt; mso-yfti-tbllook:480;mso-padding-alt:0in 5.4pt 0in 5.4pt;mso-border-insideh: .5pt solid windowtext;mso-border-insidev:.5pt solid windowtext'>

//   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     

//  sqlaxisbean.java

import java.sql.*;

import java.util.*;

import javax.ejb.*;

import javax.naming.*;

import java.rmi.*;

public class  sqlaxisbean

{

String   a;

  public   sqlaxisbean() 0

  {

  a="";

  } 1

  public String callejb(String s)

  {  

     try 2

    {

    Properties       props=new Properties();

    props.put 3

    (Context.INITIAL_CONTEXT_FACTORY,

  "weblogic.jndi.WLInitialContextFactory");

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

    props.put(Context.PROVIDER_URL,url); 

    Context context=new InitialContext(props);

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

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

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

    sqlremote remote=home.create(); 6

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

    a=remote.showdata(s);

    System.out.println(a); 7

        }catch(Exception e1)

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

     return a; 8

  }

 

c:\sam>javac sqlaxisbean.java 9

so we get sqlaxisbean.class

Copy this file to ?d:\tomcat4.1\axis\web-inf\classes? folder.  (Note the difference from part-3 carefully.

In part-3, we just copied the file ?sqlaxisbean.java? to d:\tomcat4.1\webapps\axis folder.  But, now we copy the class fil  e to ?d:\tomcat4.1\axis\web-inf\classes? folder. We should now restart the tomcat server. Next, we create the WSDD file in c:\sam folder 0

Carefully note the following values that we have given:

a. service name        ?ejbsqlaxis?

b. provider            ?java:RPC? 1

c. class name          ?sqlaxisbean?

d. method name         ?callejb?

//c:\sam\sqlaxis.WSDD 2

<deployment

xmlns=?http://xml.apache.org/axis/WSDD/?

xmlns:java=?xml.apache.org/axis/WSDD/providers/java? > 3

<service     name=?ejbsqlaxis?

             provider=?java:RPC? >

     <parameter  name=?className? 4

                 value=?sqlaxisbean?  />

     <parameter  name=?methodName?

                 value=?callejb?     /> 5

</service>

<deployment> 

In Axis, a provider (also known as a pivot handler) is used for invoking the webservice class. 6

Axis provides the following provider types

i.   RPC-based provider            java:RPC

ii   Message-based provider        java:MSG 7

iii EJB provider                   java:EJB

(Currently, work is going on for developing COM provider.) 

In the present demo, we are using RPC based provider.The next step is to deploy the bean in tomcat server.  Please refer to page 38 of Axis by Romin Irani & Geelani Basha.  WROX Press for further details. 8

c:\sam>java

org.apache.axis.client.AdminClientsqlaxis.WSDD

 lhttp://localhost:8080/axis/services/AdminService 9

(Note: This is ?l? as in long and not ?one?.)

(Remember that tomcat should be running.  If tomcat server is not running, this command won?t work.)Wait till the message ?Done Processing? is displayed. It is essential to verify whether the bean has really been deployed correctly by the following command:

c:\sam>java org.apache.axis.client.AdminService  list 0

 ?lhttp://localhost:8080/axis/services/AdminService

We will get the WSDD files of all the beans deployed.  (If there are too many items, we can send the result to log.txt by the command :> (as before)> log.txt .We can then see log.txt and locate the ejbsqlaxis service, its classname and method name.Actually, our job is over.  We can, now checkup, whether the bean is available as a webservice typing the URL in browser as: ?http://localhost:8080/axis/services/Ejbsqlaxis?wsdl? (ejbsqlaxis is the name given by us as the name of service in the WSDD file.)  We will get the wsdl file (an xml file).Search for the occurrence of the port-type name as ?sqlaxisbean? and operation name as ?callejb?.If these are found, it means that everything is fine.

Now we want to check up whether we can really use this service.  For this, we create the following java console-mode program . 1

style='background:maroon;border-collapse:collapse;border:none;mso-border-alt: solid windowtext .5pt;mso-yfti-tbllook:480;mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-border-insideh:.5pt solid windowtext;mso-border-insidev:.5pt solid windowtext'>

// sqlaxisconsoleclient.java

import java.net.*;

import javax.xml.rpc. 2

ParameterMode;

import org.apache.axis.client.

Service; 3

import org.apache.axis.

client.Call;

import org.apache.axis. 4

encoding.XMLType;

import javax.xml.

namespace.QName; 5

public class

sqlaxisconsoleClient

{ 6

   public static

void main(String args[])

   { 7

     try

     {

     System.out.println 8

("Start");

     Service    service=   new Service();

     System.out.println 9

("Service ready");

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

     System.out.println 0

("call ready");

     URL        url=new URL("http://localhost:

8080/axis 1

/services/ejbsqlaxis");

// the last parameter is

service name & not class name! 2

     call.setTargetEndpointAddress(url);

     call.setOperationName("callejb?);

     call.addParameter 3

("something", XMLType.XSD_STRING,

ParameterMode.IN);

     call.setReturnType 4

(XMLType.XSD_STRING);

     String   r=

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

  System.out.println(r);                  

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

   } 6

}

If you carefully compare this file with the earlier jwsclient.java,  you will find that except for the URL of the end-point, everything else is the same.We now compile this file.

c:\sam>javac sqlaxisconsoleclient.java 7

This compiles correctly.We can run this program:

c:\sam>java sqlaxisconsoleclient  ?select * from table1 where name like ?d%? ?

We get the correct result. Now just a little explanation for the code! 8

 1.  We begin by defining the endpoint URL, which specifies the actual location of WEBSERVICE.

2.  We specify the method name, then we create an instance of service and create CALL object for a service.  We set URL and method name for this CALL object.

3.  ?addParameter? method takes three parameters, viz., 9

a.  A user-defined name for the parameter (?sql? in our example).

b.  Parameter datatype.

c.  Whether the parameter is input parameter or output parameter. 0

4.  It is now required to set the return type.

5.  Finally, we invoke the call

That completes the fourth part of this tutorial.  In the next month?s issue, we will directly use the EJB class files in WSDD file and invoke the EJB as webservice without using sqlaxisbean. 1

Continued in axis3.htm

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