WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2)

Creating and testing an EJB in WebLogic Server.Let us begin by creating our working folder as c:\sam.

Ads

Tutorials   
Jersey - Java Framework for RESTful Web services Web Services in Java Tutorial for Beginners Web Services Growth Apache Axis2 Tomcat: Installing Apache Axis2 on Tomcat Introduction to Web services technologies Installing axis2 eclipse plugin Axis2 Eclipse plugin Tutorial Axis2 ant wsdl2java - Learn WSDL2java utility of Axis2 with example Axis2 client - Axis2 Client example Apache Axis2 Hello World Example Downloading and Installing Apache Axis2 Apache Axis2 Introduction Apache Axis2 - Apache Axis2 Tutorial Database driven webservices JAX-RPC Advance Concepts Security in Web Service Application Using JAX-RPC WSDL program SOAP Header SOAP with Attachments API for Java Ejb Webservice Java Client webservice Web Service WEBSERVICE USING APACHE AXIS- TUTORIAL-2 J2ME CLIENT FOR EJB & EJB-WEBSERVICE WEBSERVICE USING APACHE AXIS TUTORIAL-2 Web Services Tutorials and Links WEBSERVICE USING APACHE AXIS - TUTORIAL-2 AXIS FOR EJB-WEBSERVICE (part-5) WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS WEBSERVICE USING APACHE AXIS TUTORIAL-1 WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2) WEBSERVICE USING APACHE AXIS -TUTORIAL-2 UNDERSTANDING APACHE AXIS What is Service-Oriented Architecture? Developing Axis Web services with XML Schemas. Web Services - Web Services Tutorials WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS J2EE Web Service Development with Attachments Using Axis J2EE Web Service Development with Attachments Using Axis SOA and Web Services Web Services Examples in NetBeans SOA and Web Services

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

Creating and testing an EJB in WebLogic Server.Let us begin by creating our working folder as 
c:\sam.

We then edit the three files for EJB in that folder. 

sqlremote.java

sqlhome.java)

sqlbean.java 

// sqlremote.java

import javax.ejb.*;

import java.rmi.*; 

public interface sqlremote extends EJBObject

{

  public String showdata(String s) throws RemoteException;

}

 

//sqlhome.java

import javax.ejb.*;

import java.rmi.*; 

public interface sqlhome extends EJBHome

{

  public sqlremote create() throws RemoteException,CreateException;

}

 

 

// sqlejbbean.java

import java.sql.*;

import javax.ejb.*;

import java.rmi.*;

import javax.naming.*; 

public class sqlejbbean implements SessionBean

{

  public sqlejbbean()

  {} 

  public String showdata(String s)

  {

      String r=" "; 

      try{

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    String url="jdbc:odbc:dbdemo";

    Connection con=DriverManager.getConnection(url);

    Statement st=con.createStatement(); 

    ResultSet rs=st.executeQuery(s);

    while(rs.next())

    {

      r=r+rs.getString(1)+"\n"+rs.getString(2)+"\n"+"-------";

    }

         }catch(Exception e1)

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

       return r;

  } 

  public void ejbCreate()   {} 

  public void ejbRemove()   {} 

  public void ejbActivate()   {} 

  public void ejbPassivate()  {} 

  public void setSessionContext(SessionContext sc)  {} 

} 

Please note that Weblogic7 will work only in Windows 2000. So, we are now working in Windows 2000.

Let us now set HOMEPATH & CLASSPATH.

c:\sam>set JAVA_HOME=d:\jdk1.4.2 

(We have installed jdk1.4.2 in d :\) 

c:\sam>set WL_HOME=d:\bea\weblogic700 

c:\sam>set path=c:\windows\command;d:\ jdk1.4.2\bin;

d:\bea\weblogic700\server\bin;

c:\sam>set classpath=c:\sam;

d:\bea\weblogic700\server\lib\weblogic.jar;

We now compile files in c:\sam folder. 

c:\sam>javac    *.java

Create a subfolder named META-INF as follows:

( it should be capital letters!) 

c:\sam>md META-INF

c:\sam>cd META-INF 

c:\sam\META-INF> 

 In META-INF folder, create the following two Deployment-Descriptor files (XML files).  These files are MOST IMPORTANT.  XML files are case-sensitive.   

//   ejb-jar.xml

<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC

"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"

"http://java.sun.com/dtd/ejb-jar_1_1.dtd"> 

<ejb-jar>

    <enterprise-beans>

       <session>

          <ejb-name>sqlejbbean</ejb-name>

          <home>sqlhome</home>

          <remote>sqlremote</remote>

          <ejb-class>sqlejbbean</ejb-class>

          <session-type>Stateless</session-type>

          <transaction-type>Container</transaction-type>

       </session>

    </enterprise-beans>

</ejb-jar>

 

 

//weblogic-ejb-jar.xml

<?xml version="1.0"?>

<!DOCTYPE weblogic-ejb-jar PUBLIC

"-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN"

"http://www.bea.com.servers/wls700/dtd/weblogic-ejb-jar.dtd"> 

<weblogic-ejb-jar>

  <weblogic-enterprise-bean>

     <ejb-name>sqlejbbean</ejb-name>

     <jndi-name>sqlejbJndi</jndi-name>

  </weblogic-enterprise-bean>

</weblogic-ejb-jar>

 

 Now, revert back to c:\sam folder. 

Create the jar file as follows: 

sam>jar  cf   sql.jar      *.class          META-INF\*.xml

This command will create sql.jar. 

The next step is to create sql1.jar for deployment in weblogic server.

sam>java   weblogic.ejbc  sql.jar   sql1.jar 

This will create sql1.jar.  We may get some warning messages, which can be ignored.  Finally, we get the message ?ejbc successful?. 

Now copy sql1.jar to the following folder:

d:\bea\user_projects\mydomain\Applications Start weblogic server by the following procedure:

Startmenu->programs->

bea weblogic platform->user projects->mydomain->startserver 

Give     username:  system

password:  administrator    

Wait till you get the message: ?started for Running mode?.  Minimize this window.  That completes the job of deployment in ejb server.  We should now create a console-mode client for the ejbean 

// sqlConsoleClient.java

import java.ejb.*;

import java.rmi.*;

import javax.rmi.*;

import javax.naming.*;

import java.io.*;

import java.util.*; 

public class sqlConsoleClient

{

   public static void main(String args[])

   {

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

  }

  catch(Exception e1)

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

  }

} 

 

 Now compile the client file:

C:\sam>javac sqlConsoleClient.java

Let us now run the client program:

>java  sqlConsoleClient     ?select * from table1?

We will get a few names and numbers.We now proceed to create the jsp file .

// sqljspclient.jsp

<html>

<body>

<%@  page  import=?javax.ejb.*?       %>

<%@  page  import=?java.rmi.*?        %>

<%@  page  import=?javax.rmi.*?       %>

<%@  page  import=?javax.naming.*?    %>

<%@  page  import=?java.util.*?       %>

<%@  page  import=?java.io.*?         %> 

<%

String  sql=  request.getParameter(?text1?);

Out.println(?please wait?);

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

    out.println(a);

  %> 

</body>

</html>

 

 Create the corresponding html file to invoke the above jsp.

// sqljspclient.htm

<html>

<body>

<form   method=post 

        action=?sqljspclient.jsp? />

sql

<input   type=text   name=?text1?  size=60>

<input   type=submit>

 

</form>

</body>

</html>

We have installed tomcat3.2 in e: drive.  Copy sqljspclient.jsp  &  sqljspclient.htm to e:\tomcat\webapps\root.

 To start the tomcat server, cd to 

 e:\tomcat\bin>set JAVA_HOME=D:\JDK1.4.2

>SET CLASSPATH=%CLASSPATH%;c:\sam;

 d:\bea\weblogic700\server\lib\weblogic.jar

>startup

This will start the webserver. Start the browser and type the URL as:?http://localhost:8080/sqljspclient.htm?.  We get a form.  Type the sql and submit.  We get the correct result (tested and found ok).  Thus, we have created a stateless session EJB, tested it in console mode and also as a jsp deployed in tomcat3.2.  We now proceed to expose our ejb as an XML-WebService, using AXIS by two methods:

  1. as *.jws (known as Drop-in Deployment).( part-3)
  2. by using wsdd file etc.(part-4)

 The next article discusses these aspects in detail. 

Continued in axis2c.htm Visit  http://in.geocities.com/rsramsam

Advertisements

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2)

Posted on: March 13, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: WEBSERVICE USING APACHE AXIS TUTORIAL-2 UNDERSTANDING APACHE AXIS (part-2)   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads