Professional Documents
Culture Documents
Whether it is a DIME attachment or MIME attachment the way we get the data from the
attachment is similar. But it is very important to make an input data validation at every point.
The very first step in the getDimeData() or getMimeData() is to check whether the attachment
we received is of correct type or not. If the attachment is not of the expected type we can throw
an InputValidationException. Listing 2 shows the code to handle the DIME attachment.
MessageContext msgContext =
MessageContext.getCurrentContext();
Message rspmsg =
msgContext.getResponseMessage();
log.info("org.apache.axis.attachments.At
tachments.SEND_TYPE_DIME : "
+
org.apache.axis.attachments.Attachments.
SEND_TYPE_DIME);
int inputAttachmentType =
rspmsg.getAttachmentsImpl().getSendType(
);
log.info("inputAttachmentType : " +
inputAttachmentType);
if (inputAttachmentType !=
Attachments.SEND_TYPE_DIME){
String failMsg = "Attachment
passed is not a DIME attachment, please
check.";
throw new
InputValidationException("Invalid input
data error : " + failMsg);
}
MessageContext msgContext =
MessageContext.getCurrentContext();
Message rspmsg =
msgContext.getResponseMessage();
log.info("org.apache.axis.attachments.At
tachments.SEND_TYPE_MIME : "
+
org.apache.axis.attachments.Attachments.
SEND_TYPE_MIME);
int inputAttachmentType =
rspmsg.getAttachmentsImpl().getSendType(
);
log.info("inputAttachmentType : " +
inputAttachmentType);
if(inputAttachmentType !=
Attachments.SEND_TYPE_MIME){
String failMsg = "Attachment
passed is not a MIME attachment, please
check.";
throw new
InputValidationException("Invalid input
data error : " + failMsg);
}
After checking for the correct type of attachment, we need to some how get the contents in the
attachment. We need to get the byte array in the attachment. Although attachment can be used to
send images and various other types of content, in our current problem we are just dealing with
an XML string. Listing 4 shows the code to get an array of bytes from the DataHandler object.
The procedure to get the byte array is similar what ever may be the attachment.
Listing 4. Getting the byte array from any attachment
Once we have the byte array it is easy to get the actual content if we know the type of content.
Since it is a String in the current scenario, we can use UTF-8 charset to convert it to the original
String. Listing 5 shows the code to get the input String passed by the client from the attachment.
Listing 5. Getting the client's input String from attachment
private String
getInputString(DataHandler dh) throws
InputValidationException {
String failMsg = null;
if (dh == null ) {
failMsg = "Attachment is
null -- missing attachment.";
throw new
InputValidationException("Invalid data
error : " + failMsg);
} else {
byte[] responseBytes =
null;
try {
responseBytes =
Utils.getBytesFromDataHandler(dh);
log.info("responseBytes length :
" + responseBytes.length);
} catch(IOException e) {
failMsg = "Error
occured while parsing the input XML,
please check the input.";
throw new
InputValidationException("Invalid input
data error : " + failMsg);
}
if(responseBytes ==
null) {
failMsg = "null
data received while parsing the input
XML, please check the input.";
throw new
InputValidationException("Invalid input
data error : " + failMsg);
}
String inputStr = null;
try {
inputStr = new
String(responseBytes, "UTF-8");
log.info("inputStr : " +
inputStr);
}
catch(UnsupportedEncodingException e) {
failMsg = "Please
check the encoding attribute value of
the input XML, it should be UTF-8.";
throw new
InputValidationException("Invalid input
data error : " + failMsg);
}
return inputStr;
}
}
After getting the input String, we can use this input String to do the necessary operations such as
database retrieval or update. After performing the necessary operations according to business
need, we now have an output file let's say output.xml. In this article I have used an output
String created from an output.xml for an illustration and in a real application this output can be
any String generated by any process. Now our goal is to return this result to the client as an
appropriate attachment i.e., if the input is DIME attachment we have to return the output String
as a DIME attachment and if the input is a MIME attachment we have to return output String as
a MIME attachment. Listing 6 shows the procedure to send the output String as a DIME
attachment.
Listing 6. Sending output as a DIME attachment.
Listing 7 shows the procedure to send the output String as a DIME attachment.
Listing 7. Sending output as a MIME attachment.
You might be wondering why a temporary file is used in case of a MIME attachment.
Technically whether it is a DIME or MIME the same code should work in the context of creating
an output DataHandler object. But, when using the Apache axis implementation it will not work
for MIME attachment. If we use the same procedure we will get
javax.mail.MessagingException. I observed this problem with Apache AXIS, you might not
get the problem with other implementations and in that case you can use the same code for both
DIME and as well as MIME attachments. This might be a bug in one of the open source
implementation and the work around for this is to use a temporary file for constructing
DataHandler and of course these temporary files will be deleted whenever the server restarts if
you use the above code.
Deployment of web Service
After developing the web service it is time to build the war file and deploy the application. The
src.zip file contains all the source code. The required jar files are activation.jar, axis.jar,
commons-discovery.jar, commons-logging.jar, jaxrpc.jar, log4j.jar, saaj.jar, soap.jar and
wsdl4j.jar. I used Maven to build the war file and you can find more info on Maven at maven
site. You can find the actual version of the jar files used in project.xml in my source distribution.
You can build the war file by using your favorite build procedure, but make sure that you include
all the required jar files in the final war distribution. Once you have the war file, you can just
deploy on any web server. I have used Tomcat as the web server. After you deploy the war file in
Tomcat, you will see an error in the AttachmentService.log file saying 'unable to find the config
file'. Do not worry about it, we are going to create server-config.wsdd by using the deploy.wsdd
file. Listing 8 shows the contents of deploy.wsdd file.
Listing 8. Contents of deploy.wsdd file.
<deployment
xmlns="http://xml.apach
e.org/axis/wsdd/"
xmlns:java="http://xml.
apache.org/axis/wsdd/pr
oviders/java"
xmlns:ns1="AttachmentSe
rvice">
<service
name="AttachmentService
" provider="java:RPC">
<parameter
name="className"
value="webservices.atta
chments.AttachmentServi
ce"/>
<parameter
name="allowedMethods"
value="getDimeData,getM
imeData"/>
<operation
name="getDimeData"
returnQName="returnqnam
e"
returnType="ns1:DataHan
dler">
<parameter
name="dh"
type="ns1:DataHandler"/
>
</operation>
<operation
name="getMimeData"
returnQName="returnqnam
e"
returnType="ns1:DataHan
dler">
<parameter
name="dh"
type="ns1:DataHandler"/
>
</operation>
<typeMapping
deserializer="org.apach
e.axis.encoding.ser.JAF
DataHandlerDeserializer
Factory"
languageSpecificType="j
ava:javax.activation.Da
taHandler"
qname="ns1:DataHandler"
serializer="org.apache.
axis.encoding.ser.JAFDa
taHandlerSerializerFact
ory"
encodingStyle="http://s
chemas.xmlsoap.org/soap
/encoding/"/>
</service>
</deployment>
After installing axis application on Tomcat web server, execute the following command in
/src/conf/ directory.
On Windows
java -cp %AXISCLASSPATH%
org.apache.axis.client.AdminClien
t
-lhttp://localhost:8080/axis
/services/AdminService
deploy.wsdd
On UNIX
java -cp $AXISCLASSPATH
org.apache.axis.client.AdminClien
t
-lhttp://localhost:8080/axis
/services/AdminService
deploy.wsdd
Please follow the guidelines listed on the axis user guide at Installing new WebServices.
Running the above command creates the server-config.wsdd file in the
webapps/AttachmentServices/WEB-INF directory. If you have trouble creating WSDD file, you
can just use the server-config.wsdd file included in the source distribution as it is. If you reached
this stage means our web service is ready to be accessed for outside world. You can check
WSDL file for this service at
http://localhost:8080/AttachmentServices/services/AttachmentService?wsdl. If you encounter an
error, it may be caused by problem during deployment of the war file or running the
AdminClient. Double check all the steps listed in axis installation user guide.
Client implementation
Once the web service is ready we can write a client application for accessing this. There are two
approaches for building the client application. One is to create some wrapper classes using some
utility classes provided by axis and using these wrapper classes you can create simple main
method. Another approach is to write a client application on your own. I used the latter approach
because it will be more useful in understanding what parameters were actually passed to the Call
object before invoking the web service. Practically, I found it to be more useful to know what is
happening rather than using the wrapper classes generated by some utility classes.
First, create the org.apache.axis.client.Call object as shown in Listing 9 :
Listing 9. Creating Call Object for the service.
Service service =
new Service();
Call call = (Call)
service.createCall(
);
After creating the call object, set various parameters that are needed before accessing the service
as shown in Listing 10 :
Listing 10. Client program to access the web service.
call.setTargetEndpointAd
dress(new
URL(WEB_SERVICE_URL));
//This is the
target services method
to invoke.
call.setOperationName(ne
w
QName(WEB_SERVICE_NAME,
operation));
QName
qnameAttachment = new
QName(WEB_SERVICE_NAME,
"DataHandler");
DataHandler dhSource
= new DataHandler(new
FileDataSource(INPUT_XML
));
call.registerTypeMap
ping(dhSource.getClass()
, //Add serializer for
attachment.
qnameAttachment,
JAFDataHandlerSerializer
Factory.class,
JAFDataHandlerDeserializ
erFactory.class);
call.addParameter("s
ource", qnameAttachment,
ParameterMode.IN); //Add
the file.
call.setReturnType(q
nameAttachment);
try {
Object
ret = call.invoke(new
Object[]{dhSource});
//Add the attachment.
log.info("ret : " +
ret);
if(ret ==
null) {
log.info("null
response received.");
} else
if(ret instanceof
String) {
String
errorMsg = (String)ret;
log.info("errorMsg : " +
errorMsg);
} else
if(ret instanceof
DataHandler) {
DataHandler dh =
(DataHandler)ret;
log.info("dh.getName() :
" + dh.getName());
byte[]
responseBytes =
Utils.getBytesFromDataHa
ndler(dh);
log.info("responseBytes
length : " +
responseBytes.length);
String
responseStr = new
String(responseBytes,
"UTF-8");
log.info("responseStr :
" + responseStr);
}
}
catch(RemoteException
e) {
log.error("AttachmentSer
viceException :" , e);
}
}
As seen in the client code in the source distribution, the only difference between sending a DIME
attachment and a MIME attachment is setting Call.ATTACHMENT_ENCAPSULATION_FORMAT
property.
Conclusion
As I have shown in this article, writing a web service that can handle attachments and the client
to access the web service using Apache Axis implementation is not a very difficult task, but there
is not enough documentation at one place to accomplish this complete task. Even though this
article talks about deploying in Tomcat web server, it should work on any J2EE web server. All
you need to do is to deploy the war file on the server and create server-config.wsdd.
Download
Download the source code of this article: Source Code
Resources
• For more information on Apache Axis and installation, refer to Axis Installation.
• For more information on processing attachments using JAX-RPC handlers, refer to
Process attachments using JAX-RPC handlers.
• For creating web services with Apache Axis, refer to Creating Web services with Apache
Axis.
• For more information on DIME attachments, refer to an article on DIME attachments.
By Jeevaraj Gnanaselvan Dhanaraj (jeevaraj_1970@yahoo.com)
(Jeeva has over 7 years of experience in designing and developing enterprise class web
applications using JAVA and J2EE technologies.
He currently works for Itreya Technologies, Bangalore, leading a team of over 10
programmers and designers, developing a multi-user, distributed, web-based workflow
application)
• Introduction
In this tutorial we will create a simple web service and a client web application using eclipse IDE
along with Lomboz plug in. We will also deploy and test the web service on Tomcat 5.5.4 web
application server. This application, while simple, provides a good introduction to Web service
development and some of the Web development tools available.
• Environment
J2SDK 1.4.2
http://java.sun.com/
Eclipse 3.1
http://www.eclipse.org/
Tomcat 5.5.4
http://tomcat.apache.org/
Lomboz 3.1RC2
http://lomboz.objectweb.org/
• Installation
Install JDK (in D:\j2sdk1.4.2_04)
Install Tomcat (in E:\Tomcat5.5)
Install Eclipse (in E:\Eclipse3.1)
Install Lomboz (in E:\Eclipse3.1)
• Setting up
1. Set up the installed JRE in eclipse (Windows -> Preferences -> Java -> Installed JREs)
2. Set up the installed runtime for server in eclipse (Windows -> Preferences -> Server -> Installed
Runtimes)
3. Set up the Server view in eclipse (Windows -> Show View -> Other)
4. Set up the Tomcat Server by right clicking and selecting New -> Server option from the Server
view in eclipse
• Creating a Web service
1. Create a new Dynamic Web Project in eclipse (File -> New -> Other)
2. Enter name as “WebServiceTutorial”, select project location as “E:\Test” and select Apache
Tomcat v5.5 as the Target server.
3. Now create a new Java class from the Project Explorer (Dynamic Web Projects -> Java Source
-> New -> Class)
19. Click on the sayHello(..) method, enter your name (for e.g. “Jeeva”) in the inputs section and
click “Invoke”.
20. The browser greets using the web service.
21. The WSDL for the Hello Web service can be found in
E:\Test\WebServiceTutorial\WebContent\wsdl\Hello.wsdl. On double-click, the WSDL opens in a
graphical editor.
22. Right-click on the WSDL file and explore the options to test the web service / publish the WSDL
file / generate client / etc.
• Conclusion
In this tutorial we learned how to create a simple web service and a client web application using
eclipse IDE along with Lomboz plug in. We also deployed and tested the web service on Tomcat
5.5.4 web application server. This application, while simple, provides a good introduction to Web
service development and some of the Web development tools available.
We saw some simple examples for XML-RPC & SOAP in the March,2004 issue. However, the
latest technology is Axis from Apache Software Foundation.
Apache Axis can be thought of as an improved implementation of Apache SOAP. While Apache
SOAP used DOM for XML parsing, Axis makes use of SAX and hence it is more efficient and
fast. Secondly, it supports automatic generation of WSDL (Web Service Description Language)
file. We have already seen how this is done in an earlier tutorial on utilizing JWS from
ASP.NET. (see axis1.htm ).
In that lesson, we had created a simple bean and exposed that as web service in Axis.
In this tutorial, we will create a Stateless Session Bean EJB using WebLogic-7 Enterprise server,
first. For a change, we will be using simple query as business logic rather than the customary
‘greeter’ bean. This will also help those readers who missed the earlier installments of the EJB
tutorial.
After developing the EJBean and deploying it in WebLogic-7 server, we will test it with a
standalone console-mode client. This is the correct step-by-step procedure in developing
programs. If it works well, we will create a JSP to access the EJBean. In all our previous
lessons, we had been using servlet as client for the EJB. This is the first time that we are using
JSP for accessing the EJB.
Normally, it is not a good practice to simply transfer the servlet code to JSP as scriplet, because,
in that case the business logic will be exposed to the web server administrator. If it is a servlet,
the developer is deploying the class file only in the web server. So the web server’s
administrator cannot see the source code for the business logic. But, if it is a JSP with plain
scriplet, without using ‘JSPbean’, the server administrator can see the source code. It is normally
observed that except in the OSF/FSF circles, business logic is not meant to be exposed to others.
That is why it is the standard practice to use a JSPbean and refer to it in the JSP file. It also helps
in partial separation of code and presentation. (Readers can refer to the first installment of J2EE
tutorial on page 110 of DeveloperIQ, October 2003 issue, for details on JSP, JSPbean
etc,available in j2ee1a.htm) .
But, in the present case, we need not follow that procedure and unnecessarily complicate things
because the actual business logic is in EJB and not in JSP. The JSP is simply the code for
invoking the EJB. This will considerably simplify things. We will deploy the JSP and test the
JSP in tomcat3.2 server.The big question now is “Why not deploy the JSP in weblogic server
itself?”
After all, any J2EE container will have provision for running Servlets & JSP, as also EJB. So it
is possible and sometimes recommended. But, it is not always essential and is sometimes to be
avoided for the following reasons:
1. It may not be desirable to get tied down to any one Enterprise server for all our requirements.
By keeping the servlet/JSP part in tomcat and using weblogic for EJB only, we achieve some
degree of independent operation. If we decide to use JBoss3.2 or JBoss4, later, we can just
change a few lines of code in the reference of our file. This type of flexibility may be necessary
in real life. Certainly, there may be some degradation in speed but what we lose in speed, we
gain in simplicity & freedom of choice. This is an architectural decision and opinions may
differ.
2. Moreover, Apache themselves are reported to be working on the creation of an EJB server
and it is certain that there will be greater synergy between tomcat and Apache EJB server when it
appears.
3. Besides all these reasons, we have a much more important reason for using tomcat as the
web-tier. We want to expose our EJBean as an XML-webservice, using Axis and it works fine
in tomcat as both are from Apache.
Some people prefer to use simple JavaBeans in place of EJB. But, it is not advisable…
Scalability, security, load balancing, transaction support etc. are of paramount importance in
enterprise and it will be most unreasonable to forego all these built-in advantages of EJBean and
opt for plain bean.
There was an interesting posting in the web by Joshua Davis on this topic as follows: (quoted
below).
Misconception (1)
‘J2EE = Java Server Pages’
‘Java Server Pages are useful for creating HTML user interfaces quickly, but that’s about
it. Projects that attempt to ‘simplify J2EE’ by using JSPs and Servlets without using
EJBs inevitably end up having transaction management problems.’
Misconception (2)
‘EJBs are too complex’
‘EJBs do not need to add significant complexity. Stateless session EJBs are not difficult
to write, and provide a simple way to expose transaction-managed functionality from an
EJB server. Home interface, remote interface, EJB implementation and deployment
descriptor are easily made as templates, & no complex ‘persistence’ is coed
A reference has been made by Manoj Kothale who has written about such templates, which can
be found in DeveloperIQ, October 2003 issue. It is advisable to avoid BMP beans and even CMP
is being replaced gradually by JDO (Java Data Objects). Castor is one such technology, which
was covered by Manoj Kothale in DeveloperIQ, March ’04 issue & there was an article on JDO
by Sivakumar (DeveloperIQ, July 2003 issue).Readers may get more information about this
latest and elegant technology from the book “Java Data Objects” from OReilly press,by David
Jordan & Craig Russell..
In Enterprise environment, the cost of and established server like WebLogic/WebSphere/JBoss,
more than offsets the expenditure, by comprehensive support and reliability with advanced
features.
However, while EJB is essential for Enterprise level, it is equally important to provide for inter-
operability, for at least some of the business logic. It extends the reach of the business object to
more clients. It is able to overcome firewalls and enables interaction between programs. And
that is the topic of our present tutorial.
So, we now proceed to study, how we can ‘expose’ our EJBean as an XML-webservice, using
Axis.
There are two methods, by which a bean can be exposed as a webservice in Axis. The first
method is just to write the java source code and save it as a file with *.jws extension in Axis
folder of tomcat ( as was done in the earlier article; please review the earlier lesson on this
technique as given on page 62, DeveloperIQ, Jan-2004 issue). This is known as ‘Drop-in
Deployment’.axis1.htm
This is a very simple and quick method.
But, this assumes that the java source file is available with us and secondly we do not mind that
source code to be visible to the tomcat administrator. Normally, it may not be desirable but in
the present case, the actual business logic is in the EJBean and the source code that is placed in
Axis folder of tomcat is only the code for the bean that calls the EJBean! So, there is no problem
at all! And this is an ultra-simple method of exposing our EJB service as an XML-webservice!
We will do that in first demo. Once we place this jws file in tomcat, we can easily get the
automatically generated wsdl file. This can then be used in ASP.NET or a java program.
Microsoft cannot be wished away! Any serious enterprise has to interact with Microsoft
platform. Secondly, a number of such webservices can interact with each other
programmatically.
This is why Sun’s J2EE1.4 has made XML-webservice the cornerstone of its implementation!
The second method is more involved and orthodox. This method is necessary if we do not want
our source code to be visible to anyone.
In this case, we create the Axis-bean, compile it and copy the class file to Axis/web-inf/classes
folder of tomcat. Then, we proceed to create a wsdd file (web service deployment descriptor).
This is an XML file. In the next step, we deploy the bean in tomcat. After this, we can easily get
the wsdl file.
Here again, we can either create a javabean to access our EJB and create a wsdd for that or we
can skip creating such a javabean and create a wsdd directly for the EJB. We will demonstrate
both the methods, but it is said that at present, neither stateful beans nor Entity beans can be used
in Axis. That may be a fact but if we adopt our method as outlined above, i.e. accessing the EBJ
by an Axis bean, it may be possible! And we will also demonstrate how the web service can be
accessed by a servlet and also by a WAP/J2ME client. The book “J2EE Blue Prints” from Sun
Micro Systems (Pearson-Education), discusses all these possibilities.To ensure that the wsdl file
works fine, we create a console mode program in java for accessing the web service and test it.
This introductory note on what is about to be done is necessary since there are so many files here
and we are likely to get confused.
It is assumed that we have already created a simple Access database named ‘telephone’ and a
table1 with just two fields (name and number)(both are strings). We should also remember to
register it in ODBC. As we have to first create the EJB, for it to be deployed, we now proceed to
do it.
We are using WEBLOGIC-7. That is being taken up in the next part of this seven part tutorial,
which follows.
Continued in axis2b.htm
Visit http://in.geocities.com/rsramsam
WEBSERVICE USING APACHE AXIS TUTORIAL-2
UNDERSTANDING APACHE AXIS
(part-2)
published in DeveloperIQ..April,2004) (www.developeriq.com)
R.S.RAMASWAMY(rs.ramaswamy@gmail.com)
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>
// 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);}
}
}
// 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>
// sqljspclient.htm
<html>
<body>
<form method=post
action=’sqljspclient.jsp’ />
sql
<input type=text name=’text1’ size=60>
<input type=submit>
</form>
</body>
</html>