NetBeans e lo sviluppo di applicazioni Java/JavaFX per Facebook. Corrado De Bari corrado.debari@sun.com Sun Microsystems Italia



Similar documents
Lab-S : Build a GlassFish JavaFX Monitoring Application using REST monitoring API

Performance Testing for Ajax Applications

Java SE 6 Update 10. la piattaforma Java per le RIA. Corrado De Bari. Sun Microsystems Italia Spa. Software & Java Ambassador

Rich Internet Applications

Distribution and Integration Technologies

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

MASTERTAG DEVELOPER GUIDE

Getting Started Guide for Developing tibbr Apps

Java Application Developer Certificate Program Competencies

Server based signature service. Overview

Tableau Server Trusted Authentication

Cloud Elements ecommerce Hub Provisioning Guide API Version 2.0 BETA

NetBeans and GlassFish v 2.1 Creating a Healthcare Facility Visual Web Application

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

An evaluation of JavaFX as 2D game creation tool

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Glassfish, JAVA EE, Servlets, JSP, EJB

InsideView Lead Enrich Setup Guide for Marketo

Tutorial: setting up a web application

Drupal CMS for marketing sites

SETTING UP YOUR JAVA DEVELOPER ENVIRONMENT

Facebook apps in Python

JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

Integrating CRM On Demand with the E-Business Suite to Supercharge your Sales Team

Intellicus Single Sign-on

Web Development with R

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

From Delphi to the cloud

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

How To Write An Ria Application

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Integration Overview. Web Services and Single Sign On

Absorb Single Sign-On (SSO) V3.0

JAVA r VOLUME II-ADVANCED FEATURES. e^i v it;

Onset Computer Corporation

Overview of Web Services API

Visual WebGui for ASP.NET Ajax (and other Ajax) Web Developers Learn what makes Visual WebGui not just another Ajax framework

ACCESSING THE PROGRESS OPENEDGE APPSERVER FROM PROGRESS ROLLBASE USING JSDO CODE

An Oracle White Paper June RESTful Web Services for the Oracle Database Cloud - Multitenant Edition

Custom SIS Integration Type Development. Jim Riecken Blackboard Learn Product Development

Open ebay Apps Jumpstart

LiveStreamingCDN Producer User s Guide

Developing Web Views for VMware vcenter Orchestrator

How To Create A Native Ad On A Nast On A Pc Or Mac Or Ipad (For Android) On A Mac Or Mac) On Pc Or Ipa (For Mac Or Pc) On An Android Or Ipam (For Pc Or

Using the VMRC Plug-In: Startup, Invoking Methods, and Shutdown on page 4

Developing Facebook Applications By. M.ALI and Aamir Latif

Cyber Security Challenge Australia 2014

NetIQ Access Manager. Developer Kit 3.2. May 2012

Whitepaper. Rich Internet Applications. Frameworks Evaluation. Document reference: TSL-SES-WP0001 Januar

XML Processing and Web Services. Chapter 17

Amazon Glacier. Developer Guide API Version

JavaFX Session Agenda

Sample HP OO Web Application

Web application Architecture

Cloud Elements! Marketing Hub Provisioning and Usage Guide!

<Insert Picture Here> Java, the language for the future

Integrating Siebel CRM with Microsoft SharePoint Server

Login with Amazon. Getting Started Guide for Websites. Version 1.0

The HTTP Plug-in. Table of contents

IT6503 WEB PROGRAMMING. Unit-I

2.8. Session management

Configuration Guide - OneDesk to SalesForce Connector

Web Services Security: OpenSSO and Access Management for SOA. Sang Shin Java Technology Evangelist Sun Microsystems, Inc. javapassion.

Copyright 2013 Consona Corporation. All rights reserved

5.1 Features Denver CO 80202

Fairsail REST API: Guide for Developers

Web Security (SSL) Tecniche di Sicurezza dei Sistemi 1

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

Working with Indicee Elements

AJAX and JSON Lessons Learned. Jim Riecken, Senior Software Engineer, Blackboard Inc.

MarkLogic Server. Node.js Application Developer s Guide. MarkLogic 8 February, Copyright 2016 MarkLogic Corporation. All rights reserved.

HireDesk API V1.0 Developer s Guide

PHP Language Binding Guide For The Connection Cloud Web Services

CSI 2132 Lab 8. Outline. Web Programming JSP 23/03/2012

OpenLDAP Oracle Enterprise Gateway Integration Guide

Tutorial: Building a Web Application with Struts

WebSphere Business Monitor

Automated Integration Testing & Continuous Integration for webmethods

Visa Checkout September 2015

Sabre Red Apps. Developer Toolkit Overview. October 2014

Rich Web Applications in Server-side Java without Plug-ins or JavaScript

LabVIEW Internet Toolkit User Guide

Dell One Identity Cloud Access Manager How to Develop OpenID Connect Apps

Web Services ( )

Salesforce Console Integration Toolkit Developer's Guide

Contents. 2 Alfresco API Version 1.0

Introduction to XML Applications

Web Services API Developer Guide

TATJA: A Test Automation Tool for Java Applets

Building Java Servlets with Oracle JDeveloper

Oracle Hyperion Financial Management Developer and Customization Guide

Google Web Toolkit (GWT) Architectural Impact on Enterprise Web Application

Research on HTML5 in Web Development

Transcription:

NetBeans e lo sviluppo di applicazioni Java/JavaFX per Facebook

Agenda Goals Architecture Samples step by step References

Why JavaFX for Facebook Facebook as a world wide content manager: Photos and Videos the main assets No manipulation allowed, just a repository RIA apps everywhere

JavaFX vision JavaFX is the Platform for Creating and Delivering Rich Internet Applications Across Multiple Screens JavaFX is Powered by Java

JavaFX architecture JavaFX Applications and Services JavaFX Apps Framework JavaFX Desktop Runtime Desktop Extensions JavaFX Mobile Runtime JavaFX TV Runtime Mobile Extensions TV Extensions JavaFX Common Profile Authoring Tools Developer Tools (IDE Plug ins, RAD, Production Suite) Designer Tools (Authoring, Publishing, Media Encoding) Java Platform (Java Plug in)

Facebook developing model HTTP request HTML/HTTP HTTP request facebook Callback canvas URL FBML or iframe (html/http) Web application HTTP request facebook REST server XML or JSON Glassfish

Sample Architecture

Architecture details

Sequence diagram

First Facebook Web App Get Netbeans 6.8/6.7.1 with Glassfish 2.1/3 Create a FBSaas application Drag: usersgetloggedinuser New Web app application Into index.jsp drag the Facebook usersgetloggedinuser service Add in top JSP: <%! Add under //TODO: String sessionkey; %> sessionkey = FacebookSocialNetworkingServiceAuthenticator.getSessionKey(request, response); out.println("<br>the SaasService returned: " + result.getdataasstring()); out.println("<br>\nthe SaasService session returned: " + sessionkey);

Generated code: org.netbeans.saas.facebook.* <%@ page import="org.netbeans.saas.*, org.netbeans.saas.facebook.*" %> <% Try { String format = null; RestResponse result = FacebookSocialNetworkingService.usersGetLoggedInUser(request, response, format); I f (result1.getdataasobject(facebook.socialnetworkingservice.facebookresponse.usersgetloggedinuserresponse.class) instanceof facebook.socialnetworkingservice.facebookresponse.usersgetloggedinuserresponse) { facebook.socialnetworkingservice.facebookresponse.usersgetloggedinuserresponse result1obj = result1.getdataasobject(facebook.socialnetworkingservice.facebookresponse.usersgetloggedinuserresponse.class); els e if (result1.getdataasobject(facebook.socialnetworkingservice.facebookresponse.errorresponse.class) instanceof facebook.socialnetworkingservice.facebookresponse.errorresponse) { facebook.socialnetworkingservice.facebookresponse.errorresponse result1obj = result1.getdataasobject(facebook.socialnetworkingservice.facebookresponse.errorresponse.class); //TODO - Uncomment the print Statement below to print result. sessionkey=facebooksocialnetworkingserviceauthenticator.getsessionkey(request,response); out.println("<br>the SaasService returned: " + result1.getdataasstring()); out.println("<br>\nthe SaasService session returned: " + sessionkey); catch (Exception ex) { ex.printstacktrace(); %>

Netbeans Saas generated packages org.netbeans.saas RestConnection/RestResponse handler org.netbeans.saas.facebook FacebookSocialNetworkingServiceAuthenticator. sign() service in FacebookSocialNetworkingService: wrapper on REST function used in.jsp with drag&drop

setup application on FB http://www.facebook.com/developers/

setup api_key & secret Update facebooksocialnetworkingserviceauthenticator.properties:

First JavaFX app Create an FBapp as a JavaFX application Set in application properties:

Main.fx (1/2) In main.fx: package fbapp; import javafx.scene.scene; import javafx.scene.text.font; import javafx.scene.text.text; import javafx.stage.stage; import javafx.io.http.httprequest; import javafx.scene.paint.color; var apikey: String; var sessionkey: String; var sessionkeyjnlp: String; sessionkey = {FX.getArgument("sessionkey").toString(); sessionkeyjnlp = {FX.getArgument("sessionkeyjnlp").toString();

Main.fx (2/2) In main.fx: Stage { title: "FacebookClient" width: 500 height: 200 scene: Scene { fill: Color.GREEN content: [ Text { font : Font { size: 15 x: 10, y: 20 content: "SessionID:" ] Text{ content: bind sessionkeyjnlp translatex: 10 translatey: 40 font:font{ size: 15 Text { font : Font { size: 15 x: 10, y: 70 content: bind sessionkey

Setup arguments to pass JavaFX In FBapp.html of FBapp, with a copy&past from Fbapp project Tab: Files File: Fbapp.html:

Setup arguments to pass JavaFX Past in index.jsp of FBSaas, adding a line: <script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script> javafx( { archive: "FBapp.jar", draggable: true, width: 500, height: 200, code: "fbapp.main", name: "FBapp", sessionkey: "<%=sessionkey%>" ); </script>

Setup arguments to pass JavaFX app Past in index.jsp of FBSaas, adding a line: <script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script> javafx( { archive: "FBapp.jar", draggable: true, width: 500, height: 200, code: "fbapp.main", name: "FBapp", sessionkey: "<%=sessionkey%>" ); </script>

Add JavaFX app to FBSaas Build Fbapp and copy Fbapp.jar from

Add JavaFX app to FBSaas to:

Run On FBSaas project, right click to run: Click on Facebook Login

AuthO/AuthN Facebook

Result Page same sessionid available JavaFX applet

Create a Restful wrapper on: package Sign Service org.netbeans.saas.facebook FacebookSocialNetworkingServiceAuthenticator { static String sign(string[][] params) {... This package has been created with drag&drop Facebook services as mentioned before NOTE: Create a singleton RESTful resource class with GET and PUT methods using Java API for RESTful Web Service (JSR-311). This pattern is useful for creating a simple HelloWorld service and wrapper services for invoking WSDL-based web services.

Restful WS skeleton generated package org.fbsaas.fxhelper;... @Path("signer") public class Signer { @Context private UriInfo context; /** Creates a new instance of Signer */ public Signer() { /** * Retrieves representation of an instance of org.fbsaas.fxhelper.signer * @return an instance of java.lang.string */ @GET @Produces("application/xml") public String getxml() { //TODO return proper representation object throw new UnsupportedOperationException(); Substitute...

Implement RESTful service (1/2) package org.fbsaas.fxhelper; import... import org.netbeans.saas.facebook.facebooksocialnetworkingserviceauthenticator; @Path("signer") public class Signer { @Context private UriInfo context; public Signer() { @GET @Produces("application/xml") public String getsign( /*@DefaultValue("")*/ @QueryParam("api_key") String api_key, @QueryParam("session_key") String session_key, @QueryParam("call_id") String call_id, @QueryParam("v") String v, @QueryParam("format") String format, @QueryParam("flid") String flid, @QueryParam("method") String method, @QueryParam("fields") String fields, @QueryParam("uids") String uids) { //TODO return proper representation object

Implement RESTful service (2/2) //TODO return proper representation object String sig = new String("ERROR"); try { String[][] params = null; params = new String[9][2]; params[0][0] = "api_key"; params[0][1] = api_key; params[1][0] = "session_key"; params[1][1] = session_key; params[2][0] = "call_id"; params[2][1] = call_id; params[3][0] = "v"; params[3][1] = v; params[4][0] = "format"; params[4][1] = format; params[5][0] = "flid"; params[5][1] = flid; params[6][0] = "method"; params[6][1] = method; params[7][0] = "fields"; params[7][1] = fields; params[8][0] = "uids"; params[8][1] = uids; sig = new String(FacebookSocialNetworkingServiceAuthenticator.sign(params)); catch (java.io.ioexception e) { sig = new String("ERROR"); String result = new String("<sigs> <sig>" + sig + "</sig> </sigs>"); return result;

Test RESTful Web Services

Call Sign Service from JavaFX package fbapp; import javafx.data.pull.pullparser; import javafx.data.pull.event; public class SigPullParser { public function parse(input: java.io.inputstream ): String { var sig: String; // Parse the input data (Photo Metadata) and construct Photo instance def parser = PullParser { input: input onevent: function(event: Event) { println("event text: {event.text"); if (event.text.length()>30) { sig= event.text; parser.parse(); println("signature got: {sig"); return sig; PullParser class get in input an java.io.inputstream and generate Event parsing the input. Each Event may be intercepted implementing a callback function onevent

Facebook REST interface API The Facebook API REST server http://api.facebook.com/restserver.php API http://wiki.developers.facebook.com/index.php/api

GetFriend() friends.get mandatory fields: api_key call_id sig ( MD5 hash of the current request and your secret key) v version API Return example: <?xml version="1.0" encoding="utf-8"?> <friends_get_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true"> <uid>2327873</uid> <uid>748378</uid> </friends_get_response>

Call a Facebook REST API (1) call_id = String.valueOf(System.currentTimeMillis()); method = "facebook.friends.get"; var requestsign: HttpRequest = HttpRequest { location: "http://localhost:8080/fbsaas/resources/signer?api_key={apikey&session_key={sessionkey &call_id={call_id&v={v&format={format&flid={flid&method={method" method: HttpRequest.GET oninput: function(input: java.io.inputstream) { var parser = SigPullParser{; signature = (parser.parse(input)).tostring(); try { println("bytes of content available: {input.available()"); finally { input.close(); ondone: function() {... requestsign.start(); HttpRequest class enable an http connection to do REST call to signer services implemented before location determine url to call oninput define callback function it will be asyncronously called passing an java.io.inputstream to be parsed A SigPullParser instance of will parse the signature got calling REST service ondone will define callback function to be called on Http stream closed

Call a Facebook REST API (2)... ondone: function() { var requestfriend: HttpRequest = HttpRequest { location: "http://api.facebook.com/restserver.php?api_key={apikey&session_key= {sessionkey&sig={signature&call_id={call_id&v={v&format={format&method={method" method: HttpRequest.GET oninput: function(input: java.io.inputstream) { var parser = UsersPullParser{; friends = parser.parse(input); for (x in friends) {insert x.uid into friendsid; try { println("bytes of content available: {input.available()"); finally { input.close(); ondone : function(){ In ondone callback function it will be getphoto(friendsid); implemented the real Facebook API requestfriend.start(); call, using the signature got by server side implemented before UsersPullParser is another PullParser implementation in which a UserList it will be parsed

GetPhoto() users.getinfo mandatory fields: api_key call_id sig v uids: (array) List of user IDs. This is a comma-separated list of user IDs. fields: (array) List of desired fields in return. This is a commaseparated list of field strings. It will be specified as field pic_square : URL of a square section of the user profile picture, with width 50px and height 50px.

Final result: Face Mosaic

References Call Facebook rest services by netbeans web apps: http://www.netbeans.org/kb/61/websvc/facebook.html JavaFX applet reads arguments from html page http://forums.sun.com/thread.jspa?threadid=5387552 A JavaFX app as Facebook app: http://kaansoral.com/?p=133 Facebook apps setup: http://www.marketing-ninja.com/facebook-app/starting-your-first-facebook-app-demystifying-application-form-field-by-field/