SocialSite, Gadgets, and You(r Web Site)

In a previous SocialSite blog, I had a short screen cast that described in brief what your web site needs to do to include SocialSite gadgets. To save you some clicking, here it is again. In this blog, I'll give some more information, and, if you follow along, a complete working example. A simple example, but a working example.

In a recent email thread on our users list, Dave broke the integration down into three necessary steps:

  1. Add an authentication delegator page to your web app
  2. Add the SocialSite context and Gadgets to pages in your app
  3. Add socialsite_context.xml to SocialSite to specify your app's delegator page
I'll cover the steps here, starting with some pre-work.

Step 0, part A

Have a web site. In this example, I've used NetBeans to create a simple web app. No frameworks, nothing fancy, just a simple web app called SimpleWebApp with the default index.jsp file that is created for you. For this web app, the index.jsp page could be reached at http://localhost:8080/SimpleWebApp/. Start NetBeans, choose New Project, then Java Web -> Web Application and follow the prompts.

Step 0, part B

Install SocialSite. If you haven't done that yet, you're in the wrong blog. However, here are some steps that are necessary for getting gadgets running. When you first install SocialSite and go to the web app in a browser, you'll see a login form in the middle like this:

Login Form

If you already have users in your web application, you can register them here. For this example, I've clicked Want to register? and entered this information (the password, not that it matters, was password):

New User Information

Note: In one email to our user's list, someone tried using the built-in "admin" user in a sample web app. By default, the "admin" user has no profile and so the gadgets won't work until you create a profile. For instance, if you log into SocialSite as the admin you'll see this on the main page:

Admin has no profile

Step 1

Add an authentication delegator page to your web app. In the screen cast, this is the socialsite_context.jsp or context.html.erb file. A request for this file is sent by the SocialSite server, sending the same cookies to your web app that the client would. It's how your site can assert the identity of the current user to SocialSite. A real-life example of this file is in the socialsite workspace. For my simple web app that has no user authentication, I've hard-coded the user for demonstration purposes. Just create a socialsite_context.jsp page in your simple app and add this:

<%@ page language="java" %>
<%@ page contentType="application/json" %>
  'attributes': {
    <%-- demonstration only! --%>
    'viewerId': 'newuser'

In a real web app, make sure you specify the user here the same way you would in your other web pages, either with request.getRemoteUser() for Java EE container authentication or however you're handling authentication.

Step 2

Add the SocialSite context and Gadgets to pages in your app. Now you can add gadgets to your pages, though first you need to add some context for SocialSite. In this example (save file and open in an editor), I've added two javascript elements at the top to load information from SocialSite and to tell SocialSite where I put the authentication delegator page. These calls need to be in all the pages that are going to include gadgets, so it's a good idea if you have a header jspf file or something similar to put them there. The calls look like this:

    <script type="text/javascript"
    <script type="text/javascript">
        'attributes': {
          'ownerId': 'newuser' <%-- hard coded for demo! --%>
        'delegate': {
          'method': 'GET',
          'url': 'http://localhost:8080/SimpleWebApp/socialsite_context.jsp',
          'headers': {
            'cookie': document.cookie

In the body of the page, now you can add the calls to load SocialSite gadgets. For example:

    <script type="text/javascript">
      socialsite.addGadget({'spec':'/local_gadgets/dashboard.xml', 'removable':false});

Step 3

Add socialsite_context.xml to SocialSite to specify your app's delegator page. You're almost there. Finally, you need to let SocialSite know that it's ok to communicate with an external app -- specifically, that it's ok to let another site assert the id of the user. To do this, add a socialsite_context.xml file to SocialSite's classpath. For my "SimpleWebApp" example, here is the file to use. Note that it contains the URL of the context delegator page that you added in step 1. One easy way to add this file to your classpath is to copy it to your glassfish/domains/domain1/lib/classes/ directory, which should already contain a file that was added during installation. Restart GlassFish to pick this up.

More official documentation is on the way, but I hope this helps you get started. Feel free to add comments, and follow along on the SocialSite blog for all the latest information.


there is another socialsite_context.xml in src\\java\\com\\sun\\socialsite\\web\\rest\\opensocial directory, it is useless in this demo, right? If I use socialsite, should I write my own socialsite_context.xml instead of the socialsite's one?

Posted by Vincent on October 03, 2008 at 08:32 PM EST #

Hi Vincent,

That's the default context file used by SocialSite to allow it to run gadgets in its own pages. If you're comfortable building the source code, you could use that file and simply add your delegator URL like this:


However, it's a better practice (and easier) to create your own xml file, add it to the server's classpath, and the information will be picked up there. This is analogous to the way properties are handled in the file. This file exists in our source tree, but you can override property values by having them in the props file in glassfish/domains/domain1/lib/classes/

That way you can change properties or, in this case, the rules for which sites are allowed to have gadgets, without having to rebuild the workspace. In development, I often just change the props file in the source tree, but that's more overhead than you usually want.


Posted by Bobby Bissett on October 06, 2008 at 01:21 AM EST #

Thank you, Bobby. I had written two <direct> elements in socialsite_context.xml and it worked normally.
I have another problem here: the buttons at the bottum of dashboad in SimpleWebApp don't work. Any library(e.g. jmaki) is missed?

Posted by Vincent on October 06, 2008 at 02:00 PM EST #

Hi Bobby,

Sorry for the very basic question here.

In Step 0, part B
What does it mean "Install SocialSite" ?

Does it mean the same steps given in INSTALL.txt at

or some other steps required specific to NetBeans IDE ?

Could you provide the step, If any additional step required specific to IDE.

Posted by skyfam on October 06, 2008 at 08:21 PM EST #

For skyfam: Yep, I was referring to the regular installation (the URL you gave) and nothing specific to NetBeans. You could do all of this without NetBeans, but I used it to create the simple web app for me.

Vincent: I don't think you need any special libraries in your app -- they should all be loaded by SocialSite. Can you send an email to the users list and include anything you're seeing in your server.log and socialsite.log files?


Posted by Bobby Bissett on October 07, 2008 at 02:37 AM EST #

To anyone using the socialsite_context.xml file that I include in this blog, I originally left out the source element for the SocialSite server. So while gadgets will appear in your app, the ones in SocialSite will break. I just updated the file to include this line.

Posted by Bobby Bissett on October 10, 2008 at 03:34 AM EST #

Post a Comment:
Comments are closed for this entry.

Whatever part of GlassFish or the Java EE world that catches my attention. (Also, go Red Sox.)


« March 2015