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
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.
// 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; } |
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: 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 |
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"); 4 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);} } } |
// 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 2