Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
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

(part-4)(published in DeveloperIQ..April,2004) (www.developeriq.com)
R.S.RAMASWAMY (rs.ramaswamy@gmail.com)

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()

  {

  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;

  }

 

c:\sam>javac sqlaxisbean.java

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

Carefully note the following values that we have given:

a. service name        “ejbsqlaxis”

b. provider            “java:RPC”

c. class name          “sqlaxisbean”

d. method name         “callejb”

//c:\sam\sqlaxis.WSDD

<deployment

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

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

<service     name=”ejbsqlaxis”

             provider=”java:RPC” >

     <parameter  name=”className

                 value=”sqlaxisbean  />

     <parameter  name=”methodName

                 value=”callejb”     />

</service>

<deployment> 

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

Axis provides the following provider types

i.   RPC-based provider            java:RPC

ii   Message-based provider        java:MSG

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.

c:\sam>java

org.apache.axis.client.AdminClientsqlaxis.WSDD

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

(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

 –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 .

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.

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

sqlaxisconsoleClient

{

   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

/services/ejbsqlaxis");

// the last parameter is

service name & not class name!

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

   }

}

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

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!

 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.,

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.

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.

Continued in axis3.htm

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

» View all related tutorials
Related Tags: c http web architecture com tutorials service io remote help services distributed request soa vi tutorial using managed int ria

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.