Sunday, November 22, 2009

Visit of Devoxx 2009

Usually when I come to JavaPolis/Devoxx I'm always trying to learn about the new technologies and the trends of the year to come. And in order to learn something new I attend an occasional session of topics I've only heard about.

This year I was decided to attend everything I could about JavaFX and the current state of JDK7. And of course to attend the JavaPosse session !!!! :-)

JavaFX

The different sessions were mainly about the language. But some were awesome : Gaming JavaFX on Friday. Using the phys2d library to make explosions, shooting cannon balls and others and see the pieces flying around. In a BOF session we (tried to) program a game.

See the FX Experience Blog for details.

Last but not least : Previews of the RAD and authoring tool. The former is a drag & drop wysiwyg tool to create JavaFX applications with the regular controls (new have been added !). The latter is an impressive tool to create animations. The RAD tool is to be released with Netbeans 6.8. According to the schedule that should be the 10th of December.

The graphics layer will be replaced with PRISM. Faster than anything we know.

JavaFX will hit like a bomb !!! If only they could making it start up faster ...

JDK7 / Java 7

Having followed the debates about the next JDK on the JavaPosse podcast I was very eager to hear about the current state from the original authors. And also to hear whether they've solved the modularization issues that promise to make Java (and thus also JavaFX) smaller and faster. So it can compete with the low installation and startup time of other RIA technologies. If JDK7 doesn't deliver, JavaFX is probably going to remain a second-ranking technology.

There's also the closures debate - will they be implemented or not ?

And what about Coin ? What will they be able to contribute ?

Apparently at Sun they went through the pain of dividing the Java runtime into logical parts with their dependencies and refactor accordingly. The good news is that this is work in progress. The bad news is that the release has been delayed. Which is not so good news for JavaFX either. Without a full modularized JDK, we're still imposing JavaFX users a relatively long download and startup. Whatever cool features and tools we'll have. I hope Sun can do a JDK7 release with only modules for example. Kind of a backported JDK6.

Project Jigsaw is all about dividing the runtime into modules and provide developers with means to create modules on their own. And killing the classpath because it is way too inefficient.

Reinier took the time to write out notes about the Jigsaw session.

As of last week there should be a prototype for Jigsaw, but only functional on Ubuntu. I still have to try this.

See the JDK7 features for details.

TBC...

Monday, November 16, 2009

Devoxx 09 - JSF 2 and beyond

As the program was stating this was for beginners and experienced people I decided to go there and learn about the "fabulous" changes they made to JSF.

Tough luck ! Only slideware (no demo's) and you obviously need a basic level about JSF to understand what they're talking about. Not to mention the way it was brought. Such a shame... I walked right out and did some stuff on the laptop. I guess I'll find a book somewhere.

Devoxx 09 - jbpm 4

This was a very nice presentation. Knowledgeable people and lots of demo's. I would advise anyone who's wanting to learn about jbpm 4 to attend the following sessions.

The graphical design tool plugin certainly looks nice and looks a lot more stable than the last time I looked. Would there be any Netbeans plugin yet for jbpm ? :-)

Tuesday, October 13, 2009

SQE for Netbeans 6.7.1 !

SQE for Netbeans 6.7.1 has been released ! The nmb's can be downloaded at http://kenai.com/projects/sqe/sources/update-center/show.

I've made a zip file of all 57 nbm files which can be downloaded here.

Saturday, June 20, 2009

JavaFX http file upload

I have been fiddling around to find an easy way to upload files with a post http request. This doesn't come out of the box with JavaFX 1.2. With a simple subclass of HttpRequest however this is possible:

Consider the use case of having the user to select one or more files to upload :

// total amount of bytes to upload
var uploadFileSize = 0;

// total amount uploaded bytes
var uploadedBytes = 0;

// a file chooser to select the files to upload
def fc = JFileChooser{};

// the http request object to use for a post
var uploadRequest:HttpRequest;

// the url to post to
def uploadURL = "http://localhost:8080/alexandria/wsrs/document";

// more than one file can be selected
fc.setMultiSelectionEnabled(true);

// the user did select one or more files
if ( fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION ) {

// compute total bytes to upload (approximation)
uploadFileSize = 0;
for ( file in fc.getSelectedFiles() ) {
uploadFileSize += file.length();
}

// kick off the upload
uploadedBytes = 0;
progressDialog.visible = false;

// initiate the upload request to the server
uploadRequest = FileUploadHTTPRequest {
location: uploadURL
files: fc.getSelectedFiles()

onWritten:function(bytes: Long) {
uploadedBytes = bytes;
}

onDone: function() {
println("Upload finished")
}

onResponseCode: function(code:Integer) {
println("onResponseCode - responseCode: {code}")
}

onResponseMessage: function(msg:String) {
println("onResponseMessage - responseMessage: {msg}")
}
}

uploadRequest.start();

}

This is the source code for the upload http request

import javafx.io.http.HttpRequest;
import java.io.File;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import javafx.io.http.HttpHeader;
import javafx.date.DateTime;
import javafx.data.Pair;

/**
* HttpRequest able to upload files to a given url, using Pair objects
* to send fields.
*
* @author jan
*/

def PREFIX = "--";

def NEWLINE = "\r\n";

def BOUNDARY = createBoundary();

def CONTENT_TYPE = "multipart/form-data; boundary={BOUNDARY}";

def NAME = "upfile";

function createBoundary() :String {
def now = DateTime {};
return "{Long.toHexString(now.instant)}";
}


public class FileUploadHTTPRequest extends HttpRequest {

// A sequence of files to upload
public-init var files:File[];

// Fields to upload together with the request
public-init var fields:Pair[];

postinit{

// we always do a post
method = HttpRequest.POST;

// override the onOutput
onOutput = writeFiles;

// add the headers we need
insert HttpHeader {
name:HttpHeader.ACCEPT
value: "*/*"
} into headers;
insert HttpHeader {
name:HttpHeader.CONTENT_TYPE
value: CONTENT_TYPE
} into headers;
insert HttpHeader {
name:HttpHeader.CONNECTION
value: "keep-alive"
} into headers;
insert HttpHeader {
name:HttpHeader.CACHE_CONTROL
value: "no-cache"
} into headers;
insert HttpHeader {
name:HttpHeader.ACCEPT_CHARSET
value: "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
} into headers;
}

function writeFiles( output:OutputStream ) {
try {
// send the files
if ( files != null and sizeof files > 0 ) {
for ( file in files ) {
// leading characters
output.write(PREFIX.getBytes());
output.write(BOUNDARY.getBytes());
output.write(NEWLINE.getBytes());
output.write("Content-Disposition: form-data; name=\"{NAME}\"; filename=\"{file.getName()}\"".getBytes());
output.write(NEWLINE.getBytes());
output.write("Content-Type: application/octet-stream".getBytes());
output.write(NEWLINE.getBytes());
output.write(NEWLINE.getBytes());
// write the file's content
var input = new BufferedInputStream( new FileInputStream( file ) );
IOUtils.copy(input, output);
input.close();
// end of file
output.write(NEWLINE.getBytes());
output.flush();
}
output.write(NEWLINE.getBytes());
}

// write the fields
if ( fields != null and sizeof fields > 0 ) {
for ( field:Pair in fields ) {
output.write(PREFIX.getBytes());
output.write(BOUNDARY.getBytes());
output.write(NEWLINE.getBytes());
// write content header
output.write("Content-Disposition: form-data; name=\"{field.name}\"".getBytes());
output.write(NEWLINE.getBytes());
output.write(NEWLINE.getBytes());
// write content
output.write("{field.value}".getBytes());
output.write(NEWLINE.getBytes());
output.flush();
}
}
output.write(PREFIX.getBytes());
output.write(BOUNDARY.getBytes());
output.write(PREFIX.getBytes());
output.write(NEWLINE.getBytes());

} finally {
output.flush();
output.close();
}
}
}

Sunday, May 3, 2009

Code samples page

A one-hour presentation derailed into a two and half hour workshop. I really thought I could give it in half an hour with another half an hour for the questions and trials. It derailed even when I thought I've cut out the maximum to avoid a long presentation.

I hope at least some people appreciated - they patiently sat down until I was finished. Thanks guys !

As the sample code for the presentation is way too big to send to the audience I hastily opened a web page to put them on. This way anyone who's experimenting with JavaFX can have some code already to play with.

The page can be visited here