miércoles, 7 de agosto de 2013

Install Apache Flex 4.10 Ubuntu 13.04 64 bits

So finally! The guys at Apache Flex has made available an installer for the latest release of the 4.10 Apache Flex SDK version for Linux/Ubuntu. It take some time, but finally an installer for our beloved platform. So let's install it:

First you must have Adobe Air 2.6 installed, here is a great tutorial. Next download the deb file containing the installer here.

Next double click and ... what an error ?

If you have Adobe Air installed you need to check the version to do this just run this command:

dpkg -l adobeair

and you should get something like this:

So, i if my math is still good i suppose that version 1: is greater than 1:, so i just ignore this and use this command to install the package:

sudo dpkg -i --force-depends apache-flex-sdk-installer-2.6.0-bin.deb 

and voilà:

From there just use the handy wizzard, and after some time you will get this.

Congratulations. I hope this short tutorial helps, if you need any extra help just comment and i will be happy to help you.

lunes, 3 de octubre de 2011

Using Embed Jetty and BlazeDS Remoting with Adobe AIR

When we need to communicate with server side data from an Adobe AIR application we usually use HTTP services, Web Services or Remoting this works great, but what happens when we need to create an standalone application? We have options like merapi, flerry and transmission...

I want to show you how to embed Jetty Server in an Adobe Air application and use BlazeDS for communication. The use case is simple access a MySQL server directly from Adobe AIR but with this option you might experiment and create better use cases for this.

We need to download the following:
  • Jetty library (i use jetty-all-7.4.0.RC0.jar)
  • Servlet api (i use servlet-api-2.5.jar)
  • Mysql Connector
  • BlazeDS 4

Let's coding:

First we create a simple table for sample purposes:

Java side:
First we create a simple Java Project and add the 2 jars in the classpath.


Here i use plain JDBC but you can use JPA, Hibernate, etc. 


This is a very important class, here we are going to create the Server instance and start it. 
Note: I assume that you know something about embedding servers, if you want some background here you can find a great resource.


Now we need to extract the BlazeDS.war content. create a folder called webapp inside your src folder with this content, your project structure should look like this.

The last thing you need to do is declare a remote destination on your services-config.xml

Now we code the Air side:
Fist create an asset folder inside your air src folder and copy all the bin folder from your java project

As you can see i made the same copy into the bin-debug folder, i don't know why it doesn't export all the files to the bin-debug.

Now let's code the application, first in the descriptor file enable the extended desktop profile so you can use Native Process

Now  the code:


Now let's take a more closer view to the code:
  • First the executable file will be the Java path so it depends on your machine.
  • I use NativeProcess to start the embed Jetty instance and a socket to shutdown the embed jetty instance.
  • The arguments for the NativeProcessStartupInfo are the necessary classes to make the Java desktop app run. In the application:
  •  Once it connects you can use RemoteObjects to make rpc call to your Java code.
  • You can use messaging too.
Before you run check your ip match with the socket connection ip, and verify the JDBC setting in the Java code.

When you click the start server button, in the text area you see the log comming from the server.

Now click the Get Data button and in my case the screen will be the following:

Stop the server by clicking the Stop Server button.

And that's all, hope this will help you, any question or bug please let me know.
Here is the source code for the Java Project
Here is the Source code for the Flex Project

viernes, 26 de agosto de 2011

Using BlazeDS Remote Object and Java to Upload and get Files

In a Java/Flex project i have been working on we need to upload and download images, simply task no? Yes... is simple we use the FileReference class and point this to a servlet then simply use the upload method.

Really easy when you run in your local machine but what happens when we run this in a remote machine... let me think... ah! yes the lovely Flash Player Sandbox Security Exception... ok! we can handle it, just use crossdomain.xml file and run your application again and... Flash Player Sandbox Security Exception again (dear this is becoming my best friend), then i read, to upload a file Flash player uses the socket api and now we need a socket policy file... so i give up and try to do it in another way.

Today i show you how you can do a kind of  "upload" and "show" a remote file using Remote Objects and the lovely BlazeDS. So let's start

We use a Java class (not servlet) to manage the upload and the get of a file.

In the Java side we have two methods uploadFile and getFile, the first one uses the name, the directory and the content as an byte array to write a file in the disk using the FileOutputStream class. For the second method we need the full file name (directory + file name) and use the FileInputStream to read it and put the data in a byte array and the send it to Flex.


Don't forget to change your remoting-config.xml :-)

And in the flex side we still use the FileReference but this time only for load the file, and then we use remote objects to send the chunk of data, the file name and the directory to the upload method, for getting the file the java side just send the chunk of data and we manage it with a ByteArray and show it.

That's all now you can upload a file using a remote object and show this file with this two methods, and remember to secure your endpoints and externalize your server configuration. Any question or mistakes just let me know. Thanks for reading.