Beruflich Dokumente
Kultur Dokumente
RESTful Web
<Insert Picture Here>
Polygot Application
Deploying JavaFX
<Insert Picture Here>
RESTful Web
REST Overview
• REpresentational State Transfer
– Architectural styles and the design of network base software
architectures – Roy Fielding PhD thesis
• Major components
– Nouns (resources) are identified by URIs
• Eg. http://twitter.com/statuses/public_timeline.json
– Small set of verbs to manipulate the nouns
• Eg. GET
– Representation is how you would like to view the state (data)
• Eg. Twitter example, we requested JSON format
– Use verbs to exchange application state and representation
• Eg. POST a tweet – changing the public timeline
• Key to being mashable
RESTful Exchange Example
Request
GET /music/artists/magnum/recordings HTTP/1.1
Host: media.example.com
Accept: application/xml
http.start();
END_DOCUMENT
Document to Events – JSON
START_DOCUMENT
START_VALUE “user”
START_ELEMENT 0
{
START_VALUE “id”
“user”: {
TEXT “123456”
“id”: “123456”, END_VALUE “id”
“name”: “Tweety Bird”
} START_VALUE “name”
} TEXT “Tweety Bird”
END_VALUE “name”
END_ELEMENT 0
END_VALUE “user”
END_DOCUMENT
Parsing HTTP Request
def parser: PullParser = PullParser {
documentType: PullParser.JSON
onEvent: function(evt: Event) {
…
else if (evt.eventType == PullParser.END_DOCUMENT) {
parser.input.close();
}
} Close stream when done
}
def http = HttpRequest {
location: “http://twitter.com/statuses/public_timeline.json”
method: HttpRequest.GET
onInput: function(inputStream: InputStream): Void {
parser.input = inputStream;
parser.parse();
Callback when input stream is ready
}
}
http.start(); Start then request then start the parsing
RSS and Atom
• Convenience classes to read RSS and Atom
– Exercise: write a RSS parser with HttpRequest and PullParser
• RssTask contains channels with multiple items
• AtomTask contains feeds with multiple entries
• Specify the location and the pool interval
RssTask {
location: “http://....”
internal: 30m
onChannel: function(channel: Channel): Void {
…
onItem: function(item: Item): Void {
…
}.start()
URL Encoder and Decoder
• URLConverter to encode and decode parameters
def params = [
Pair { name: “w”, value: “2502265” },
Pair { name: “u”, value: “c” }
];
var convert = URLConverter { }
var url = “http://weather.yahooapis.com/forecastrss?
{convert.encodeParameters(params)}”;
Polygot Application
JavaFX RIA Architecture
JavaFX Application
JavaFX Runtime
Web Start / Applet
Java Plugin
Browser
Operating System
Knowing Where You Are
• JavaFX design to run in multiple environments
– “For all the screens of your life”
• Application can find out where are they running
• __PROFILE__ pseudo variable provides the following
values
– browser, mobile, desktop
…
// Get JSObject instance
var window = netscape.javascript.JSObject.getWindow(applet);
JavaFX
Main Pass interface as handle
Interface
JavaFX
UI
JavaFX UI Implements Interface
public class DisplayText extends ShowMessage {
var text: String;
Implements the interface
override public function show(): Void {
var stage: Stage = State {
//Initialize you stage Good to have a method
… to control Stage visibility
content: bind text
};
stage.visible = true;
}
override public function displayText(msg: String): Void {
text = msg;
}
Java Application
public class Main implements RunnableFuture
{
Deploying JavaFX
Java Deployment Reloaded
• Really bad experience
• Lots of improvements over the last few years
– JDK 6u10 – improve startup time
– Java Plugin2 – more robust browser plugin
– Deployment toolkit – easier deployment
– Unifying JavaWeb Start and Applet programming model –
liberating the Applet
New Java Plugin
• Live outside of the
browser
– Will not crash the browser
• Applets can run in
separate VM
– Choose the JDK version
JVM
– Configurable on a per in
Browser
Applet basis
– Live beyond the browser
• Unify Applet and the Web Applet Applet
Start deployment
JVM
– Applet runs on Web Start
Applet
JVM
Deployment Toolkit
• A JavaScript library for
– Detecting, downloading and installing JDK
– Query the environment
– Programmatically creates <applet> or equivalent tags
– Launching JavaWeb Start applications
• Works without and JRE installed
• Includes deployJava.js in web page
– Introduces deployJava JavaScript object
– http://java.sun.com/javase/6/docs/technotes/guides/jweb/depl
oyment_advice.html
<script src=”http://java.com/js/deployJava.js”/>
Example – Launch an Applet
<script src=“http://java.com/js/deployJava.js”/>
<script>
function launch() { Applet attributes
deployJava.runApplet({
codebase:'http://www.mycompany.com/java/',
archive:'myapplet.jar', code:'Main.class',
width:400, height:300
}, null, “1.5+”); Minimum JDK version
}
Applet parameters
if (deployJava.versionCheck(“1.5+”)) {
document.writeln('<button onclick=”launch()”>Launch Applet</button>');
} else {
document.writeln('<button
onclick=”javascript:deployJava.installLatestJRE();”>
Install Java</button>');
}
Unifying Applets and WebStart
• Applets can now be describe with JNLP
<applet width="300" height="300"
code="com.mycompany.MyApplet">
<param name="jnlp_href" value="my_applet.jnlp">
</applet>
<jnlp href="my_applet.jnlp" codebase=”http://...”>
<offline-allowed/>
<shortcut><desktop/></shortcut>
<resources>
<j2se version="1.5+" initial-heap-size=”512m” java-vm-args=”-esa” />
<jar href="my_applet.jar" main="true" />
<extension name="ext" href=".../ext.jnlp" />
</resources>
<applet-desc name="My Applet" main-class="com.mycompany.MyApplet">
<param name=”host” value=”myserver.com”/>
</applet-desc>
</jnlp>
Applet in JavaWeb Start
• Applet runs in a sandbox
– Cannot read/write to filesystem, print, etc
– Needs to be signed for security
• Plugin2 allows applet to access JNLP API
– Do not need to sign, yet secure
– User retains control
• Or use NetBeans
<Insert Picture Here>
Conclusion
Summary
• JavaFX provides simple and easy to use APIs to
access and parse REST resources
• Tight integration with the Java platform and the
browser
– LiveConnect provides AJAX like functionality
– JavaWeb Start API provides secure access to the platform
• Deployment toolkit Java Plugin2 enhances user's
experience
We encourage you to use the newly minted corporate tagline
“Software. Hardware. Complete.” at the end of all your presentations.
This message should replace any reference to our previous corporate
tagline “Oracle Is the Information Company.”
For More Information
search.oracle.com
or
oracle.com
Alternate Title with Subhead
Arial Size 18 (Gray)
• First-level bullet
– Second-level bullet
• Third-level bullet
– Fourth-level bullet
• Fifth-level bullet
Deploying with JavaWeb Start
• Default deployment mode for JavaWeb Start
– Automatically generated with NetBeans
• Set your Java main instead of JavaFX main
• That's it!
• Might have to customize JNLP if you have library
dependencies
Polygot Programming
• Multiple programming languages
– Already happening with JavaEE on different layers
– Everything is now in a single VM
– Leverage the strength of a particular language
• JavaFX + Groovy
• Libraries and components from multiple sources
– Java, Groovy, Scala, JavaFX, etc
• Integration at the JVM level
– Class files and bytecode