Chapter 6. EIS integration using Java Message Service 157
Example 6-5 Trader IMS integration Message Driven Bean method
public void onMessage(javax.jms.Message msg) {
StockOrderRequest request;
StockOrderConfirmation confirmation = new StockOrderConfirmation();
try {
ObjectMessage m = (ObjectMessage) msg;
request = (StockOrderRequest) m.getObject();
confirmation.setStockOrderBO(request.getStockOrderBO());
InitialContext cxt = new InitialContext();
TraderIntegrationLocalHome localhome = (TraderIntegrationLocalHome)
cxt.lookup("java:comp/env/ejb/TraderIntegration");
TraderIntegrationLocal local = localhome.create();
confirmation = local.invoke(request);
confirmation.setMessage("Message was sent");
} catch (CreateException e) {
e.printStackTrace();
confirmation.setMessage("Message could not be delivered");
} catch (NamingException e) {
e.printStackTrace();
confirmation.setMessage("Message could not be delivered");
} catch (JMSException e) {
e.printStackTrace();
confirmation.setMessage("Message not valid");
}
}
The TraderIMSIntegration MDB receives and processes the incoming message
but does not send a reply message. You can extend the bean by encapsulating
the StockOrderConfirmation object into an ObjectMessage and by sending the
message to a reply queue. The code snippet to add this feature is similar to the
code shown in Example 6-6 on page 158. This example depicts client code that
sends messages to the MDB.
To test the JMS channel of the Trader EIS component, we created a session
bean and added the invokeNoResponse() method. To send a message, you first
retrieve the connection factory and the queue to send to from JNDI. Then, you
create a queue session and a sender object. Finally, you call the send() method
at the sender object and pass the message that you have created.
The session EJB that provides the invokeNoResponse() method can now be
easily integrated into BPEL processes. For this purpose, the service creation
wizard of WebSphere Studio Application Developer Integration Edition is used
(see Example 6-6 on page 158).
158 Managing Information Access to an EIS Using J2EE and Services Oriented Architecture
Example 6-6 Trader IMS integration JMS client
public void invokeNoResponse(StockOrderRequest sor) {
// invoke service
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
ObjectMessage message = null;
try
{
jndiContext = new InitialContext();
// Look up connection factory and queue
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("java:comp/env/jms/TraderQCF");
queue = (Queue) jndiContext.lookup("java:comp/env/jms/TraderQueue");
// Create connection.
queueConnection = queueConnectionFactory.createQueueConnection();
// Create session from connection
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// Create sender and text message.
queueSender = queueSession.createSender(queue);
message = queueSession.createObjectMessage();
message.setObject(sor);
// Send messages
queueSender.send(message);
}
catch (NamingException e) { e.printStackTrace(); }
catch (JMSException e) { e.printStackTrace(); }
finally {
if (queueConnection != null)
{
try { queueConnection.close(); }
catch (JMSException e) {}
}
}
}
To create a service:
1. Go to the Business Integration perspective and select File
New
Service built from.
2. Select EJB in the window that opens and click Next.
Chapter 6. EIS integration using Java Message Service 159
3. In the next window browse to the EJB and select the method that you wish to
call from the BPEL process.
4. Click Next. You can accept the defaults for the service name and the names
of the WSDL files and click Finish.
The wizards creates the three WSDL files that describe the service: its interface,
the EJB binding details, and the EJB service location details. You can later
include the EJB service as BPEL partner link into a BPEL process (see
Chapter 9, “Integration into business processes” on page 241).
WebSphere Business Integration Server Foundation includes the extended
messaging feature that extends the base JMS support and support for MDB by
introducing container managed messaging. Additional types of EJBs, for
example a sender EJB, are introduced and new management objects are
available at the administration console to configure the environment for those
beans. Although we have not attempted to use extended messaging in our
sample scenario, we would recommend that you evaluate its use for real
environments.
6.4.4 Deploying the EIS component
The Trader EIS component consists of EJB modules including session EJBs,
MDB, and Java utility classes. To deploy the component to the test environment
or to a WebSphere Application Server instance, you have to create and configure
the following administration objects for that server:
???? A JAAS security alias for the IMS user on the IMS host. The alias is later used
when creating the J2C connection factory.
???? A J2C IMS connection factory to connect to the J2C IMS resource adapter.
???? JMS connection factories for the MDB and for the sender bean of the EIS
component’s client.
???? JMS destinations and queues for the MDB and for the sender bean.
???? A JMS listener port for the MDB.
Configuration of these resources is error-prone. In particular, mismatches when
specifying JNDI names often cause issues. Even in production environments, we
have seen misconfigurations (for example, for the JMS listener ports). To avoid
bottlenecks and to be able to process many messages simultaneously, you might
have to adapt the size of the thread pool for a JMS listener port.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset