Chapter 6. EIS integration using Java Message Service 147
Figure 6-11 IMS service bindings including the InvokeTrader operation
To create the Java utility classes, select the services WSDL file (for example,
TraderEISIMSService.wsdl), and select Enterprise Services
Generate
Service Proxy. In the wizard that opens, you can accept all defaults. However,
in the last window you have to select the proxy style and the operation. We
recommend that you select Client Stub style. This results in the generation of
methods at the proxy class that map to the defined methods in the binding WSDL
file.
In addition to the proxy class, the wizard generates the Java utility classes that
we used in the following steps. You create Java classes that map to the input and
output data structures that you have selected from the COBOL copybook. These
classes can be used to set the input and get the output of the operation. The
wizard also generates Web Services Invocation Framework (WSIF) format
handlers that are used by the underlying WSIF environment to generate the byte
stream that is sent to the IMS system. Although did not use WSIF to invoke the
IMS transaction, we used the format handlers to generate the byte stream.
148 Managing Information Access to an EIS Using J2EE and Services Oriented Architecture
We also recommend that you test the generated artifacts in a J2SE environment
right away. For this purpose, we suggest that you create a JUnit test case for the
proxy class:
1. Highlight the proxy class in the Navigator view and select File
New
Other from the menu bar.
2. Go to Java
JUnit.
3. Select Test Case and click Next.
You can accept the defaults but make sure that you check all options at the
bottom of the window as depicted in Figure 6-12.
Figure 6-12 Generate a JUnit test case
4. In the next window, select the operation that you have defined in the Service
Creation wizard and click Finish.
In the test class that gets generated, you have to add a class variable with the
type of the proxy class, for example TraderEISProxy in our scenario. Instantiate
the class in the setUp() method, and de-reference it in the tearDown() method.
Finally, you also have to code the test method. Example 6-1 on page 149 shows
the code to invoke the Trader method.
Chapter 6. EIS integration using Java Message Service 149
Example 6-1 JUnit test class
public void testInvokeTrader() {
// Initialize
boolean result = false;
int inSize = new com.itso.ims.ibmcobol.INBUFFERFormatHandler().getSize();
INBUFFER in = new INBUFFER();
OUTBUFFER out = new OUTBUFFER();
try {
// Set input to call Buy
in.setIn__ll((short) inSize);
in.setIn__zz((short) 0);
in.setIn__trcd("TRADERBl");
in.setRequest__type("Buy_Sell");
in.setCompany__name("IBM");
in.setUserid("TestUser");
in.setNo__of__shares__dec((short) 5);
in.setUpdate__buy__sell("1");
// Call transaction
System.out.println("Calling IMS transaction ...");
out = tp.InvokeTrader(in);
// Transaction completed
System.out.println("Transaction completed.");
result = true;
} catch (WSIFException e) {
System.out.println("In catch block ...");
e.printStackTrace();
} finally {
assertTrue(result);
}
}
You run the JUnit test class by selecting Run Run from the menu bar. In the
window that opens, select JUnit and click New. Make sure that the test class is
entered correctly and click Run.
The generation process of the Java utility classes can also be started as a batch
job. WebSphere Studio Application Developer Integration Edition provides
templates for XML-based configuration files and a executable to run the service
and helper class generation in the background. We recommend that you use the
Note: If you cut and paste code into the generated Java stub, many types are
not recognized because the corresponding import statements are missing.
Right-click in the code and select Source
Organize Imports to let the tool
create the statements for you.
150 Managing Information Access to an EIS Using J2EE and Services Oriented Architecture
batch import and generation if your IMS transactions and COBOL copybooks
change frequently. Refer to the WebSphere Studio Application Developer
Integration Edition Help for more details (search for
batch import).
IMS transactions often return multi-segmented messages which means that they
return a byte stream with variable length and data structures. The WebSphere
Studio Application Developer Integration Edition tools cannot generate the WSIF
format handlers and helper classes for multi-segmented messages. A
workaround is to generate helper classes for the different segments by defining
an artificial operation that returns each segment. The segment data type can be
selected from the COBOL copybook for that transaction. Having created the
WSIF format handlers for the segments, development of code to parse the byte
stream returned by the IMS transaction is facilitated.
Creating the IMS access feature
As described in section “The stock trade scenario” on page 137, the IMS feature
consists of the utility classes and a session bean. The session bean implements
the feature interface.
We created the session bean using the J2EE tools of WebSphere Studio
Application Developer Integration Edition. To do this:
1. Go to the J2EE perspective, and select the EJB project in the J2EE Hierarchy
view.
2. Open the EJB generation wizard by selecting New
Enterprise Bean.
In the wizard, you select the bean type (for example, session bean) and
provide names for the bean and the Java package. For the feature bean, you
also have to generate a local interface, so make sure to check Local client
view.
Furthermore, you can select the interface that the session bean extends for both
the local and remote view. In this case, you have to create the feature Java
interface as depicted in Figure 6-7 on page 140. Alternatively, you can add the
methods to the bean implementation class and promote the methods to the local
and remote interface, respectively.
Example 6-2 on page 151 shows the code for the Trader IMS feature of the
interface operations. In the runTransaction() method, we used the J2C API to
access the IMS system. The INBUFFER and OUTBUFFER Java classes and the
corresponding WSIF format handlers are generated by the WebSphere Studio
Application Developer Integration Edition wizard.
Chapter 6. EIS integration using Java Message Service 151
Example 6-2 Trader IMS feature session bean methods
private StockOrderRequest request = new StockOrderRequest();
private StockOrderConfirmation confirmation = new StockOrderConfirmation();
public void setInput(StockOrderRequest request) {
this.request = request;
}
public StockOrderConfirmation getOutput() {
return confirmation;
}
public void runTransaction() {
int inSize = new
com.itso.ims.ibmcobol.INBUFFERFormatHandler().getSize();
INBUFFERFormatHandler infh = new INBUFFERFormatHandler();
INBUFFER in = new INBUFFER();
OUTBUFFERFormatHandler outfh = new OUTBUFFERFormatHandler();
OUTBUFFER out = new OUTBUFFER();
JCARecord inrecord = new JCARecord();
JCARecord outrecord = new JCARecord();
try {
// get IMS connection factory
InitialContext cxt = new InitialContext();
IMSConnectionFactory cf = (IMSConnectionFactory)
cxt.lookup("java:comp/env/eis/IMSTrader");
// create J2C connection spec and interaction spec
IMSConnectionSpec ics = new IMSConnectionSpec();
ics.setUserName("java1");
ics.setPassword("java1");
IMSConnection ic = (IMSConnection)
cf.getConnection((ConnectionSpec)ics);
IMSInteractionSpec iis = new IMSInteractionSpec();
iis.setCommitMode(1);
iis.setExecutionTimeout(1000);
IMSInteraction ii = (IMSInteraction) ic.createInteraction();
// set input data
in = (INBUFFER) infh.getObjectPart();
in.setIn__ll((short) inSize);
in.setIn__zz((short) 0);
in.setIn__trcd("TRADERBl");
in.setRequest__type("Buy_Sell");
in.setCompany__name(request.getStockOrderBO().getStock());
in.setUserid(request.getStockOrderBO().getAccount());
in.setNo__of__shares__dec((short)
request.getStockOrderBO().getQuantity());
in.setUpdate__buy__sell("1");
..................Content has been hidden....................

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