Satya Aravind Kopparthi Weblog

06/28/2009

Ride your RIA Vehicle using Google App Engine in a Cloud

Filed under: Google App Engine — akopparthi @ 11:02 am

Know your Engine:

GAE is running Java 6. However, there are  number of limitations that have been imposed to constrain Java to fit the GAE model. GAE Java is based on the Java 2.4 Servlet API:

  • Once a request is sent to the client no further processing can be done. This includes data streaming.
  • A request will be terminated if it has taken around 30 seconds without completing. At this point an exception is thrown. If not caught a 500 error is returned to the user.

Moving up the stack are several sandbox restrictions:

  • Applications can not write to the file system and must use the App Engine datastore instead.
  • Applications may not open sockets
  • Applications can not create their own threads or use related utilities such as timer.

java.lang.System has been restricted as follows:

  • exit(), gc(), runFinalization(), and runFinalizersOnExit() do nothing.
  • JNI access is not allowed.

Choose your RIA Vehicle(FLEX/BLAZEDS/JAVA):

Aravind Kopparthi.


05/23/2009

Flex using BlazeDS with Java. Do you care about security?

Filed under: Flex — akopparthi @ 7:17 pm

1. Secure the primary keys
- Store at least the primary key in Session on the way out from java to flex. When you get the request from flex to java, check to make sure the user has access to the primary key they are trying to change.
2. Secure the foreign keys
-Other classes will probably have your customer.id as a foreign key in their class. Make sure these are secure from tampering as well.
3. Secure your remote methods that flex will be calling
-Use remoting-config.xml to exclude methods that the user should not have access to. One way to this:

  <destination id=”customerService”>
        <properties>
            <source>customerService</source>
        </properties>
  <exclude-methods>
  <method name=”updateCustomer” security-constraint=”admin-users”/>
  </exclude-methods>
</destination>

You can read more about this in the BlazeDS dev guide.
4. Secure any other fields that are sensistive and should not be able to be changed by the end user.

references: flexpasta.com

05/19/2009

Flex AMF DS comparisons

Filed under: Uncategorized — akopparthi @ 7:14 pm

GDS over BlazeDS:

If you are a software provider using Java EE persistent technologies such as Hibernate, you will certainly feel the importance of a framework that takes great care of your lazy fetching strategy. One of the most important features of GDS (and one of the main reasons of its creation) was the possibility to use exact ActionScript3 copies of Hibernate detached objects on the client side, just like if we were in the web layer of a classical Java EE application. This does not seem to be possible at all with BlazeDS, and that means that you cannot just replace GDS with BlazeDS. Additionally, you’ll be able to use Gas3 code generation features which are real time savers.

 

 

 

 

 

Feature BlazeDS GraniteDS WebORB LifeCycleDS
Data management Services
Client-Server synchronization - + + +
Conflict resolution - - + +
Data paging - + + +
SQL adapter - - + +
Hibernate adapter - + + +
Document Services
LiveCycle remoting - - + +
RIA-to-PDF conversion - - +(plugin) +
Enterprise-Class Flex application services
Data access/remoting + + + +
Proxy service + + + +
Automated testing support - - +(through RIA AppPuncher –coming soon) +
Software clustering + + + +
Web tier compiler - + + +
Flex code generation - + + -
Enterprise Integration
WSRP generation - - - +
Ajax data services + - + +
Flex-Ajax bridge + - - +
Runtime configuration + - + +
Open adapter architecture + - - +
JMS adapter + + + +
Server-side component framework integration + + + +
Stateful services (session scope for Java objects) - + + ?
Singleton services (application scope for Java objects) - + + ?
Server-to-client method invocation - - + ?
ColdFusion integration - - + +
Service browser
displaying POJOs,
Spring beans, EJBs and
a list of deployed JAR
files
- - + -
Offline Application Support
Offline data cache - - + +
Local message queuing - - + +
Real – Time Data
Publish and Subscribe messaging + - + +
Real -time data quality of service - + + +
RTMP tunneling - - + +
Frameworks build-in integration
Spring - + + -
EJB3 - + ? -

 

I used the following articles:

http://sujitreddyg.wordpress.com/2008/01/31/blazeds-and-lcds-feature-difference/

 http://www.infoq.com/news/2008/02/granite-data-services

http://www.themidnightcoders.com/weborb/java/product_editions.shtm

http://www.graniteds.org/confluence/display/DOC/1.1.+What+is+Granite+Data+Services


http://www.adobe.com/products/livecycle/dataservices/features.html

03/08/2009

Building Flex Applications using Cairngorm with Maven 2.

Filed under: Flex — akopparthi @ 3:50 pm

There is a lot of documentation already out there for Cairngorm but many of the basic examples on the web (and especially on labs.adobe.com) are now slightly out of date, and use deprecated methods. I expect it can be a little frustrating for someone coming in to Cairngorm for the first time, especially if you have not used anything similar before, so this should be a good next step for you if you have already read the docs, understand the basic concepts and want an aid to help speed up your understanding


Step 1: Download Cairngorm swc component

The first thing to do is download the Cairngorm binary and a Cairngorm example application. I’m currently using FlexBuilder3 beta (Moxie), and so I decided to go with the latest version of Cairngorm which is 2.2. Due to issues with a recent FlexBuilder hotfix I’ve downloaded a beta version called 2.2.1_beta. The best thing to do is look at the Cairngorm wiki on Adobe.labs to ensure you get the correct version for you:

http://opensource.adobe.com/wiki/display/cairngorm/Downloads

Step 2: Install using mvn

mvn install:install-file -DgroupId=com.adobe.flex.framework -DartifactId=cairngorm-framework-Dversion=2.2.1 -Dpackaging=jar -Dfile=c:\cairngorm.swc

Step 3: Reference the installed component in pom

<dependency>
<groupId>  com.adobe.flex.framework </groupId>
<artifactId>cairngorm-framework </artifactId>
<version>2.2.1</version>
<type>swc</type>

</dependency>

Step 4: Download the example

You can view the Diagram Explorer here, view the example app here and download the example app here.

Good luck.

Passing QueryString params to Flex 3 Application

Filed under: Flex — akopparthi @ 3:15 pm

You pass request data to Flex applications by defining the flashVars properties in the wrapper. You can also access URL fragments by using the BrowserManager.

The flashVars properties and URL fragments are read in the Flex application at run time. As a result, changing flashVars properties or URL fragments does not require you to recompile the Flex application.

Passing request data with flashVars properties

You can pass variables to your Flex applications using the flashVars properties in the <object> and <embed> tags in your wrapper. You do this by adding ampersand-separated sets of name-value pairs to these properties.

The following example sets the values of the firstname and lastname in the flashVars properties inside the <object> and <embed> tags in a simple wrapper:

<html>
<head>
<title>/flex2/code/wrapper/SimplestFlashVarTestWrapper.html</title>
<style>
body { margin: 0px;
 overflow:hidden }
</style>
</head>
<body scroll='no'>
<table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr><td valign='top'>

<h1>Simplest FlashVarTest Wrapper</h1>

    <object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' height='100%' width='100%'>
        <param name='src' value='FlashVarTest.swf'/>
        <param name='flashVars' value='firstName=Nick&lastName=Danger'/>
        <embed name='mySwf' src='FlashVarTest.swf' pluginspage='http://www.adobe.com/go/getflashplayer' height='100%' width='100%' flashVars='firstName=Nick&lastName=Danger'/>
    </object>

</td></tr></table>
</body>
</html>

If you are using the wrapper that is generated by the web-tier compiler or Adobe® Flex® Builder™, or one of the wrappers that are included in the /templates directory, your wrapper will probably be very different from the previous example. These wrappers call functions in the AC_OETags.js file to build the <object> and <embed> tag structure in the HTML page. As a result, you pass the flashVars as parameters to the AC_FL_RunContent() function in the wrapper. For a function call that already has a flashVars parameter, you can append your flashVars to the end, as the following example shows:

"FlashVars","MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+'&myName=Danger&myHometown=Los%20Angeles'+"",

If the function parameters do not already include the flashVars variable, then you can insert it in the list, as the following example shows:

AC_FL_RunContent(
    "src", "TestApp",
    "flashVars", "myName=Danger&myHometown=Los%20Angeles",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "TestApp",
    "quality", "high",
    "name", "TestApp",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
);

The value of the flashVars properties do not have to be static. If you use JSP to return the wrapper, for example, you can use any JSP expression for the value of the flashVars properties that can be evaluated to a String.

The following example uses the values stored in the HttpServletRequest object (in this case, you can use form or query string parameters):

<html>
<head>
<title>/flex2/code/wrapper/DynamicFlashVarTestWrapper.jsp</title>
<style>
body { margin: 0px;
 overflow:hidden }
</style>
</head>

<%
    String fName = (String) request.getParameter("firstname");
    String mName = (String) request.getParameter("middlename");
    String lName = (String) request.getParameter("lastname");
%>

<body scroll='no'>
<table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr><td valign='top'>

<script>
<h1>Dynamic FlashVarTest Wrapper</h1>
</script>

    <object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' height='100%' width='100%'>
        <param name='src' value='../assets/FlashVarTest.swf'/>
        <param name='flashVars' value='firstname=<%= fName %>&lastname=<%= lName %>'/>
        <embed name='mySwf' src='../assets/FlashVarTest.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='100%' width='100%' flashVars='firstname=<%= fName %>&lastname=<%= lName %>'/>
    </object>

</td></tr></table>
</body>
</html>

If your user requests the SWF file directly in the browser, without a wrapper, you can access variables on the query string without providing additional code. The following URL passes the name Nick and the hometown San Francisco to the Flex application:

http://localhost:8100/flex/myApp.swf?myName=Nick&myHometown=Jacksonville

About flashVars properties encoding

The values of the flashVars properties must be URL encoded. The format of the string is a set of name-value pairs separated by an ampersand (&). You can escape special and nonprintable characters with a percent symbol (%) followed by a two-digit hexadecimal value. You can represent a single blank space using the plus sign (+).

The encoding for flashVars properties is the same as the page. Internet Explorer provides UTF-16-compliant strings on the Windows platform. Netscape sends a UTF-8-encoded string to Flash Player.

Most browsers support a flashVars String or query string up to 64 KB (65535 bytes) in length. They can include any number of name-value pairs.

Using the src properties to pass request data

You can append the values of properties to the <object> and <embed> tags’ src properties in the wrapper. The src property identifies the location of the Flex application’s SWF file. You access these the same way that you access flashVars properties.

The following example appends query string parameters to the src properties in the custom wrapper:

<object ... >
    <param name='src' value='TitleTest.mxml.swf?myName=Danger'>
    ...
    <embed src='TitleTest.mxml.swf?myName=Danger' ... />
</object>

Variables you define in this manner are accessible in the same way as flashVars properties.

Accessing the flashVars properties

To access the values of the flashVars properties, you use the Application object’s parameters property. This property points to a dynamic object that stores the parameters as name-value pairs. You can access variables on the parameters object by specifying parameters.variable_name.

In your Flex application, you typically assign the values of the run-time properties to local variables. You assign the values of these properties after the application’s creationComplete event is dispatched. Otherwise, the run-time properties might not be available when you try to assign their values to local variables.

The following example defines the myName and myHometown variables and binds them to the text of Label controls in the initVars() method:

<?xml version="1.0"?>
<!-- wrapper/ApplicationParameters.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initVars()">
  <mx:Script><![CDATA[
     // Declare bindable properties in Application scope.
     [Bindable]
     public var myName:String;
     [Bindable]
     public var myHometown:String;

     // Assign values to new properties.
     private function initVars():void {
        myName = Application.application.parameters.myName;
        myHometown = Application.application.parameters.myHometown;
     }
  ]]></mx:Script>

  <mx:VBox>
  <mx:HBox>
     <mx:Label text="Name: "/>
     <mx:Label text="{myName}" fontWeight="bold"/>
  </mx:HBox>
  <mx:HBox>
     <mx:Label text="Hometown: "/>
     <mx:Label text="{myHometown}" fontWeight="bold"/>
  </mx:HBox>
  </mx:VBox>
</mx:Application>

When a user requests this application with the myName and myHometown parameters defined as flashVars properties, Flex displays their values in the Label controls.

To view all the flashVars properties, you can iterate over the parameters object, as the following example shows:

<?xml version="1.0"?>
<!-- wrapper/IterateOverApplicationParameters.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
  <mx:Script><![CDATA[
     private function init():void {
        for (var i:String in Application.application.parameters) {
           ta1.text += i + ":" + Application.application.parameters[i] + "\n";
        }
     }
  ]]></mx:Script>

  <mx:TextArea id="ta1" width="300" height="200"/>

</mx:Application>

Java and Flex moving at the speed of Kepler…

Filed under: Flex — akopparthi @ 2:52 pm

Java-based Compiler API

Flex 3 includes a Java-based compiler API that lets you compile SWF and SWC files from Java applications. The API supports all the same options as the mxmlc and compc command-line tools. The API includes classes like Application, Logger, and Project

more info: http://blogs.adobe.com/flexdoc/oem/oem_guide.pdf

02/25/2009

Java classes to Actionscript3 classes using Maven 2

Filed under: ActionScript, Flex, Maven — akopparthi @ 9:23 pm

At some point I found myself in a situation where I had data objects in Java and in order to use the same objects in Flex application I had to duplicate these classes in Actionscript 3. It was pretty boring and in addition to that, the possibility to forget to add or change some attribute was very high and it happened of course more than once. As I started to look around in web I had very low expectations to find a tool for converting Java classes to Actionscript classes. After some digging I found that actually there is a great tool, which does exactly what I needed.

Franck Wolff had created an Actionscript generator which can be run as an Ant task and you only have to define the source directory where your compiled Java classes are located and the destination directory where you want the generated Actionscript classes to have and that’s it. As I was more used to Maven and couldn’t spend too much time on the topic I decided to use the Maven’s Ant plugin to call the generator from pom.xml (an example how I use it can be seen below).

- compile the Java classes in my web application
- call the Actionscript generator to take the compiled Java classes and generate Actionscript out of them
- call the Flex compiler to compile the Flex application with the generated classes (you can get a more detailed view of this and following points – also here)
- call the maven-flex2-plugin to copy the compiled Flex app to my web application module
- package all together to a war file
- deploy it to Tomcat server
Ok, there was also some other stuff too like generating hibernate mappings and adding functionality to generated Actionscript classes but I’ll try to write about it soon. Great thing was that all of it actually worked and I had the possibility to configure this tool the way I wanted.

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>install</phase>
            <configuration>
                <tasks>
                    <taskdef className="org.granite.generator.ant.As3BeanAntTask" name="gas3" />
                    <gas3 outputdir="../flex/src">
                        <classpath>
                            <pathelement location="target/classes" />
                        </classpath>
                        <fileset dir="target/classes">
                            <include name="ee/quest/model/question/*.class" />
                        </fileset>
                    </gas3>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>1.5.3</version>
            <scope>compile</scope>
        </dependency>
          <dependency>
            <groupId>org.granite</groupId>
            <artifactId>granite-generator</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.granite</groupId>
            <artifactId>gas3</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</plugin>

02/15/2009

JSF Flex Framework

Filed under: Uncategorized — akopparthi @ 9:39 pm

JSF Flex goal is to provide users capability in creating standard Flex components as JSF components {note dynamic charts and some other components are not part of standard Flex components}. So users would create the components as normal JSF components and the project will create the necessary MXML, SWC, SWF files and etcetera and link the values of the components back to the managed beans using JSON+Javascript and Actionscript. {standard Flex components have been open sourced through MPL license}
Components

JSF Flex project contains concrete JSF component for each Flex component.

Each of the JSF component that needs to preserve the value will have the following syntax of values checked during the decode process

_ {i.e. for List _selectedIndex}. For certain components there will be a set of ids sent to the decode process {i.e. RadioButton component has two values checked during the JSF decode process { _selectedValue and _selected }.

JSF Flex project utilizes the myfaces build plugIn which automatically creates :

the concrete class for each abstract class of JSF component
the tag class for each JSF component
the tld file
the facesconfig.xml for the configuration
In order to view how to create such components, please refer to the current components within jsf-flex project.

better support for creating XMLList and its associated data for Facelet using dataBinding + static XML data
possible creation of Array + list of Objects using dataBinding to beans {similar implementation as for XMLList + XML}
Main points for JSF Flex Renderers

Main thing to note in terms of design for the renderers are the following :

Classes which are not concrete, meaning MXML.+TemplateRenderer will mainly have a method called mapFields which is simply to inspect either the replaceMapping XML or annotation {depending on the JRE version} to retrieve the values from the sub-class of UIComponent during the JSF Flex’s encodeBegin lifecycle.
Concrete classes have a method createPreMxml which is to create the preMxml file with the responsibility of creating these files lie with implementations of _FileManipulatorTaskRunner interface {default being VelocityFileManipulatorTaskRunnerImpl }. The implementation choice for this interface and two other interfaces _CommonTaskRunner and _FlexTaskRunner are determined during the maven build process.
MXMLComponentBaseRenderer class during the encodeEnd will write the body content of the component {i.e. MXMLScript} as long as the correct content is pushed to the attribute map. For an example, view the MXMLUIScriptTag within the jsf-flex project where the body content is pushed to the component’s attribute map as MXMLConstants.TAG_BODY_CONTENT_ATTR.
MXMLApplicationRenderer is a special class that has an added responsibility during its encodeEnd to
merge the preMxml files into a MXML file
create SWC file for the system’s library
extract the SWF file from SWC for the shared resource of all application SWF files
flush necessary resources {i.e. componentValueMapper.xml} for the system’s library to the correct directory
extract the flexSDK to the correct directory
create the application’s SWF file.

References
Further details and the source code: http://code.google.com/p/jsf-flex/

02/14/2009

8 essential MySQL queries

Filed under: Uncategorized — akopparthi @ 9:43 pm

Here”s a list of queries that I found myself using very often and that save me a lot of development time. I hope you can benefit from them as well.

1. Create a quick backup

Before testing a new piece of code you suspect might mess up data in one or more tables it”s always a good practice to create a backup. To quickly create a backup copy of a table, use this query:

CREATE TABLE backup SELECT * FROM TABLE original;

The query creates a table backup which is a copy of the original table and includes both structure and content.

2. Create/change/restore a password

Many applications store MD5-crypted passwords in the database. If you want to quickly create a new MD5-ed password, or you have forgotten your password, use the following query to get a new one:

SELECT MD5(”somepasshere”);

This statement will give you “b5bab206cc8002bf7c10d47b24a2d0e6″ which is the encrypted version of the string “somepasshere”. There are other function that crypt stings in MySQL using different algorithms, most notably PASSWORD() which is using MySQL“s own crypting algorithm.

3. Working with Unix timestamps

To convert from human-readable MySQL date/time format into Unix timestamp, use: SELECT UNIX_TIMESTAMP(); Without parameters, this will give you the timestamp of the current date and time. With parameters, you can get timestamp for any date. For example: SELECT UNIX_TIMESTAMP(”2006-12-31″); This statement gives you the timestamp 1167541200. To get a date back from a timestamp, use: SELECT FROM_UNIXTIME(1167541200); This results in “2006-12-31 00:00:00″

4. Quick increment

To increment an integer stored in a table (useful for stats for example), use: UPDATE sometable SET counter=counter+1 WHERE …; Here “counter” is the name of the field that stores the integer value.

5. Toggle a value

If you have a field that stores a Boolean type of value, like 0/1 or yes/no, you can easily toggle the value with one if-statement:

UPDATE sometable SET flag=(IF(flag=”no”,”yes”,”no”));

6. Find/replace

Say you want to update a piece of text if all records in a table field. REPLACE() comes to the rescue:

UPDATE sometable SET field = REPLACE(field, “black”,”white”);

This statement will replace all occurrences of the string “black” with the string “white” in all records of the “field” column. Apart from the string “white” the rest of the text contained in the field will be left as is.

7. Get a random record

If you want to select a random row in your table, you can use the statement:

SELECT * FROM table ORDER BY RAND();

8. Upper/lower case

If you want to modify a value and make it upper or lowercase, use the UPPER or LOWER functions, like this:

SELECT LOWER(”Value”); // gives you “value”

SELECT UPPER(”Value”); // gives you “VALUE”

I hope you learned something new today which will make your everyday life as a developer just a bit easier. Thank you for reading!

02/13/2009

eclipse -ganymede save action

Filed under: Uncategorized — akopparthi @ 7:08 pm

I am absolutely convinced that source code must be formatted according to rules a team agrees on. Therefore I have my Save Actions setup for auto-formatting my code (by the way I just rely on the eclipse built-in rules, I would only adjust the line length to 120) every time it is saved. For those who often need to fix/change unformatted code (code that is not auto formatted at all) are going nuts. Once you start comparing with older revisions you can’t actually tell anymore what exactly you have modified, the auto-formatter has done a damn good job! So now you can set an option that only formats actually modified lines code.

Windows-preferences->java->Editor->Save Actions
Check Perform the selected actions on save
and select format edited lines.

Older Posts »

Blog at WordPress.com.