Tuesday, November 23, 2010

Run OAuth service provider on GateIn portal

You can also test Shindig against the sample OAuth service provider from oauth.net:

Download the sample service provider code:

1. svn co http://oauth.googlecode.com/svn/code/java oauth
2. cd oauth
3. mvn install
4. cd example/oauth-provider/
5. In oauth-provider/target, copy .war and put into tomcat/webapps folder of GateIn
6. Add new consumer into oauth.json from exo.portal.gadgets-core-3.2.0-Beta01-SNAPSHOT.jar in lib folder
7. run gatein and add a oauth gadget to dashboard

Wednesday, November 17, 2010

ThreadLocal in java programming

* The java.lang.ThreadLocal [2] allows thread-specific variables to be added in an ad-hoc fasion to just about any code.
* The ThreadLocal class maintains a table associating data (Object references) with Thread instances. ThreadLocal supports set and get methods to access data held by the current Thread. [1]
* The following example is from [3] . When running the program notice that the ThreadLocal variable in column one remains the same throughout the program's run.

import java.util.Random;

public class ThreadLocal1
{

// Define/create thread local variable
static ThreadLocal threadLocal = new ThreadLocal();

// Create class variable
static volatile int counter = 0;

// For random number generation
static Random random = new Random();

// Displays thread local variable, counter,
// and thread name
private static void displayValues()
{
System.out.println(threadLocal.get() + "\t" + counter + "\t"
+ Thread.currentThread().getName());
}

public static void main(String args[])
{

// Each thread increments counter
// Displays variable info
// And sleeps for the random amount of time
// Before displaying info again
Runnable runner = new Runnable()
{
public void run()
{
synchronized (ThreadLocal1.class)
{
counter++;
}
threadLocal.set(new Integer(random.nextInt(1000)));
displayValues();
try
{
Thread.sleep(((Integer) threadLocal.get()).intValue());
displayValues();
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
};

// Increment counter, access thread local from
// a different thread, and display the values
synchronized (ThreadLocal1.class)
{
counter++;
}
threadLocal.set(new Integer(random.nextInt(1000)));
displayValues();

// Here's where the other threads
// are actually created
for (int i = 0; i < 5; i++)
{
Thread t = new Thread(runner);
t.start();
}
}
}


(from http://programmingexamples.wikidot.com/threadlocal)

Wednesday, November 3, 2010

Review Portlets In Action book

Portal is a concept, a technology that is not new to those who are developing portal applications. Nobody can deny its usefulness for developing portal applications. Features such as authentication, personalization, content aggregation, customization, etc. allow us to completely develop our complex portal applications on the existing portlet technology. Portal guides are often not detailed enough. In "Portlets in Action", Ashish Sarin gives us great detail. He sumarizes his portal development experiences and walks us through real-world requirements.

Sarin covers basic concepts such as portal, portlet, portlet container, portlet lifecycle, etc. to help both newcomers and those who are experienced with portal to be able to play their portlets on the portal. Theory is integrated with detailed, specific examples of each business requirement in order to give readers relevant techniques for their specific purposes.

Popular web technologies like Spring portlet MVC, Tag library, Hibernate, Ajax, DOJO, DWR, JQuery, etc. are each integrated into the examples. More advanced topics like communication with other portlets, web services for remote portlets, porting web applications to portlets using portlet bridges that help with migrating applications, are all covered in individual chapters.

Sarin also includes common examples that can be run on all of the popular portals. He always follows the standards used in portals JSR-286. It is not easy to be compatable with everything, but Sarin has done a large part of this successfully. Default examples are explained and illustrated for the Liferay portal and are also tested on the GateIn portal.

This book is still in the MEAP version and does not give detailed features of each specific portal. The author does, however, introduce some individual features, such as role-based security in GateIn and Liferay.

I find this book valuable for web developers interested in using powerful support to build web applications based on portal.
(Posted at Dzone)