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:
- Add an authentication delegator page to your web app
- Add the SocialSite context and Gadgets to pages in your app
- 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:
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):
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:
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"
src="http://localhost:8080/socialsite/js/consumer.jsp"></script>
<script type="text/javascript">
socialsite.setContext({
'attributes': {
'ownerId': 'newuser' <%-- hard coded for demo! --%>
},
'delegate': {
'method': 'GET',
'url': 'http://localhost:8080/SimpleWebApp/socialsite_context.jsp',
'headers': {
'cookie': document.cookie
}
}
});
</script>
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});
</script>
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 socialsite.properties 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.