May 19, 2010

How to consume AR System web services with Flex

Note : This post was copied from BMCDN

I can't just give the source because it won't make much sense (that's to not tell it's a horrible mess ...), but here are a few copy/paste that could help :

First, you will need to import these :
import mx.rpc.soap.SOAPHeader;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.LoadEvent;
import mx.rpc.soap.WebService;


I declared these variables :

public var _webServiceFields:WebService; // web service
public var _webServiceFieldsLoaded:Boolean = false; // flag noting when wsdl has been loaded


Then, you initialize your webservices and declare the events and their handlers (if you already know Flex, it's likely to be familiar to you ). FIELD_WS holds the complete URL for the WSDL file. You have to add the header for authentication.

public function FieldsInit():void 
{
_webServiceFields = new WebService();
_webServiceFields.wsdl = FIELDS_WS;
var q1:QName=new QName("http://soapinterop.org/xsd","AuthenticationInfo");
var header1:SOAPHeader = new SOAPHeader(q1, {userName:FIELDS_USER, password:FIELDS_PWD});
_webServiceFields.addHeader(header1);
// add listeners
_webServiceFields.addEventListener(LoadEvent.LOAD, load_listener_fields);
_webServiceFields.addEventListener(ResultEvent.RESULT, result_listener_fields);
_webServiceFields.addEventListener(FaultEvent.FAULT, fault_listener);
// load wsdl
_webServiceFields.loadWSDL();
}


The fault listener is pretty generic :
public function fault_listener(event:FaultEvent):void 
{
debug += event.fault.faultCode + "\n"+ event.fault.faultString + "\n"+ event.fault.faultDetail;texteditor.text = debug;
}


The load listener starts once loadWSDL() is done, and calls the GetField function below.
public function load_listener_fields(event:LoadEvent):void 
{
debug +="WS Loaded ... Retrieving fields\n";
_webServiceFieldsLoaded = true;GetFields();
}


The result listener fires when the result has been received.
public function result_listener_fields(event:ResultEvent):void 
{
var i:int = 0;
while (i < event.target.OpGetList.lastResult.list.length)
{
fields.addItem(event.target.OpGetList.lastResult.list.source[i].chrChamp);
debug += "- " + event.target.OpGetList.lastResult.list.source[i].chrChamp + "\n";
i++;
}
debug +=fields.length + " fields found\n";
DataInit();
}

Finally, this function unleashes the power of your creation :
public function GetFields():void 
{
if (_webServiceFieldsLoaded)
{
// is wsdl is loaded
_webServiceFields.OpGetList(_source_Fieldstag);
}
else
{
FieldsInit();
callLater(GetFields); // wait a frame and try again
}
}


NB : Since then I have used Flex + WS in a production environment, and it's pretty reliable. But as an afterthought, I would have rather made it a datavisualization plugin.

Nov 20, 2008

Tour de Flex

Tour de Flex is a desktop application for exploring Flex capabilities and resources, including the core Flex components, Adobe AIR and data integration, as well as a variety of third-party components, effects, skins, and more.

Tour de Flex has three primary purposes:
  • Provide non-Flex developers with a good overview of what is possible in Flex in a “look and see” environment
  • Provide Flex developers with an illustrated reference tool
  • Provide commercial and non-commercial Flex developers a place to showcase their work



Oct 20, 2008

Still learning Flex - FlexChess

Hey, I have had a good time these days, making this little chess game. I was thinking about making it a client for a real online chess project based on webservices. I'll just keep it in my "possible projects for bored times" case. It's already rather busy in there, but I do the dust from time to time.




The Eclipse project zip is available here. Comments are in french.

While I was looking for some inspiration, Alexandre directed me to this fantastic site. The guys at chesscube made a great 100% Flex chess site. The only thing that is boring me is the lack of design innovation. It just looks too much like another Flex site, and they are overusing this bling-bling reflection fashion for every single image. That's it for the negative part. All the rest is very, clear, easy, fluent, the chess board is extremely readable. That all makes it one of my favourite sites now.

Jul 31, 2008

pureMVC, and Amfphp or webOrb ?

I have been playing around lately with various frameworks, and I have to say pureMVC really got me.
I have also started to test two AMF implementations WebOrb PHP (blog) and Amfphp. Both teams have made terrific jobs and I need to play more with them.
Interesting discussion between the two leaders of both projects here.

Jan 10, 2008

Reading and extracting data from a word file attached to an email

[Description]
A customer receives intervention requests via email and wants to have them pushed as tickets in ITSM v7. These requests come a attached word files with a standard format.

ITSM v7 runs on version 7.0.1 of ARS on Solaris.
The customer won't change the format for a regular ARS-template-shaped email.

[Solution]

1/ Download antiword sources here and compile

Antiword allows us to display the text contained in a word file.
It is maintained as a package in various linux distributions like Debian or Fedora, and even available in Cygwin, but not on Solaris.
It compiled like a charm on Solaris once gcc was installed.

2/ Write a perl/bash+awk/foobar/... script

I did this with perl, overusing conditions and regular expressions to generate a string that looks like this :
field1=value1(separator)field2=value2(separator)field3=value3(separator)...

The field identifier must be unique, and your (separator) must not be found in a value. I used ";" but something more complex like "@X@Y@Z@" or "Wh@t3v3R" for example would be a better choice.

3/ Create an ARS form

This is were attachments will be pushed and analyzed.
You need :
- a long field for the post-treatment string,
- an attachment pool with one attachment field,
- a temporary display only integer field,
- a temporary display only character field [0],
- an AttachmentID character field [40],
- one field per word field

4/ Push attachments to your form

Add a filter to your "AR System Email Attachments" that pushes the document to your form if its name matches whatever its name should match.

5/ Add filters to your ARS form

- the first filter saves the .doc file into your temporary folder and executes your script to get the big string out of it and set it into the long field.
- one filter per field :
* set the location of the first occurence of the researched field name into the temporary integer field (STRSTR)
Tmp_Int = STRSTR($String$, "headerdate=")
* set the substring of the string starting from the fieldname to the end into the temporary character field (SUBSTR)
Tmp_Char = SUBSTR($String$, $Tmp_Int$)
* set the location of the first occurence of your separator into the temporary integer field (STRSTR)
Tmp_Int = STRSTR($Tmp_Char$, "")
* you have the beginning and the end of the value you are searching for, set the substring into the corresponding field of your form (SUBSTR)
headerdate = SUBSTR($Tmp_Char$, + 1 , $Tmp_Int$ - 1)

6/ Push the fields to a new ticket

A last filter must now be able to push the data into the HPD:Interface_Create form.

You can see my perl script here.