• Entries (RSS)
  • Comments (RSS)

Creating a Hello World RESTful web service with RAD and WebSphere Application Server using IBM JAX-RS

Posted by | Posted in WebSphere | Posted on 22-05-2011

Tagged Under : , , ,

Creating a Hello World RESTful web service with RAD and WebSphere Application Server using IBM JAX-RS

REST is the buzzword now. So its time to learn how to create a RESTful web service now. Here is my simple hello world tutorial on creating a RESTful web service using Rapid Application Developer and IBM JAX-RS. JAX-RS is a Java API for developing REST applications. JAX-RS 1.0 defines a server-side component API to build REST applications. This ia an implementation of the JAX-RS (JSR 311) specification.

All the REST implementations I have seen need a minimum Java 1.5 to run. All these implementations use annotations. So my code will not work on WebSphere Application Server 6 and below versions. The minimum required version is WebSphere Application Server 6.1. I have tested these examples only in WAS 7. You need to have Feature pack for Web 2.0 for WebSphere installed on your application server. So once you have your app server ready with Web 2.0 feature pack installed then you have pretty much everything to get started. Follow the below steps to create your first hello world RESTful web service with RAD and WAS 7. For my development purposes I was using RAD 7.5. But I am sure that the following steps will work even for other RAD version too.
Read the rest of this entry »


Sending an e-mail using WebSphere Mail session settings.

Posted by | Posted in WebSphere | Posted on 27-10-2008

Tagged Under : , , , ,

Sending an e-mail using WebSphere Mail session settings.

Yesterday I had posted about configuring a Mail Session in WebSphere Application Server admin console. Today I will be talking about sending an email from your JSP using the configured mail session.

To access the Mail session for sending your email you need to do a JNDI lookup from your JSP file. The complete code for sending email using the Mail Session settings is given below.

	// Look up mail session
	javax.naming.Context context = new javax.naming.InitialContext();
	javax.mail.Session mailSession = (javax.mail.Session) context.lookup("mail/localmail");
	javax.mail.Message msg = new javax.mail.internet.MimeMessage(mailSession);
	msg.setFrom(new javax.mail.internet.InternetAddress(fromEmail));
	msg.setRecipients(javax.mail.Message.RecipientType.TO, javax.mail.internet.InternetAddress.parse(toEmail));
	System.out.println("Message Sent");

I have used the JNDI name directly for accessing the mail session settings. A better alternative is to use the resource reference in your JSP/Servlet code. The advantage of this approach is that we don’t need to alter the code even if our configuration name changes.

To add a resource reference opens your web.xml. Go to References Tab. Click on Add and select Resource Reference as the reference type and enter the details. For type select javax.mail.Session from the drop down box. If you are using resource reference, your lookup code will change to

	javax.mail.Session mailSession = (javax.mail.Session) context.lookup("java:comp/mail/localmail");

Configuring a Mail Session in WebSphere Application Server

Posted by | Posted in WebSphere | Posted on 25-10-2008

Tagged Under : , , ,

Sending emails is necessary in almost every web application. If your Web application is hosted in WebSphere Application Server you can lookup a Mail session from your servlet or JSP using JNDI. Today I will be explaining how to configure Mail Sessions in WebSphere Application Server? To configure your mail session settings follow the steps.

1. Login to admin console. The admin console url will be http://localhost:9060/admin if you are using the default port and your server is localhost. Else change the port and server name.

2. Click on Resources -> Mail providers.

3. From the page opened click on Built-in Mail Provider.

4. From Built-in Mail Provider page click on ‘Mail Sessions’ link.

5. The Mail Sessions page will be opened. Now click on New.

6. Mail session configuration page appears. Enter the details. Here Name is the administrative name of the JavaMail session object, JNDI name is the name of the resource. If your mail server needs a username and password for sending emails, enter Mail transport user ID and Mail transport password too.

7. Apply and Save the changes to master configuration.

You are done with the configuring your mail session settings. Now you can use the configured the mail session for sending mail from your web application using a JNDI lookup.


Changing the default port in WebSphere Application Server

Posted by | Posted in WebSphere | Posted on 27-08-2008

Tagged Under : , ,

Changing the default port in WebSphere Application Server

Sometimes we may need to change the default port of a WebSphere Application Server installation as a security precaution or for some other reasons like for coexisting with another WAS installation on the same machine. Moreover it’s always better to change the default ports in production environments. You can follow the below steps to change the default http port.

1. Logon to your admin console :-) (Obviously this is the first step. When we have such a nice interface available why we need to think some other options?).

2. Click on Servers -> Application servers -> .

3. Click on Ports link under communications, under the Configuration tab. (If you expand the Ports section click on details).

4. Click on the port name you want to change. Here I am changing the default http transport port. So I clicked on WC_defaulthost port.

5. Enter the port number you want to use in port text box. (Please make sure that port is not already used by some one else). Apply and save the changes. After entering the new port the WC_defaulthost will look like the one in the below image.

6. Now click on Environment -> Virtual Hosts. This page would display all the virtual hosts present in the system.

7. Click on default_host.

8. Click on Host Aliases.

9. Click on the port you want to change.

10. Enter the new port number.

Apply and Save the changes to Master Repository. You are done. Restart the server and now the server will start binding to the new port.


Configuring TAI in WebSphere Application Server

Posted by | Posted in WebSphere | Posted on 03-07-2008

Tagged Under : , , ,

Configuring TAI in WebSphere Application Server.

Yesterday I posted about how to create a custom Trust Association Interceptor for WAS. Today I will be explaining how to configure the TAI in WAS. In order to configure the TAI in WebSphere Application Server, export the TAI project as a jar file. (Creating and exporting a jar is very easy in RAD. Right click on the project and select Export. From the export wizard window select ‘JAR file’. It will show all the projects available with the one we right clicked as selected. Enter the destination where we want to save our generated jar file and enter a name for the jar file say tai.jar and click on Finish. Our jar file is ready).

Once we completed generation of jar file for TAI, we need to copy the same jar file to WAS_INSTALL_DIR\lib\ext folder. Now we need to make an entry for our TAI inside the admin console. The steps for configuring a TAI in WebSphere are given below.

1. Login to WebSphere admin console.
2. Click on Global Security under Security menu.
3. From the page opened up expand Authentication Mechanisms and click on LTPA
4. The LTPA configuration page opens up. Click on Trust Association links.
5. Select the “Enable trust association” check box. And save the changes.
6. Come back to the same page if you are not there already.
7. Click on Interceptors
8. Click on New
9. Enter the fully qualified name of your TAI inside “Interceptor class name” text box.
10. Save the changes

We are done. Restart the server and our new custom TAI will be ready for use.