Web Services from Stateless Session EJB3 with Websphere Integration Developer

How to create a bottoms-up Websphere with Websphere Integration Developer that is deployed to Websphere Application Server V7.

Below is the steps to create an simple Web Service using Websphere Integration Developer:

1. Open up Websphere Integration Developer and create an new EJB Project

Step 2: Click on the ‘New’ button to create a new EAR Membership.

The following 3 files will be created

Step 3: Create a new Stateless Session Bean

Step 4: Complete the following information below (Important to select Remote)

Step 5: Open the Bank interface object and add a method.

Step 6: Open your Stateless Session Bean File and right click and select ‘Override/Implementation Methods’, make sure the @Override notation is added to your code (see in red block)

Step 7: Add code inside your method

Step 8: Verify that there is no error.

Step 9: Add an Application Server to your WID IDE and start the server.

Step 10: Right click on your Application Server and click on ‘Add and Remove Projects’ and Select the BankAccount project

Step 11: Verify that the Application Server has successfully synchronized the new project and no errors occurred.

Step 12: Creating the Web Service is done in the following Steps, right click on your Stateless Session Bean and Select Web Service -> Create Web Service.  Your will see the following screens:

Confirm that the right Server type is selected, being WAS, WPS, WBM or any Application Server

For this example the binding type is HTTP, you can change it to JMS or EJB.

As we only have one method, select the method BankAccount. WS-Security can be added in this step to create a more secure Web Service.

Optional you can deploy your WSDL to the Websphere UDDI for Web Services discovery. Click Finish to complete. Confirm that Web Service creation was successful.

Step 13. Test your new Web Service by opening Web Services Explorer and browsing for the Bank.wsdl

Step 14: Enter the relevant information into the two fields provided and click ‘GO’

Web Service Completed successfully.  This Web Services can now be deployed to Websphere Registry and Repository to be discovered by all other systems in your environment.

Creating your first stateless session bean using RAD 7.5 running on WAS 7

Creating my first stateless session bean using Rational Application Developer 7.5 and deployed to Websphere Application Server V7.0.0.7 that shows the current system time.
Step 1: Create a new Enterprise Application Project.
Step 2: Create a new EJB Project by right clicking on the newly created Enterprise Application Project.
Make sure that to add the Enterprise Application Project as a EAR member.
Step 3: Right click on your newly created EJB project and select -> Session Bean
Enter the package name as: com.ibm.ejb.time
Enter the class name as: time
Make sure that business interface is set to Local
Step 4: Open the newly created Session Bean called time and add the following method.
Make sure that to add the Enterprise Application Project as a EAR member.
public String getTimeInfo(String timeinput) {
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
if timeinput != null && timeinput.length() > 0) {
timeinput = timeinput.toUpperCase();
}
return DateFormat.getTimeInstance().format(now) + ” on ” + df.format(now);
Make sure to add all the neccessary Imports using Quick Fix.
Step 5: Right click anywhere in the editor and Navigate to Java EE Tool -> Promote Method
Select ‘getTimeInfo’ method and click ‘OK’
Step 6: Go back to your Enterprise Exlorer and right click on the Enterprise Application Project created in Step 1.
Select New -> Dynamic Web Project
Make sure that to add the Enterprise Application Project as a EAR member.
Step 7: Right click on your newly created Dynamic Web Project and select ‘Properties’
Step 8: Select ‘Java EE Module Dependencies’
Select ‘Allow Both’ under reference to EJB JARs with EJB client JARs.
Select both JARs and click ‘OK’
Step 9: Create a new Servlet by right clicking on the Dynamic Web Project and selecting New->Servlet.
Enter the package name as: com.ibm.ejb.time
Enter the class name as: timeServlet
Accept the superclass javax.servlet.http.HTTPServlet
Click Finish.
Step 10: Open the new timeServlet.java file.
Add the following two commands under TimeServlet class:
@EJB
TimeLocal time;
Using quick fix import the neccessary packages.
Add the following commands under doGet class:
PrintWriter out = response.getWriter();
String time = clock.getClockInfo(“medium”);
out.println(“<html><body>”);
out.println(“<h3>The current time is:</h3>”);
out.println(“<p>” + time + “</p>”);
out.println(“</body></html>”);
Using quick fix import the neccessary packages.
Add the following commands under doPost class:
String format = request.getParameter(“timeinput”);
request.setAttribute(“time”, clock.getTimeInfo(timeinput));
RequestDispatcher rd = getServletContext().
getRequestDispatcher(“/index.jsp”);
rd.forward(request, response);
return;
Step 11: Import the index.jsp file into your Dynamic Web Project.
Step 12: Start an instance of Websphere Application Server inside RAD 7.5
After the instance has started right click on the Server and click on ‘Add and Remove Projects’
Step 13: Run the Dynamic Web Project by right clicking on it and selecting ‘Run As’->’Run on Server’Creating my first stateless session bean using Rational Application Developer 7.5 and deployed to Websphere Application Server V7.0.0.7 that shows the current system time.