developing sleek and collaborative applications with opensocial and ajax push

44
Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push. S304285 Ted Goddard, Ph.D. Senior Software Architect, ICEsoft Chris Schalk Developer Advocate, Google

Upload: chris-schalk

Post on 21-Jan-2015

1.530 views

Category:

Technology


1 download

DESCRIPTION

Presentation: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push.This was presented at Community One 2009 on June 1st in San Francisco by Ted Goddard of IceFaces and Chris Schalk of Google.

TRANSCRIPT

Page 1: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

Developing Sleek andCollaborative Applications withOpenSocial and AJAX Push.

S304285

Ted Goddard, Ph.D.Senior Software Architect, ICEsoft

Chris SchalkDeveloper Advocate, Google

Page 2: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

22009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Learn the fundamentals ofOpenSocial and Ajax Push. Put itinto practice with the OpenSocialJava API and ICEfaces.

Page 3: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

32009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 4: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

42009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Why AJAX Push and Collaboration makes Sensecollaboration = social + push

Collaboration requires communication

Communication requires real-time updates

Communication flows through a social network

Ajax Push is the key to communication on the web

Page 5: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

52009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 6: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

62009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

What is OpenSocial?

“OpenSocial defines a common set of APIs based on Open Standardsfor building social applications across multiple websites”

Page 7: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

72009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

What is OpenSocial?

Before OpenSocial…

Page 8: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

82009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

What is OpenSocial?

Standards Based

Page 9: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

92009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

What is OpenSocial?

Learn once… Write everywhere

Page 10: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

102009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Who owns OpenSocial?

OpenSocial is managed under the auspices of the“OpenSocial Foundation” - http://www.opensocial.org

No!?

Page 11: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

112009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Who’s Using it?

Page 12: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

122009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Now has over 800 Million users

Page 13: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

132009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 14: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

142009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

OpenSocial REST Support

As of V0.8 OpenSocial supports REST protocols

Opens new development models

• Server-to-server communication

• Multiple client types

• Server based UIs (JSP/JSF)

• Mobile devices

Page 15: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

152009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

RESTful Protocol• Resources are URLs.

/people/{guid}/@all

• All people connected to the given user:Example - People:

/people/{guid}/@friends

• All friends of the given user:

/people/{guid}/@self

• Profile of the given user:

/people/@me/@self

• Profile of the authenticated user:

/people/@supportedFields

• Supported Person fields:

Page 16: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

162009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

• Request extra fields

• Filtering:

• Paging:

fields={-join|,|field}.

filterBy={fieldname}filterOp={operation}filterValue={value}updatedSince={xsdDateTime}networkDistance={networkDistance}

count={count} sortBy={fieldname}sortOrder={order}startIndex={startIndex}

format={format}

RPC Protocol• Http POST instead of GET

Page 17: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

172009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

OpenSocial Client Libraries

17

http://code.google.com/p/opensocial-php-client http://code.google.com/p/opensocial-ruby-clienthttp://code.google.com/p/opensocial-python-clienthttp://code.google.com/p/opensocial-java-client

A set of client libraries that enabledirect communication to an OpenSocialserver.

• Client libraries exist for PHP, Ruby, Python and Java• Supports both REST and RPC protocols• Documentation Wiki pages• Sample applications provided

Page 18: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

182009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Sample: Fetching a user’s friends from Shindig

OpenSocialClient c = new OpenSocialClient("myhost.com");

c.setProperty(OpenSocialClient.Properties.REST_BASE_URI, "http://localhost:8080/social/rest/"); try { OpenSocialPerson p = c.fetchPerson("john.doe"); System.out.println(p.getDisplayName());

Collection<OpenSocialPerson> friends = c.fetchFriends("john.doe"); for (OpenSocialPerson friend : friends) { System.out.println(friend.getDisplayName()); }

} catch (Exception e) {

}

Page 19: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

192009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 20: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

202009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

OpenSocialServer-side REST accessdemonstrations

Page 21: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

212009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

OpenSocial Facts

Originally a Google led initiative

Launched in November 2007

Serves as a set of standard APIs for build social applications

Is managed through OpenSocial.org

Current version is 0.9.

OpenSocial APIs center on 3 core areas:People, Activities, Data

Initially only resided in gadgets only

As of 0.8, RESTful APIs have been availableEnables server/desktop/mobile integrations

Over 800 million users of OpenSocial technology worldwide

Page 22: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

222009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Social SecurityMind what you share.

Build applications with UI security, such as with JSF• Output is escaped, avoiding cross-site scripting• Input processed by components, avoiding network attacks• Input processed by ORM, avoiding SQL injection

User data and Social model have privacy concerns

OAuth Consumer Secret and Consumer Key forauthentication

Page 23: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

232009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 24: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

242009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Ajax Push for Social Applicationscollaboration = social + push

Real-time updates offer many possibilities

Friend statusPolls, surveys, voting, questions and answersCollaborative top-10 listCurrent mp3, browser URL (security risk?)AuctionsGamesFlash mobs (or just meet for coffee/lunch)And, of course, chat applications

Page 25: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

252009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Social Networking in the EnterpriseA valuable new form of collaboration.

duke: love the new pic lolhalf a minute ago from web · Reply · View Tweet

Page 26: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

262009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Social Networking in the EnterpriseA valuable new form of collaboration. Seriously.

In-house deployed system avoids distractionsWorkplace formality improves communicationSocial Application informality eases communication

Uses:• Task completion updates• Requests for information• Bug report updates, automated build/test completion• Collaborative meeting tools• Org-chart structured communications, call setup• Multi-step business processes

Page 27: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

272009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 28: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

282009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 28

Server-mediated CollaborationThe full realization of Ajax.

Server

Chris Ted

UserAction Push

Page 29: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

292009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 29

Server-initiated UpdatesStocks, sensors, and status.

Server

Chris Ted

External Application

Push Push

Page 30: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

302009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 30

Ajax Push (Long Polling)HTTP message flow inversion.

GET /auctionMonitor/block/receive-updates?icefacesID=1209765435HTTP/1.1Accept: */*Cookie: JSESSIONID=75CF2BF3E03F0F9C6D2E8EFE1A6884F4Connection: keep-aliveHost: vorlon.ice:18080

HTTP/1.1 200 OKContent-Type: text/xml;charset=UTF-8Content-Length: 180Date: Thu, 27 Apr 2009 16:45:25 GMTServer: GlassFish/v3

<updates> <update address="_id0:_id5:0:chatText"> <span id="_id0:_id5:0:chatText">Howdy</span> </update></updates>

Chat message “Howdy”

Page 31: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

312009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 31

Ajax Push ServerOne connection is all you need.

ICEfacesApplication

Ajax PushServer

ApplicationServer

Asy

nchr

onou

s C

onne

ctio

ns

ICEfacesApplicationJMS

http:// host / ajaxpush /

Page 32: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

322009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 33: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

332009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

ICEfaces OpenSocialOpenSocial Activities with Ajax Push

Page 34: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

342009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 35: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

352009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 35

JavaServer Faces for AjaxA language for Developers and Designers

public class PageBean { String message;

public String getMessage() { return message; }

public void setMessage(String message) { this.message = message; }

}

<f:view xmlns:f=“http://java.sun.com/jsf/core” xmlns:h=“http://java.sun.com/jsf/html” >

<html> <body> <h:form> <h:inputText value=“#{pageBean.message}” /> </h:form> </body> </html>

</f:view>

PageBean.java Page.xhtml

Page 36: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

362009 CommunityOne Conference: EAST | developers.sun.com/events/communityone 36

Render-based PushAjax Push in two lines of code with ICEfaces.

To keep track of groups of users:

SessionRenderer.addCurrentSession(personName);

Asynchronously and elsewhere in the application ...

socialClient.createActivity(title, body);SessionRenderer.render(“javaone”);

The JSF lifecycle runs, updating each user’s page from thecomponent tree and current model state.

Page 37: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

372009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Socializing Ajax PushImplementing Push on top of OpenSocial.

OpenSocial is a RESTful protocol• Push is not built-in• OpenSocial servers do not provide notification

Add Ajax Push to your web application front-end• This technique used in the demo

Implement notification in an activity handler

Define blocking semantics for OpenSocial REST?

Page 38: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

382009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

ActivityBean.java (Initialization)

OpenSocialProvider shindig;OpenSocialClient socialClient;

private void init() {

SessionRenderer.addCurrentSession(personName);

socialClient = new OpenSocialClient(shindig);

socialClient.setProperty( OpenSocialClient.Property.TOKEN, “owner:” + personName + “:appid:domain:apprul:module:container” );

}

Java

Page 39: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

392009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

ActivityBean.java (Input)

public String activate() {

socialClient.createActivity(newTitle, newBody);

SessionRenderer.render(personName);

return "success";

}

<ice:form >

<ice:inputText value="#{activityBean.newTitle}" /> <ice:inputText value="#{activityBean.newBody}" /> <ice:commandButton value="Post” action="#{activityBean.activate}" />

</ice:form>

Java

XHTML

Page 40: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

402009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

ActivityBean.java (Output)

public ArrayList getActivityList() {

return socialClient. fetchActivitiesForPerson( personName );

}

<ice:dataTable value="#{activityBean.activityList}" var="activity” >

<ice:column> <ice:outputText value="#{activity.title}"/> </ice:column>

<ice:column> <ice:outputText value="#{activity.body}"/> </ice:column>

</ice:dataTable>

Java

XHTML

Page 41: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

412009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Agenda

IntroductionOpenSocial OverviewOpenSocial Protocols and APIsOpenSocial REST DemoAjax Push for Social ApplicationsAjax PushICEfaces OpenSocial DemoAjax Push Application DevelopmentConclusion

Page 42: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

422009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

Summary

OpenSocial provides standard protocols and APIs forbuilding social networking applicationsSocial Applications can benefit the enterpriseJavaServer Faces is the standard for Java webapplicationsAjax Push makes social applications interactiveICEfaces is the easy way to add Ajax Push

Page 43: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

432009 CommunityOne Conference: EAST | developers.sun.com/events/communityone

For More Information

Social-Enable Your Web Apps with OpenSocial @ 4:00

Adding Ajax Push (Lightning Talk)

Tips and Tricks for Ajax Push and Comet ApplicationsTue @ 3:20

Scaling the Asynchronous Web Tue @ 8:30

Creating Server-Side and Mobile Mashups withOpenSocial's Java Client Libraries: Tue @ 6:00

Page 44: Developing Sleek and Collaborative Applications with OpenSocial and AJAX Push

Developing Sleek andCollaborative Applications withOpenSocial and AJAX Push.S304285

Ted Goddard, Ph.D.Senior Software Architect, ICEsoft

Chris SchalkDeveloper Advocate, Google