The final process in creating a Java application that accesses
an IMS transaction is to wrap the J2C Java bean in a web page, web service,
or EJB so that it can run on a J2EE application server such as WebSphere Application
Server.
This example illustrates how to wrap the J2C Java bean using a JSP
dynamic web application. To create a JSP dynamic web application from a J2C
Java bean, complete the following steps:
- To start the J2C dynamic wizard, from the menu bar, select File
> New > Other > J2C.
- With the J2C folder expanded, select Web Page, Web Service,
or EJB from J2C Java Bean.
- Click Next.
- In the J2EE Resource from J2C Java Bean wizard, complete the following
steps:
- On the J2C Java bean selection page, next to the J2C bean implementation
entry field, click Browse.
- In the Select entries field, prime the entry field with an asterisk
(*) to view the available data types, select PBImpl.java from
the Matching types list and click OK.
- The J2C bean implementation field should contain /PhoneBookJ2CBean/sample/ims/PBImpl.java.
- Click Next.
Note: If you get
the message, "Resource nnnnn, referenced by the J2C code, is
not found on servers. Please make sure that resource nnnnn exists," it
may be that the resource has not been saved to the master configuration of
the server. If you do not get this error, continue to Step 6.
Otherwise,
to eliminate this error message, select Cancel,
then perform the following steps to save your resource to the master configuration
of the server:
- In the Servers view, ensure that the server is started.
- Right-click the server and select Run administrative
console.
- Log in to the administrative console.
- In the left pane, expand Resources and
select Resource adapters.
- At this point a warning message may appear, "The master
configuration has been updated. You currently have workspace conflicts with
these modifications. To see these updates you must Save or discard your current
workspace modifications." Save your modifications.
- If the problem persists, try stopping and starting the server.
- In the Deployment Information page, select JSP and
then click Next.
- In the JSP Creation page, select Create a Faces JSP
and add J2C Java bean as available page data.
- Next to Web project, click New, to create
a new dynamic web project. The New Dynamic Web Project window
opens.
- In the Name field, type PhoneBookWeb and
click Finish.
- Select Yes to switch to the web perspective
when requested to do so.
- In the JSP Creation page, leave the JSP Folder name blank.
- For the name of the Faces file, type PBookF.
Note: The name of the EAR project defaults to PhoneBookWebEAR.
- Click Show Advanced and type a name for
the Resource Reference. For example, myCFacRef. Note: It is strongly recommended that you provide a resource
reference for your J2EE resource. Not only does this allow you to map your
J2EE resource to different J2C connection factories when you install your
EAR on other WebSphere Application Servers, but if you do not use a resource
reference you may receive unpredictable results when running your application.
- Click Finish. The file, PBookF.jsp opens
in the JSP editor.
- Ensure that the Design tab in the JSP editor
is selected.
- Ensure that the Page Data view is open.
- In the Page Data view, complete the following steps:
- Expand java (sample.ims.PBImpl).
- Drag and drop the method runPB(sample.ims.data.INPUTMSG) onto
the Design view of PBookF.jsp in the JSP editor. The runPB(sample.ims.dat.INPUTMSG) method
entry in the Page Data view is identified with an M icon. If you have
exposed properties of IMSInteractionSpec or IMSConnectionSpec, the signature
of the runPB method will contain additional arguments.
- In the Configure Data Controls page of the Insert Java Bean
wizard, select the fields that you wish to use to input data to the runPB
method and optionally the exposed input properties of IMSInteractionSpec and
IMSConnectionSpec. Then, click Next. You
can change the order of the input fields by selecting a checked field and
using the up and down arrows to the right of the Fields to display list to
move the input field.
- Use the next page of the Insert Java Bean wizard to select the
fields that you wish to see as output data from the output message of the
runPB method, and optionally the exposed output properties of IMSInteractionSpec.
Select the fields that you wish to see as output data from the runPB method
and then click Finish.
- Close PBookF.jsp to save your changes.
You have now wrapped the J2C Java bean in a web page so that it can
run on a J2EE application server.