Flex – Rules of Thumb

When you’re building JEE Applications, you always need to apply to a given set of rules, best practices.

When you need to take a decision in which technology to use to build your new application with, you need to be able to deliver each rule of tumb with this technology.

Rules of thumb that need to tackled:
- Isolation
- Simplicity of UI and Model
- Clear separation of concerns
- Responsive & intuitive User Interface

Delivering Rules of Thumb using FDMS

The rules of thumb mentioned for Adobe Flex Integration, can be delivered using Flex Data Management Services.

1. Isolation :

Isolate handling of state, presentation, action and communication

State:

  • Assembler Class holds all necessary information regarding state-handling
  • Pull-mechanism of Data Services assures all clients have up-to-date information

Presentation:

  • Java DTO (Data Transfer Objects) are automatically mapped to Action Script DTO’s

Action:

  • Actions are immediately called on the Assembler Class that holds all needed business logic and CRUD-methods

Communication:

  • Communication between client and server are handled on server-side using the Assembler Class

2. Simplicity of UI and Data Model:

Keep UI and data model code as simple as possible

  • The User Interface only defines the lay-out of the different objects and data management is performed by the Data Services
  • Data Model is provided using Web Service Stubs created on the deployed Bpel Processes and Data Transfer Objects

We still need to manually create an Action Script DTO object for each POJO we’re using in our Web Services.

3. Clear separation of concerns:

Decouple and make programming tasks parallel so they can be carried out by different people

  • Assembler Class will be defined for each designated web service stub
  • Data Transfer Objects will be defined in ActionScript for each used object-definition in the Assembler-class

4. Responsive & intuitive User Interface:

Provide a very responsive user experience with clear feedback and zero latency

  • Provided using Data Services Management using push-mechanism
  • Use managed DTO-components so each event is known to the Data Services
  • Use validation-framework for client-side validation
  • Use conflict resolution API for exception handling

Tips & Tricks that’ll save you a lot of time regarding ODI, Flex, Soa Suite

Latelly I’ve been spending a lot of time regarding deployment and configuration of Adobe Flex applications integrated with Bpel on an OC4J-container.

On the other hand I’ve been experimenting a lot with ODI and how the tool will handle changing data models, changing datasources, …

Lastly I’ve been playing around with invocation of Bpel Processes using Web Service Proxy Clients instead of the Bpel Invocation API.

The question that’s still unanswered because no documentation or benchmarks or best practices are available yet is: ‘What’s the best practice in invoking bpel processes, the Bpel Invocation API or Web Service Proxy Clients?’

Tips & Tricks ODI:

  • Interesting Notes: 423740.1, 423817.1
  • Grant dba-privileges to your source-db-user, otherwise you’ll get ‘insufficient privileges’ exceptions when trying to execute your interfaces

Handling changing data models (new tables, deletion of existing attributes in tables, addition of new attributes, additional relationships, … ) :

  • Go to your datamodel and reverse engineer the changed tables again. New attributes are added, deleted attributes aren’t removed yet because they’re referenced in interfaces in your ODI Designer.
  • Go to your interfaces defined in the Designer-tab in ODI: remove all active mappings to the attributes that were deleted
  • Go back to the model-tab in designer and right-click the attribute in your tabel and choose delete. When all references are updated correctly (no active mapping), the attribute will be deleted from your datamodel

Tips & Tricks Flex:

  • When you’re getting weard errors regarding ‘conversion exception between java.util.Date and java.util.Calendar’ or exceptions regarding producer or consumer-errors => make sure you’ve defined ‘autocommit’-property to false on your data services (Using LCDS)
  • How to handle static data without usage of Value Object or Data Transfer Objects => use SQLAssembler without usage of java-classes or actionscript-classes in your data-management-config.
  • rtmp-host connection failure on OC4J => try to reset the connection-port to another value than the default one which is ‘2038’. I’ve defined the value to ‘2035’ and now no errors are thrown anymore
  • Use [managed] attribute to make sure all changes on objects are synced between 2 clients
  • Deploying data-management-config to different JEE Servers, e.g. Tomcat and OC4J. When you deploy to tomcat you have to define the full JNDI-location which would be for example: java:/comp/env/jdbc/flexDS. When you deploy to an OC4J, you need to define the short JNDI-descriptor: jdbc/flexDS.

The other exceptions, weard behaviour was already addressed in earlier posts:

  • You need to add an xsl-choose-when-otherwise xsl-node structure to you transform-activity in your bpel-process and in the otherwise-tag define the xsi:nil=true on your attribute to make sure the web service proxy won’t set this attribute to required.
  • You need to update the toplink-mapping file being generated in bpel when using the database adapter. Relationships aren’t defined properly, because the method accessor is checked for all one-to-many relationships whilst these aren’t defined in the java wrapper classes. Uncheck these ‘map to method accessors’ and these exceptions will disappear. You can uncheck these when drilling down in your toplink.mwp file into to your object on your mappedCollections.

A beautiful one were all newbees in SOA Suite spend ages and ages to figure out what the problem is … Oracle please fix this ???

You’ve installed SOA Suite (you can choose which version) and entered a custom password during installation for your oc4jadmin-password, not the ‘welcome1′ password. You can choose your own password wright ?

But when the newbee starts creating his first bpel and esb projects, there are weard errors poping up: ‘connection timed out’, ‘jndi-location for db-adapter isn’t properly defined’, …

Well, weard but true, the ‘welcome1′ password is defined hardcoded in different ‘oc4j-ra.xml’ files used in the jmsadapter-folder, dbadapter-folder, … Make sure to change the passwords correctly when you’re drilling through the different Oracle By Example-exercices or tutorials.

Flex and ApEx: exchanging data

Following my post Flex and Oracle, I wanted to investigate how difficult it would be to exchange data between flex and ApEx. After some trial and error I’m pleased to say that it isn’t that hard to exchange data between both technologies.

I started by looking for a way to get a simple string from a flex application to an ApEx application. I came across the ActionScript API “ExternalInterface“. The Adobe documentation for the api:


The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container or a desktop application with Flash Player embedded.

ExternalInterface has a method “call” where you can specify the name of the external function you want to call, the second parameters are the parameters you want to pass to that function.

In your html page make a function called “setDept” with the necessary parameters and let the fill the Apex Items. Make a clickhandler in your flex application and call your function, you will see that it works perfect.

Now we have send data from flex to ApEx, it’s time to send something back from ApEx to flex. To start we need to be sure we have a JavaScript function that allows us to speak with the swf file. After some searching, trial and error, I came across the next function that works in both Mozilla and IE:

Now we need to create a javascript function that will pass a String to our flex application using the thisMovie function. Once this is done the only thing we need to create an ActionScript function that can registers an ActionScript method as callable from the container. We can use the method “callBack” from the “ExternalInterface” class for this.
Your Actionscript could look something like this:

Test the JavaScript function on your html page and you will see that you send data from your ApEx application to your flex application.

<!–You can find a working example here.–>

Integrating Flex and Data Management Services with a Bpel process – What about Typed Collections?

As you can remember we’re working out a flex application using Data Management Services and Flex for the client-side and Bpel at server side.

During development I ran into a blocking issue regarding using typed collections in my ActionScript objects.

Why would I use Typed Arguments, Typed Collections or Typed Arrays ?
My bpel process is using a Global Business Object (GBO), an XML Schema Definition, that defines the entire structure of the business objects I will need in the dossier management lifecycle. The bpel process will be cut pu into different sub processes which will define the needed process lifecycle for the dossier management system we’re building.

Of course this kind of business functionality will be handling master-detail data, e.g. a dossier has dossier_members and dossier_members have address_information.

If we create a web service proxy client for our bpel process, the different objects used in this process will be defined as Java Objects. The hierarchical structure of the dossier-element or – object will be defined in the following manner:

public class Dossier implements java.io.Serializable {
protected int id;
protected be.ws.proxy.types.DossierMembersCollection dosMembersCollection;

public class DossierMembersCollection implements java.io.Serializable
{
protected be.kg.ws.proxy.types.DossierMembers[] dossierMember;

The ActionScript Objects I defined for these server side objects :

[Managed]
[RemoteClass(alias="be.kg.ws.proxy.types.Dossier")]
public
class Dossier
{
public var id:int;
public var dosMembersCollection:DossierMembersCollection;

[Managed]
[RemoteClass(alias="be.kg.ws.proxy.types.DossierMembersCollection")]
public class DossierMembersCollection
{
public var dossierMembers:ArrayCollection;
}

The exception I run into :

ArgumentError: Error #2004: One of the parameters is invalid. at
flash.net::NetConnection/flash.net:NetConnection::invokeWithArgsArray()

What does this mean?
In order for this to work, you need to serialize, you’d need to override both the readExternal and writeExternal methods on both the client and server to take of the serialization of the typed collections yourself.

Practical Approach:

  • Implement the Externalizable Interface at Client- and Server-side
  • Overwrite the readExternal()- and writeExternal()-method in both your client and server classes which match (i.e. the read methods exactly match the write methods on both client and server). You need to serialize your fields as well as the source field of the ArrayCollection (it is an Array).

Take care of serialization and deserialization at server-side, use Externalizable Interface:

public class DossierMembersCollection implements java.io.Serializable ,
Externalizable { protected be.kg.ws.proxy.types.DossierMembers[] dossierMembers;

public DossierMembersCollection() { }

/*** Deserializes the client state of an instance of dossierMembers. */ public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
System.out.println(“Receiving array ———————–“);
Object[] obj2 = (Object[]) in.readObject();
System.out.println(“Read input array obj2 ———————–“);

if (obj2 != null) {
DossierMembers[] dossierMembers = new DossierMembers[obj2.length];
System.out.println(“Initialized dossierMembers———————–“);
loop over the object array and cast the Object-classes to your custom class.
System.out.println(“Looping over array ———————–“); dossierMembers[i] = (DossierMembers) obj2[i];

System.out.println(“DossierMembers: ” + dossierMembers[i].toString());
}}

System.out.println(“Receiving array DONE ————————“); }

/*** Serializes the server state of an instance of dossierMembers. */

public void writeExternal(ObjectOutput out) throws IOException { out.writeObject(dossierMembers); }

Take care of serialization and deserialization at client-side:

[Managed]

[RemoteClass alias="be.kg.ws.proxy.types.DossierMembersCollection")]

public class DossierMembersCollection implements IExternalizable {

public var dossierMembers:ArrayCollection;

public function readExternal(input:IDataInput):void {
trace(“***********Reading dossierMembers”);
var array:Array = input.readObject() as Array;
if (array!=null) {
trace(“****Array received”);
dossierMembers = new ArrayCollection();
Loop over the array and add the arrayElements as typed objects to your collection in the following way:

dossierMembers.addItem(array.pop() as DossierMembers);

trace(“**Number of dossierMembers : ” + dossierMembers.length); }

public function writeExternal(output:IDataOutput):void {

trace(“Write ArrayCollection dossierMembers to array”);

var array:Array = new Array();

loop over object-array and add array-items to the collection: {

array.push(dossierMembers.getItemAt(i));

trace(dossierMembers.getItemAt(i).toString()); }

output.writeObject(array); trace(“Done”); } }

If you get random errors there will propbably be a mismatch between server- and client-side objects. The two approaches you can use are: print statements or stopping in your read/write external methods in the debugger. Step through actionscript classes and Java classes using Flex Debugging mode, so you can ensure that you are reading exactly what you are writing.

Hopefully this will help a lot of people facing the same issues regarding typed objects in an Adobe Flex Environment.

FLEX SQLAssembler

Recently I have been working with Adobe Flex and Adobe LiveCycle Data Services for building a dossier-management system.

I came around some strange behavior which I couldn’t understand regarding displaying referential/static data in a flex user interface.

The requirement I need to implement in my flex application is to display static, referential data in the different forms being filled in by the user.

This data needs to be looked-up and displayed in for example dropdown-lists and can be adjusted by administrator, so no CRUD-operations are needed in the entry-module of the application.

What I wanted to do is fill some ArrayCollections with data stored in an Oracle 10G database. I don’t want to convert my data to actionscript or java objects, no transfer objects or value objects because I just want to display them so I won’t use any adapters. I made a new destination in my data-management-config and added a fill:

<fill>
<name>dossier_types</name>
<sql>SELECT cd as “cd”,
omschrijving as “omschrijving”
FROM dossier_types</sql>
</fill>

You might notice that I used an alias in my query, initially I didn’t know this but without the alias I can’t display any data. For me this seemed the right solution to retrieve my data but when I tried it I didn’t retrieve anything. I couldn’t see the data in the console of my tomcat server either; my ArrayCollection always had length 0.

Not sure for what reason but I put in a JavaAdapter :

<adapter ref=”java-dao” />

Referencing to:

<adapter-definition id=”java-dao”
class=”flex.data.adapters.JavaAdapter” />

Out of the blue the ArrayCollection was populated with the wright data. Note that I did not specify any java class in my destination. I also tried to use the actionscript adapter but then I couldn’t receive any data.

I’m not sure this is the behavior I must expect but for now it works and I don’t need to define any transfer-objects in the form of actionscript or java objects, which is what I wanted to accomplish.

Flex and Oracle

Recently we have been working with Adobe Flex and Live Cycle Data Services, part from some little bugs the products seems great. The only thing that stops me from using more Flex is the fact that you need to have a license to use Adobe Live Cycle Data Services and not all customers are interested to make this investment.

So I was looking for a solution and came across this nice example of Mike Potter. He demonstrates how you can use flex with php in order to update a mySQL Database. This should also be possible in Oracle I thought, using mod pl/Sql. Let’s give it a try:


The first thing I wanted to accomplish was to display data from an Oracle database into my flex application. I will use xml to retrieve and display my data.

I started by making a new flex project with a custom component were I implemented a simple datagrid where I would display my retrieved data.

The next thing to do was to let Oracle display some xml so I could retrieve this back into my flex application. I will do this a simple as possible and just use the htp.p function in order to display some static xml:

I then called my procedure in my browser and checked of the xml is correctly generated:

This seemed correct, now I had to retrieve this data into my flex application. I will use the HTTPService tag in mxml to do this. As url property I gave the same location I typed in my browser to check the xml. Now complete your HTTPService with the right resulthandler, I used an Arraycollection to store my data and specified it as dataprovider in my datagrid. The result was what I hoped for:

This is the most simple example of course, but now I’m launched for some further research.

Eclipse & Jdeveloper Join Forces – My Bpel-enabled Flex Application

For one of my projects I need to be able to work out a RIA using Flex as the front-end, integrated with bpel processes as the back-end.

To be able to integrate these bpel processes with my flex user interface, I’ve created web service proxy clients in Jdeveloper.

These web service proxy clients can be invoked by flex using RPC or Livecycle Data Services, we’ve chosen for the last, LCDS.

After defining the architectural blue-print, I’m able to start implementing the first bpel process. In this post I will guide you through the different issues I’ve stumbled into during the development-track!

1. Installation-tips/-problems regarding Middletier with integrated BPEL :

  • Tip: Make sure that the version of the Application Server and Bpel Process Manager match the version of your JDeveloper IDE. In my case I’m working with the patched IAS Version 10.1.3.3 and Jdeveloper 10.1.3.3
  • Tip: When you’re installing an OracleAS Middle Tier you need to make sure you check ‘Configure this as an Administration OC4J instance’ when you want use Enterprise Manager. This is made optional because you can work in a clustered environment, lets say your production environment, where only 1 oc4j-instance needs to server as the Administration environment
  • Problem/Solution: When installing patch 10.1.3.3 on your existing Oracle Application Server you run into an exception when trying to overwrite Apache.exe => this probably means a Virus Scanner is running on your operating system which is preventing Unversial Installer of updating the file.

2. Problem/Solution Development-track, JDeveloper 10.1.3.3 IDE:

  • Problem, ‘Cannot edit WebService proxy after Webservice endpoint url has changed': I’ve defined my bpel process and web service proxy, but my middletier’s hostname has changed which means the bpel processes’ endpoint changed as well. I’ve manually updated the _Stub.java file, generated for the webservice proxy, and changed the endpoint url to the new hostname. If I try to edit the webservice proxy now, by choosing ‘Edit Handlers and Custom Mappings’, I get a message ‘Could Not Invoke Wizard’. The message points out that the old webservice endpoint is still used somewhere/somehow. I couldn’t find a reference to the old endpoint anywhere in the generated java-files. After some digging I finally found the cause, the webservice_proxy.proxy file. You need to change this file to be able to use the wizard again.
  • Problem/Solution: I’ve defined an XSD-file with default-attributes for my bpel process, this xsd file is validated and my bpel process is succesfully deployed BUT … If I try to create a web service proxy for this bpel process I’m getting a nullPointerException. This exception is actually true because I’ve defined the default-attribute for an xs:element with a ref-attribute, in other words, this xs:element refers to an existing defined xs:element. Solution: Define the ‘default’-attribute on the xs:element definition, using the name- and type-attribute and not the xs-element used to define your complex-type.

3. Problem/Solution Development-track, Eclipse IDE & Flex Plug-in :

  • Problem/Solution: Exception is thrown when you run your flex application ‘illegal override of rtmpChannel’. This error can be due to incompatible project files and eclipse jar-files, as in my case I imported an already existing projet in my new eclipse environment. To solve this issue I’ve created a new flex dataservices project and copied all the jar-files in the web-inf/lib folder into the imported project
  • Problem/Solution: ‘Selected wizard could not be started , Plug-in was unable to instantiate class'; this error occurs when you try to create a flex component. The solution in my case was to recreate my development environment, in other words install eclipse, flex plug-in, lcds again.
  • Problem/Solution: ‘Unable to access UserTransaction in DataService’, this errors occurs when you try to invoke the dataservice you’ve configured in your flex application using lcds. This probably means you need to configure JOTM in your tomcat server, or appliction server environment. Check out: http://kb.adobe.com/selfservice/viewContent.do?externalId=6b82874f&sliceId=2

I will keep you posted!