Archive for category Flex

The Flex compiler doesn’t like the Unicode filetype for assets under Perforce

We’re using Perforce as our version control system. In one of our Flex – Java projects, our team recently encountered an unexpected issue with a couple of assets when compiling the Flex application on Windows machines.

A Flex developer working on a Mac commited a new asset in the assets folder and then referenced it in a MXML file. He compiled the application, tested, then committed the new code on the Perforce system. Soon after, our Hudson instance doing continuous integration on the project reported a build failure on the Flex application. The failure message was huge, as it seemed that the Flex compiler was not able to resolve any of the application assets. The error message was basically a list of assets reported as missing. Here’s an excerpt :


...
[java] D:\hudson_home\jobs\project\workspace\project-client\src\assets\stylesheets\common.css(144): Error: Invalid Embed directive in stylesheet - can't resolve source 'Embed(source = "/assets/chrome/BackgroundChrome.png", scaleGridLeft = "5", scaleGridTop = "5", scaleGridRight = "965", scaleGridBottom = "685")'.
[java] scaleGridLeft="5", scaleGridTop="5", scaleGridRight="965", scaleGridBottom="685");
[java] D:\hudson_home\jobs\project\workspace\project-client\src\assets\stylesheets\common.css(150): Error: Invalid Embed directive in stylesheet - can't resolve source 'Embed(source = "/assets/chrome/BackgroundBorderChrome.png", scaleGridLeft = "5", scaleGridTop = "5", scaleGridRight = "965", scaleGridBottom = "685")'.
[java] scaleGridLeft="5", scaleGridTop="5", scaleGridRight="965", scaleGridBottom="685");
...

It seemed like all of the assets were missing. I quickly checked the Perforce system and all of the assets were there. After taking a good look at the failure message, a specific part caught my attention :


Error: exception during transcoding: Failed to grab pixels for image D:\hudson_home\jobs\project\workspace\project-client\src\assets\icons\profil_icon.png

[java] [Embed(source="/assets/icons/profil_icon.png")]
[java] D:\hudson_home\jobs\project\workspace\project-client\src\com\project\user\presentation\view\renderers\UserListItemRenderer.mxml(16): Error: Unable to transcode /assets/icons/profil_icon.png.
[java] [Embed(source="/assets/icons/profil_icon.png")]

So one of the assets, a PNG file, was generating a different exception than the other resources. As I soon found out from this post, if one [Embed] directive is failing then all of the other [Embed] tags are reported as failing as well. So I just had to find out why the PNG resource was failing.

One thing caught my eye : the PNG file was marked in Perforce as of type Unicode, while the other resources were marked as binary, as it should have been. While this was just fine on Mac machines, on Windows machines this lead to the Flex compiler being unable to transcode the image. So what I had to do is simply change the Perforce filetype of that specific PNG file from Unicode to Binary. After doing this, the Flex compiler managed to finish its job properly and the build succeeded.

, ,

No Comments

Migrating to Eclipse Galileo and the Flash Builder 4 plug-in

For some time now, I’ve been using Eclipse with the Flex Builder plug-in to code my Java/Flex projects. Recently I’ve decided to switch from Flex Builder 3 to Flash Builder 4. And since Eclipse Galileo had just been released, I just had to add it to the migration stack and let go of good ol’ Ganymede.

Installing Eclipse Galileo

As usual, installing Eclipse is a breeze. Go to the downloads page, select the package that suits you best, download it, then decompress it. I’ve taken the Java EE package for Mac OS X (Carbon), since it suits best my needs and the platform I’m running on (Mac OS X Leopard 10.5.7).

Installing Flash Builder 4

Download it from the Flash Builder 4 page from Adobe Labs.

Installing Flash Builder 4

Installing Flash Builder 4

Everything went smooth and after the installation was done, I was able to create my first FB4 project :

My first FB4 project

My first FB4 project

Other plug-ins

After FB4, I did install other plug-ins that I use in my daily work : the Perforce plug-in, M2Eclipse, the TestNG plug-in, JBoss Tools, EclEmma, the PMD plug-in, the Checkstyle plug-in and Flex Formatter.

Everything works fine, just as before, and I’m very pleased about it.

Migrating the workspace

The real test for my new IDE stack was migrating the workspaces I use. After everything was in place, I opened my latest workspace with my new Eclipse and it turned out to be OK. I didn’t experience any issues with the Java projects or the plug-ins.

Migrating Flex projects

Everything worked out smoothly, except for the Flex projects. When building the Flex projects from my workspace, I kept running into an error with a message like this :

Attempted to beginRule: R/, does not match outer scope rule: P/my.project

This error would pop up during each project build, so I had to do something about. I did a bit of googling and it turned out that this message is common to multiple issues to Eclipse, most of them who got fixed, so that didn’t help me much. I tried out a couple of workarounds and in the end I managed to fix the problem by deleting the Flex projects from the workspace (but not the project contents) and then using the Import wizard to recreate them :

Import the Flex project as an existing project

Import the Flex project as an existing project

After I did this I didn’t receive any more errors when building the projects. However, I did change the default Flex SDK to be Flex SDK 3.4, instead of 4.0 as Flash Builder defaults to. This was the last configuration I had to do before I could work as smoothly as I did before with the Eclipse Ganymede/Flex Builder 3 stack.

, ,

5 Comments

Meaningful exceptions in LCDS/BlazeDS applications using Spring BlazeDS Integration

In a project I’m currently working on we’re using LiveCycle Data Services to expose Java back-end services to a Flex client application. The back-end is structured in several layers using some flavors of Spring “glue”. You can see below the basic building blocks of the back-end :

Basic architecture

As you can see, the architecture is quite simple. We have a layer of service API which is implemented by another layer, a LCDS-based implementation which, in turn, uses an implementation of a DAO layer. In the diagram, I grayed out the DAO layers because they are of no interest to our current subject.
Briefly, the service API only contains the interfaces of the services along with related objects : exceptions and DTOs.

The service API

We use our custom business exceptions to signal to service clients any issues encountered during service operations. Each custom exception has a public code which indicates its nature and meaning.

Simple exception mechanism

At first, we decided to simply throw business exceptions from the service implementations. This meant that the Flex client application would receive a fault event, which it had to strip to get to the actual exception.
Here is the Java service exception and method :

public class InvalidCriteriaException extends Exception
{
    ...
    public String getCode()
    {
        return ExceptionCode.INVALID_CRITERIA.toString();
    }
}
 
public SearchResultDto searchById(SearchCriteriaDto criteria) throws InvalidCriteriaException
{
    try {
        // do some processing, use the DAO layer
        ...
    }
    catch (SomeDaoException e)
    {
        // convert the DAO exception into a service exception and then throw the new exception
        ...
    }
    catch (Throwable e)
    {
        // any unexpected exception is caught and a new service exception is created and thrown further
        ...
    }
}

And the corresponding Flex code :

    private function handleException(event:FaultEvent) : void {
        var errorMessage:ErrorMessage = event.message as ErrorMessage;
        Alert.show(errorMessage.rootCause.code);
    }

As you can see, the Java service code is cluttered within a try..catch block, which also contains the details on converting possible exceptions to service exceptions. On top of this, the client-side code is not very clean either, because it uses an untyped object ( rootCause ) on which we make assumptions and assumptions are generally a bad thing to do in your code. The right solution on the client-side would be to take advantage of the properties of the ErrorMessage object.

A better exception mechanism

In order to leverage the properties of the Flex class ErrorMessage, we decided to only throw instances of flex.messaging.MessageException, which is shipped in LCDS (and BlazeDS). To do this in an easy way, we proceeded in making sure that each of our custom exception would inherit MessageException :

public class InvalidCriteriaException extends MessageException
{
    ...
}

The service layer would now throw only MessageException-derived exceptions, which get deserialized on the client-side as instances of ErrorMessage. The Java exception has a field called code, who is translated in the Flex class as the field faultCode. So the only thing left to do is make sure that the code field is set to a proper value on the server side.

Using Spring BlazeDS Integration and a custom exception translator

The solution described in the previous paragraph still comes with some flaws. First of all, we didn’t get rid of the try..catch block in the service code. Uh, ugly.
Second, there is a design issue : the service API layer is exposing the service interfaces along with the exceptions, which are now derived from a LCDS exception. This makes the service API layer dependent on LCDS, which is not what we want. The service API should be clean and free of any implementation-specific dependencies.

These flaws were removed once we switched to using the Spring BlazeDS Integration to expose our Spring-based services as LCDS destinations. Along with other great features, Spring BlazeDS Integration comes with the notion of custom exception translators. The translator makes sure that exceptions thrown from the Spring-exposed LCDS destinations are converted to meaningful exceptions for the client, all of this far away from the service code which will be far more simple and clean.

First of all, we create our own exception translator :

public class ExceptionTranslatorImpl implements ExceptionTranslator
{
    public boolean handles(final Class<?> clazz)
    {
        return Boolean.TRUE;
    }
 
    public MessageException translate(final Throwable throwable)
    {
        final MessageException exception = new MessageException();
        exception.setCode(ExceptionCode.SYSTEM.name());
 
        if (throwable != null)
        {
            if (throwable instanceof BaseCustomException)
            {
                exception.setCode(((BaseCustomException) throwable).getCode().name());
            }
 
            exception.setRootCause(throwable);
            exception.setMessage(throwable.getMessage());
        }
 
        return exception;
    }
}

Then we need to register it in the application context :

  	<bean id="allExceptionTranslator" class="com.adobe.myproject.exception.ExceptionTranslatorImpl" />
 
	 <flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml"  >
        <flex:exception-translator ref="allExceptionTranslator"/>
		<flex:message-service/>
		<flex:secured />
	</flex:message-broker>

We can now remove all the exception conversion logic from the service code and let the exception translator handle all of these ugly details for us. Much better, isn’t it ?

, , , , , , , ,

9 Comments

A Flex formatter

I use the Flex Builder plug-in on top of Eclipse for Flex development . When it comes to coding in Flex, I often find myself missing all of those subtle but priceless options that Eclipse’s Java editor has, like the code formatting, code templates, commenting style or the all-mighty “Save Actions” option which automatically performs specific actions whenever you save your code.

I’ve recently started working on a project with an existing codebase, out of which 90% is Flex code. Facing the possibility of applying our team’s coding guidelines to countless lines of Flex code that I would have to modify, I turned to my browser and began a frantic search for something that would help. I came across a small project aiming to provide exactly what I needed : Flex formatting options. The project is called Flex Formatter and it can be found at  http://sourceforge.net/projects/flexformatter/ on good ol’ Sourceforge. It provides a set of formatting options for ActionScript and MXML code which may cover some of the common needs of any Flex developer out there.

To install it, I downloaded the latest version (0.6.7 at the time of this writing) from Sourceforge, in the form of a jar file. I copied the jar in Eclipse’s plugins folder and restarted Eclipse.

After restarting Eclipse, a new item called Flex Formatting appeared in Eclipse’s Preferences window, with options for ActionScript and MXML indenting and code formatting. I found particularly useful the indentation and the text wrapping options. Once I decided on the rules I wanted, I clicked ‘Apply’ to save my changes. Back in Eclipse’s main toolbar, 2 new buttons have appeared : Format Flex code (selected lines) and Indent Flex code (selected lines). The first will apply the rules you have specified on any Flex code selection (including indentation), while the second button will only properly indent the Flex code selection.

Another interesting option of this small tool is the possibility to export the rules to a file and import them later. This can be done from the same Flex Formatting item in Eclipse’s Preferences window. Exporting & importing make it easier for team members to share their coding style options. One team member could create the rules, export them to a file and put the file on a versioning server. The rest of the team could then retrieve the file from the versioning server and import it in Eclipse.

The formatter is far from complete. In its current version (0.6.7), it lacks some options like performing the formatting on save and it could also do with a more fine-grained set of formatting options. However, after just a couple of days of using it, this tool has saved me a lot of time and energy and I think it is definitely worth using it and I would recommend it to any Flex developer. Just try it, it won’t bite. It just flexes.

, , ,

4 Comments

downloadable adobe flash player 8 Buy SoundBooth CS4 adobe photoshop customer service adobe creative suite academic license Buy After Effects CS4 adobe photoshop for mac os torrent adobe illustrator web design library Buy Creative Suite 4 Master Collection copyright adobe photoshop 7 book adobe photoshop cs2 Buy Creative Suite 4 Web Premium adobe indesign cs2 torrent do not want adobe flash player Buy Dreamweaver CS3 adobe after effects cd adobe photoshop will not uninstall Buy Dreamweaver CS4 adobe photoshop elements 1.0 le release adobe photoshop and business cards Buy Adobe Fireworks CS4 adobe photoshop 7.0 serial code adobe flash programming tablet pen usage Buy Flash CS3 Professional adobe photoshop cs3 crack adobe after effects visually book Buy Flash CS4 Professional adobe premiere pro 1.5 crackz flash adobe occasion Buy Illustrator CS4 creating a city adobe after effects adobe premiere pack Buy InDesign CS3 adobe photoshop trial extension adobe premiere elements 2.0 export mov Buy InDesign CS4 adobe photoshop elements 2.0 driver update adobe photoshop style layer effects series Buy Photoshop CS3 Extended xp sp2 adobe flash problem download adobe after effects 6.5 pro Buy Premiere Pro CS4 adobe flash player8