org.springframework.social.facebook.web
Class RealTimeUpdateController

java.lang.Object
  extended by org.springframework.social.facebook.web.RealTimeUpdateController

@Controller
@RequestMapping(value="/realtime/facebook")
public class RealTimeUpdateController
extends Object

A Spring MVC controller that handles callbacks from Facebook's Real-Time Update API. Handles both the initial subscription verification request as well as individual updates: The following requests are handled:

Note that these requests are performed by Facebook and are not typically linked to or otherwise called in a web application.


Constructor Summary
RealTimeUpdateController(Map<String,String> tokens, List<UpdateHandler> updateHandlers, String applicationSecret)
          Constructs a RealTimeUpdateController.
 
Method Summary
 String receiveUpdate(String subscription, String payload, String signature)
          Receives an update from Facebook's real-time API.
 String verifySubscription(String subscription, String challenge, String verifyToken)
          Handles subscription verification callback from Facebook.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RealTimeUpdateController

public RealTimeUpdateController(Map<String,String> tokens,
                                List<UpdateHandler> updateHandlers,
                                String applicationSecret)
Constructs a RealTimeUpdateController.

Parameters:
tokens - A map of subscription names to verification tokens.
updateHandlers - A list of UpdateHandler implementations to handle incoming updates.
Method Detail

verifySubscription

@RequestMapping(value="/{subscription}",
                method=GET,
                params="hub.mode=subscribe")
@ResponseBody
public String verifySubscription(@PathVariable(value="subscription")
                                                                                 String subscription,
                                                                                 @RequestParam(value="hub.challenge")
                                                                                 String challenge,
                                                                                 @RequestParam(value="hub.verify_token")
                                                                                 String verifyToken)
Handles subscription verification callback from Facebook.

Parameters:
subscription - The subscription name.
challenge - A challenge that Facebook expects to be returned.
verifyToken - A verification token that must match with the subscription's token given when the controller was created.
Returns:
The challenge if the verification token matches; blank string otherwise.

receiveUpdate

@RequestMapping(value="/{subscription}",
                method=POST)
@ResponseBody
public String receiveUpdate(@PathVariable(value="subscription")
                                                                       String subscription,
                                                                       @RequestBody
                                                                       String payload,
                                                                       @RequestHeader(value="X-Hub-Signature")
                                                                       String signature)
                     throws Exception
Receives an update from Facebook's real-time API.

Parameters:
subscription - The subscription name.
payload - The request body payload.
signature - The SHA1 signature of the request.
Throws:
Exception