Battle JBUILDER7 + WebLogic7 (4) Continued JMS + Message-Driven Bean

zhaozj2021-02-08  211

Because 9CBS can't display all articles, please browse the full text, please visit the following connection.

http://weisoft.myrice.com/docs/jmsmdb.htm

Introduction: 1. Connect MS SQL Server20002. Session bean3. Entity bean4. JMS Message-Driven Bean5. JSP call EJB (to be continued)

All actual combat content has been strictly tested, no problem, just strictly follow the steps in the text!

Actual Warfare 4: JMS

Configuring WebLogic

Start WebLogic7

2. Open IE6, type in the address bar:

3. Enter the username and password

4. Select Services-> JMS-> Connection Factories-> JMS-> Connection Factories on the directory tree on the left, click Configure A New JMS Connection Factory on the right, enter the following information:

Configuration-> General Page:

Name = MDBDEMO Connection Factory

JNDINAME = MDBDemocf

Others constant, click Create to create Connection Factory.

Targets-> Server Page:

Move your MyServer to the list of the right, but click Apply

5. Select Services-> JMS-> Stores in the directory tree on the left, click Configure a New JMSFileStore on the right, enter the following information:

Configuration-> General Page:

Name = mdbdemo store

Directory: = f: / bea / user_projects / mydomain / jmsstores (any existing directory)

Click Create to create JMSFileStore.

6. Services-> JMS-> Servers, click Configure A New JMS Connection Factory on the right, enter the following information:

Configuration-> General Page:

Name = mdbdemo jmsserver

Store = Mdbdemo Store

Others constant, click Create to establish JMS Server.

Targets-> Servers page:

Target = MyServer (the name of your WebLogic Server)

Click Configure Destinations in Configuration-> General Page to CONFIGURATION-> General

Name = mdbdemo Topic

JNDINAME = MDBDEMO TOPIC

Others constant, click Create to establish Destination.

The configuration is complete.

Establish Message Driven Bean:

1. Turn off all works: file-> Close Projects

2. Select File-> New Project

3. Enter mdbdemo in the Name column, enter the storage path in the Directory column (do not have spaces), other unchanged, click Finish.

4. Select File-> New-> Enterprise-> EJB Module Click OK. 5. In the pop-up dialog box, enter MDBMoudle in Name, Version Select: EJB2.0 Compliant is unchanged, click OK to close the current dialog.

6. Right click in the right side of the EJB Designer: Create EJB-> Message-Driven Bean, fill in:

Bean name = mdbdemo

Transaction Type = Container

Destination name = mdbdemo Topic

Destination Type = javax.jms.topic

Others constant.

7. Project-> make "mdbmodule"

Establish a client:

The following is the client source code, after the TestClient.java joining the project, select Run-> Run "testclient.java" Using defaults run, you can see the output at the WebLogic Console window. If you can't see the output, you will try it up for WebLogic.

Package mdbdemo;

Import java.rmi.remoteexception;

Import java.util.properties;

Import javax.jms.jmsexception;

Import javax.jms.message;

Import javax.jms.session;

Import javax.jms.TextMessage;

Import javax.jms.topic;

Import javax.jms.topicConnection;

Import javax.jms.topicConnectionFactory;

Import javax.jms.topicpublisher;

Import javax.jms.topics;

Import javax.ejb.createException;

Import javax.ejb.removeexception;

Import javax.naming.context;

Import javax.naming.initialcontext;

Import javax.naming.namingexception;

Import javax.rmi.portableremoteObject;

/ **

* This class illustrates calling a message-driven bean and publicing

* quotes on a topic.

*

* @Author Copyright (c) 1998-2002 by Bea Systems, Inc. All Rights Reserved.

* /

Public class testclient {

Static private string topic_name = "mdbdemo topic";

Private string m_url;

Private context m_context;

PRIVATE TOPICCONNECTION M_TOPICCONNECTION;

Public TestClient (String URL) THROWS NAMINGEXCEPTION

{

M_URL = URL;

Try {

//

// CREATE A Context

//

m_context = getInitialContext ();

//

// Create the connection and start it

//

TopicConnectionFactory CF =

(TopicConnectionFactory) M_Context.lookup ("MDBDemocf");

M_topicConnection = cf.createtopicConnection ();

m_topicConnection.start ();

}

Catch (Exception EX) {

EX.PrintStackTrace ();

}

}

/ **

* Runs this example from the command line. EXAMPLE:

*

* java example.ejb20.Message.Client "T3: // localhost: 7001"

*

* The Parameters Are Optional, But IF Any Areu Supplied,

* They area interpreted in this Order:

*

* @Param URL URL Such AS "T3: // localhost: 7001" of Server

* /

Public static void main (string [] args) throws exception {

LOG ("/ nbeginning message.client ... / n");

String URL = "T3: // localhost: 7001";

TestClient Client = NULL;

Try {

Client = New TestClient (URL);

} catch (namingexception ne) {

System.exit (1);

}

Try {

Client.example ();

}

Catch (Exception E) {

"" There Was An Exception While Creating and Using The MDB. ");

Log ("This Indicates That There Was A Problem Communicating with The Server:" E);

//e.printstacktrace ();

}

Log ("/ NEND MESSAGE.CLIENT ... / N");

}

/ **

* Runs this example.

* /

Public void example ()

THROWS RemoteException, JMSException, Namingexception

{

Topic newtopic = NULL;

TopicSession session = NULL;

Try {

session =

M_topicConnection.createtopicSession (false, // non transacted

Session.auto_acknowledge;

NEWTOPIC = (Topic) m_context.lookup (Topic_name);

}

Catch (namingexception ex) {newtopic = session.createtopic (Topic_Name);

m_context.bind (topic_name, newtopic);

}

TopicPublisher Sender = session.createpublisher (newtopic);

TextMessageTM = session.createtextMessage ();

String [] quotes = new string [] {

"Beas 40 1/8", "SUNW 79 1/2", "IBM 82 1/4", "Hello!"

}

For (int i = 0; i

Tm.Settext (quotes [i]);

Sender.publish (TM);

}

}

/ **

* USING A Properties Object Will Work on JDK 1.1.x and java2

* Clients

* /

Private context getInitialcontext () throws namingexception {

Try {

// get an initialContext

Properties h = new profment ();

H.PUT (Context.Initial_Context_Factory,

"WebLogic.jndi.wlinitialContextFactory");

H.PUT (Context.Provider_URL, M_URL);

Return New InitialContext (h);

}

Catch (Namingexception EX) {

LOG ("WE WERE UNABLE TO GET A Connection To The WebLogic Server AT" M_URL);

"" "" "" ");

Throw EX;

}

}

/ **

* This is the java2 version to get an initialcontext.

* This version relies on the existence of a jndi.properties file in

* The application's classpath.

*

* /

// private static context getInitialContext ()

// throws namingexception

// {

// Return New InitialContext ();

//}

Private static void log (string s) {

System.out.println (s);

}

}

Actual Warfare 5: JSP call EJB

(to be continued)

转载请注明原文地址:https://www.9cbs.com/read-2768.html

New Post(0)