Files located in the src directory
FILE: Client.java
import javax.jms.*;
import javax.naming.*;
import javax.ejb.*;
import java.util.*;
import mdbex.OrderARSHome;
import mdbex.OrderARS;
import weblogic.jms.*;
public class Client {
public static void main(String[] args) {
print("Starting Client . . .");
try {
String orderVerifierJndiName = "OrderVerifierTopic"; //args[0]; mdbex/OrderVerifier
String connectionFactoryJndiName = "weblogic.jms.ConnectionFactory";
// javax.jms.TopicConnectionFactory
// javax.jms.QueueConnectionFactory
// ?weblogic.jms.ConnectionFactory
// ?weblogic.jms.XAConnectionFactory
print("Looking up the JMS destination(Topic) via JNDI.");
Context context = new InitialContext();
Topic topic = (Topic)context.lookup(orderVerifierJndiName);
print("Locating connection factory.");
TopicConnectionFactory connectionFactory =
(TopicConnectionFactory)context.lookup(connectionFactoryJndiName);
print("Creating a connection and establishing a session.");
TopicConnection connection =
connectionFactory.createTopicConnection();
TopicSession session =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher publisher = session.createPublisher(topic);
print("Creating an order with status:Submitted");
Context initialContext = new InitialContext();
Object object = initialContext.lookup("mdbex/OrderARS");
OrderARSHome orderHome =
(OrderARSHome)javax.rmi.PortableRemoteObject.narrow(object,
OrderARSHome.class);
OrderARS order = (OrderARS)orderHome.create("1", "Submitted", 100);
String orderId = order.getOrderId();
print("Order id " + orderId + " is created");
print("Creating a text message with order id and publishing it.");
TextMessage tm = session.createTextMessage();
tm.setText(orderId);
publisher.publish(tm);
print("Sleeping for 5 sec.");
Thread.sleep(5000);
print("Now the order status is:" + order.getStatus());
} catch (Exception ex) {
System.err.println(ex);
ex.printStackTrace();
}
}
static void print(String s) {
System.out.println(s);
}
}
FILE: jndi.properties
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.factory.url.pkgs=weblogic.jndi.factories:weblogic.corba.j2ee.naming.url:weblogic.corba.client.naming
java.naming.provider.url=t3://localhost:7101
java.naming.security.principal=weblogic
java.naming.security.credentials=weblogic
Located in the MDBentity library( ../src)
FILE: build.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="EJB3 Tutorial" basedir="." default="deploy">
<property name="deploy.dir" value="C:/MDBentity/deploy" />
<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/build"/>
<property name="librarydir" value="${basedir}/lib"/>
<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="${targetdir}"/>
<mkdir dir="${targetdir}"/>
</target>
<target name="compile" depends="copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"
debug="on">
<compilerarg value="-Xlint"/>
</javac>
</target>
<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="deploy" description="JARs the Task" depends="clean,copy-resources,compile">
<jar destfile="${deploy.dir}/MDBent.jar">
<metainf dir="${sourcedir}/META-INF" />
<fileset dir="${targetdir}">
<include name="**/*.class" />
</fileset>
</jar>
</target>
<target name="undeploy" description="Undeploy jar from server">
<delete file="${deploy.dir}/MDBent.jar" />
</target>
<target name="run" depends="compile">
<java classname="Client" classpathref="libraries">
<classpath path="${targetdir}"/>
<jvmarg value="-Djava.library.path=./lib"/>
</java>
</target>
</project>