Archive

Archive for May 15, 2009

How to deploy flex application in Tomcat

May 15, 2009 28 comments

Hi everybody, deploying flex application is not a big deal and it is very very simple using flex builder. Once you have configured your server settings when you created flex project in flex builder then whenever you compile the flex application, it will automatically deploy your flex application in application server and whenever you run your flex application it will run from the tomcat server and not from the actual location of the flex application.

To deploy flex application you must have two servers and they are follows.

  • BlazeDS server
  • Tomcat application server

I dont want to tell much about Tomcat server because you all know that its application server where we used to deploy our flex application so i do want to concentrate on BlazeDS server. BlazeDS is a open source server which provides set of services which allow flex application communicate with server side java classes and it also helps multiple flex clients communicate with each other. It provides pre-configured web application which does most of our task and help us to easily integrate flex application with server side technologies. So whenever flex application request Java class, blazeDS will interpret, redirect to  corresponding java class and return response to the flex application.

Now its time to explain how to deploy flex application. First create a new web application in the webapps directory of tomcat home directory. ie create new folder in the webapps directory of tomcat home directory. Extract blazeDS.war and will get two folder META_INF & WEB-INF,  copy those folders in to your web application.

Open the flex builder and create a new project. In the new project wizard, dont forget to select application server type as J2EE  and click next. In the configure j2ee server wizard, please uncheck the “use default location for lifecycle data services server” check box and in the “root folder” please specify the root location of your web application you have created in the webapps directory of tomcat home directory. similarly specify your web application name in root URL and context root

Eg :  root URL : http://localhost:8080/{web application name}

Context root : /{web application name}

Now click the validate configuration button before that please ensure that whether the tomcat server is running in your machine or not.  If you have followed all the steps i have described above then it will show that the web root and URL are valid, then as usual click finish. Thats it !!!, you have integrated flex application with tomcat. hereafter whenever you compile flex application it will be updated in tomcat server and when you run the application it will run from the tomcat server and definitely not from the actual location of the flex application.

At last i do have a confession that i have tried my best to make you understand how to deploy flex application in tomcat. If you have any doubt or if i go wrong anywhere please drop as your comments, i will try to fix it as soon as possible. Thank you !!!

Save bookmark on delicious using flex

May 15, 2009 Leave a comment

Hi, today i come up with interesting blog which explains about how to invoke api methods from flex application. Before that, i want to tell why do we need to access api methods ?. If you ever need to store or retrieve data from the third party server through any client application then we can make it possible with the help of third party api. If you want to access any third party api, you must be aware of certain things.

They are follows

  1. Which api method you are going to access ?
  2. What is the URL of the api method you need to access ?
  3. What are the parameters the api method expects ?
  4. What kind of data the api method returns ?
  5. What can you do with the returned data ?

If you can answer to the questions above when you try to access then nothing will stop you. Once you have understood what you want to do, what you are going to pass as an input and what it gonna return then you have done more than 50% of the work. the rest of the thing is coding which is very easy if you aware about flex nothing more needs.

Now i am going to add a new bookmark in my delicious account, for that i have to know certain details i have mentioned above. To know those details i have to go developers section in delicious API where you can see the available api methods in delicious and you can know about each api method HTTP URL, parameters need to pass and the data it returns. Check out this below URL and explore the delicious  api methods. http://delicious.com/help/api. now i know which method i need to access ie posts/add and all those stuff i need to know.

Steps to create flex application which adds new post in your delicious account

  • create mxml application in flex builder
  • create httpservice instance and give an ID to the httpservice
  • specify the URL of the httpservice
  • Declare the event handler function for result and fault property of httpservice
  • specify the result format of httpservice
  • pass the parameters of the httpservice via <mx:Request> which is declared inside <mx:HttpService> ie httpservicee instance
  • define event handler functions which you have declared in result and fault property of httpservice
  • Bind the user input data to the request parameters of httpservice.
  • invoke httpservice and it will prompt you to sign in your delicious account if you are not logged in already.

Once you have successfully added new bookmark, it will return xml node ie <result code=”done”/>, else it will return <result code=”something went wrong”/>.

Code


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[

import mx.controls.*;
import mx.rpc.events.*;

[Bindable]public var varUrl : String;
[Bindable]public var desp : String;
[Bindable]public var tagName : String;

public function resultHandler(event :ResultEvent):void
{
Alert.show(event.result.@code);
}

public function faultHandler(event :FaultEvent):void
{
Alert.show(event.fault.message);

}

]]>
</mx:Script>

<mx:HTTPService id="myService" url="https://api.del.icio.us/v1/posts/add?" fault="faultHandler(event)"
resultFormat="e4x" result="resultHandler(event)" showBusyCursor="true" >
<mx:request xmlns="">
<url>{urlInput.text}</url>
<description>{description.text}</description>
<tags>{tags.text}</tags>
</mx:request>
</mx:HTTPService>

<mx:Panel title="Bookmark on delicious" backgroundAlpha="0.2" paddingLeft="20" paddingRight="20" paddingTop="20" paddingBottom="20">
<mx:Form>
<mx:FormItem label="URL">
<mx:TextInput id="urlInput" />
</mx:FormItem>
<mx:FormItem label="Description" >
<mx:TextInput id="description" />
</mx:FormItem>
<mx:FormItem label="Tags">
<mx:TextInput id="tags" />
</mx:FormItem>
<mx:Button label="Save bookmark" click="myService.send()" />
</mx:Form>
</mx:Panel>

</mx:Application>

Follow

Get every new post delivered to your Inbox.