Search This Blog

Tuesday, May 1, 2012

Increasing user expectations


Users are getting increasingly more demanding about the services and functionality that (online) organizations have to offer. This is especially true for organizations where users arrange most or all of their services online. Some examples are Internet banking, online insurance and travel agencies.

Users expect this functionality:

  • To be easy to use
  • That new features are added continuously and provide real value
  • Will work on their mobile devices like phones and tablets
  • Is tailored to their personal needs

This functionality is most of the time designed within the company itself and eventually, when developed and tested, deployed in production. In this model, the company expects that the functionality will meet the needs of most or all users. I believe this model is not sufficient anymore in the ever-increasing expectations of those users.

One of the models to cope with this is to let users/developers themselves build the functionality they need. We also see a lot of this on the Internet where users build their own application/gadgets by using provided API’s. A prime example of this is of course Facebook.

What if we extend this model to the enterprise? What if, for example, Internet Banking companies expose (some) of their functionality through API’s and let users develop functionality they really need? What kind of applications would arise out of this?

I do not think this is a question of how but when. As some or most of you already know, Google owns a banking license. What does it mean for regular banks if Google or perhaps Facebook adopts such kind of platform for banking and/or insurance products? I think a whole new generation of users will make the transition to those companies. This indeed may have a large impact on the customer base of traditional organizations.

Before organizations are ready to make such transitions, a large number of questions must be addressed:

  • How do we secure access to API’s and data?
  • Which data do we want to expose?
  • Why would developers want to build applications for us? How do we compensate developers who are building great applications for us?
  • What about legal issues?
  • What technology do we use?
  • How do we change the mindset of our own people?
  • Etc.

And the most important question: when are organizations ready to adopt this model and radically change the way applications are delivered to end-users? Of course this change does not have to be a big bang but can and should be made incrementally.

From a technology point of view, one of the ways to implement such eco-system is by adopting the Open Social specification. The Open Social specification defines:

  • A social data model, which provides a standard representation of people their relationships and activities also known as a connected graph of people.
  • A set of standard API’s to access people, their relationships and activities available in REST and JavaScript API’s. Besides the JavaScript API for web applications, the REST API is particular interesting as enabler of mobile applications.
  • A standard to develop gadgets that encapsulate reusable application logic.

As an example, iGoogle is one of the platforms based on Open Social (in fact, Google donated their iGadgets container to the community which is Apache Shindig). IBM and Atlassian are also incorporating Open Social technology in their own products.

Conclusion


Since users become more and more demanding about the services and functionality that (online) organizations offer, organizations need to find other ways to provide that functionality instead of the traditional specification-build-deploy cycle. A possible way to do this is to let users themselves build the functionality they need. Open Social could be the technological enabler to facilitate this.

However, the ultimate question remains: if and when are organizations ready to adopt a radical new strategy to provide functionality to its end-users.

What is your opinion about this?

Tuesday, April 10, 2012

Flex: unittest a view with radio buttons

At a recent project where I do some coaching, we wanted to unit test the validation logic present in view components. The validation logic is implemented as an array of validators which are triggered after some specific events take place. To test this we basically did the following:

  1. Created a unit test (we are using FlexUnit)
  2. Instantiate and initialize the view in the unit test
  3. Populate the UI components with values to test
  4. Trigger the validators
All seems well until we wanted to populate the selectedValue property of a RadioButtonGroup. This did not seem to work from within our unit tests. According to the documentation the selectedValue property can both be set and read from within code. Testing this logic inside a standalone MXML component and setting the selectedValue property did work. Unfortunately this did not help in our unit test because there it did not work.

Looking at the source code of the RadioButtonGroup I noticed that when setting the selectedValue property, the code loops over the associated RadioButtons. In our unit test the associated RadioButtons are not set (I expected that they were set actually). After digging some further I noticed the addInstance(instance:RadioButton):void method. This method apparently adds a RadioButton to the RadioButtonGroup. But where is it called? Somewhere by the Flex framework but where exactly was not obvious. Notice that this method is declared in the mx_internal namespace which means that this functionally may change in a future release. It also means however that we can still call this code ourselves.

To fix our test, the mx_internal namespace is added so the addInstance method can be called from within the test. With the addInstance method all RadioButtons which belong to the RadioButtonGroup can be added to the group. See the example below.

   1:  <?xml version="1.0"?>
   2:  <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
   3:      <mx:RadioButtonGroup id="genderRadioButtonGroup"/>
   4:   
   5:      <mx:RadioButton id="male" groupName="genderRadioButtonGroup" label="male"></mx:RadioButton>
   6:      <mx:RadioButton id="female" groupName="genderRadioButtonGroup" label="female"></mx:RadioButton>
   7:  </mx:VBox>

And the code of the unit test:
   1:  package {
   2:  import flexunit.framework.TestCase;
   3:   
   4:  import mx.core.mx_internal;
   5:   
   6:  use namespace mx_internal;
   7:   
   8:  public class RadioButtonTest extends TestCase {
   9:      public function RadioButtonTest() {
  10:      }
  11:   
  12:      public function testPopulateRadioButton():void {
  13:   
  14:          var myForm:MyForm = new MyForm();
  15:          // Initialize the UI component so that all child components are added to the form.
  16:          myForm.initialize();
  17:   
  18:          // Explicitly add the radiobuttons to the group, please note the use namespace mx_internal or else this
  19:          // method can not be called.
  20:          myForm.genderRadioButtonGroup.addInstance(myForm.male);
  21:          myForm.genderRadioButtonGroup.addInstance(myForm.female);
  22:   
  23:          myForm.genderRadioButtonGroup.selectedValue = "male";
  24:   
  25:          assertEquals("male", myForm.genderRadioButtonGroup.selectedValue);
  26:      }
  27:  }
  28:  }

Conclusion
Using the mx_internal namespace is not encouraged but sometimes can help to work around certain limitations, especially in test code. In the case of the RadioButtonGroup I would assumed things worked differently but unfortunately they did not. I doubt that this will be fixed in a future release regarding the state of Flex at the moment.

If you have another solution to the above problem please share it!

Thursday, March 29, 2012

Continuously looping video in WPF

At the moment I am building a Kinect based application using the Windows Presentation Foundation framework for a client. More details on this application later.

In that application we needed to show a continuously looping video. After looking through some documentation I used the following XAML construct to play and loop the video continuously:

   1:  <MediaElement LoadedBehavior="Play">
   2:      <MediaElement.Triggers>
   3:          <EventTrigger RoutedEvent="MediaElement.Loaded">
   4:              <EventTrigger.Actions>
   5:                  <BeginStoryboard>
   6:                      <Storyboard>
   7:                          <MediaTimeline Source="Instructions.avi" RepeatBehavior="Forever" Storyboard.TargetName="video" />
   8:                      </Storyboard>
   9:                  </BeginStoryboard>
  10:              </EventTrigger.Actions>
  11:          </EventTrigger>
  12:      </MediaElement.Triggers>
  13:  </MediaElement>

Unfortunately this solution is not reliable. After some time it can took a while before the video starts playing again after it has ended. Sometimes the video stops playing completely. Some searching revealed that the MediaElement indeed is not reliable enough. Some alternatives where suggested, for example http://wpfmediakit.codeplex.com/.

The mediakit can indeed be a solution but there is a simpler way without adding a dependency on a third party framework. Instead of using a StoryBoard and a MediaTimeLine you can also manage the repetition yourself. The following code demonstrates this.

   1:  <MediaElement x:Name="instructionVideo" Width="320" Height="240" Source="Videos/Instructions.mp4" LoadedBehavior="Manual" Loaded="instructionVideo_Loaded" MediaEnded="instructionVideo_MediaEnded" VerticalAlignment="Bottom" HorizontalAlignment="Center" Canvas.Top="40"/>

The above XAML fragment is accompanied by the following code-behind:

   1:   private void instructionVideo_Loaded(object sender, RoutedEventArgs e)
   2:   {
   3:       instructionVideo.Play();
   4:   }
   5:   
   6:   private void instructionVideo_MediaEnded(object sender, RoutedEventArgs e)
   7:   {
   8:       instructionVideo.Position = TimeSpan.FromSeconds(0);
   9:   }

Instead of letting WPF manage the video, we specify a LoadedBehavior of Manual which means we can manage the starting and stopping of the video ourselves. To actually start the video the Loaded event handler is used which calls the Play method on the instructionVideo element. When the video reaches the end, the MediaEnded event is dispatched. In this event the Position is set back to 0 so the video starts playing from the beginning again. This proved to be a reliable way of continuously looping videos.

PS. the video in questions is in mp4 format and about 20 seconds in length which must loop all day long.

Monday, January 23, 2012

Monitoring an IBM JVM with VisualVM


JDK6 update 7 and onward include a tool called VisualVM. VisualVM is a visual tool with monitoring and profiling capabilities for the JVM. With VisualVM you can:
  1. Monitor heap usage
  2. Monitor CPU usage
  3. Monitor Threads
  4. Initiate garbage collections
  5. Profile CPU and memory
  6. And more…

Although VisualVM is distributed with the Oracle JDK, it can also be used to monitor IBM JVM’s. VisualVM is not able to connect to the IBM JVM locally. JMX must be used instead.

To enable JMX monitoring on the IBM JVM open the WebSphere administrative console and:
  1. navigate to: Server -> Server Types -> WebSphere application servers ->[SERVER_NAME]
  2. Expand Java and Process Management and click Process definition
  3. Click Java Virtual Machine
  4. In the Generic JVM arguments field append the following properties: -Djavax.management.builder.initial= -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1099
  5. Restart the server


To start monitoring the JVM with VisualVM start VisualVM by navigating to [JDK_HOME]\bin and start jvisualvm.exe (please note that when VisualVM is downloaded as a separate package the executable is called visualvm.exe instead). In VisualVM click File -> Add JMX Connection. Specify localhost:1099 in the connection field and click OK.

If everything went OK, you should see the localhost:1099 connection under the Local node in the tree on the left. Double-click this node to start monitoring. See the following screenshot for an example:



When using a JMX connection to monitor the JVM please be aware that not all functionality can be used compared to monitoring a local JVM. Profiling memory is for example not possible.

The above configuration was tested on:
  • Windows 7 64-bit
  • IBM JDK1.6 64 bit
  • WebSphere Application Server version 7.0

Note: Before JDK6 update 7, VisualVM can also be downloaded separately from http://visualvm.java.net/download.html
Note: To actually test if port 1099 is listening for connections use (on Windows) the netstat –a command and check wether the port is present and listening.

Wednesday, December 28, 2011

Improved IntelliJ keymap

At my current client the whole team recently switched from an Eclipse based IDE to IntelliJ. Although some of us have used IntelliJ for a long time, most had not. Switching from Eclipse to IntelliJ can be hard. It took me about three to four weeks before I was more productive with IntelliJ. Now I do not want to go back anymore.

To make the transition more smooth I am looking into several ways to accomplish this. One of the things I made is a new keymap reference for IntelliJ. The default keymap reference contains a whole list of shortcuts but I find them sometimes hard to find. The new, improved, keymap should make the most used IntelliJ features really easy to find. The most used features are based upon my own experience and the IntelliJ productivity guide of my colleagues. The productivity guide shows which features of IntelliJ are used most often.

To create the improved keymap reference I basically did the following:

  1. Stripped about half of the features from the default keymap reference. The features present on the new keymap reference are the most used features.
  2. Made a clearer distinction between the different types of functionality the features belong to.
  3. In each feature group I made a distinction between individual features which belong together.
  4. Used a larger font and more contrast to make things stand out more.
The Windows keymap reference can be found here: IntelliJ Keymap Windows
The OSX keymap reference can be found here: IntelliJ Keymap OSX

Hope you like it.

If you have any suggestions for the keymap reference please let me know.

Tuesday, August 2, 2011

WebSphere Portal 6.x Locale Resolution

When developing applications for WebSphere Portal there will be some point in time that the application should support I18N. For every language an application supports a resource bundle is provided. If a given language is not supported the application falls back to its default resource bundle. To format currencies and dates the JSTL formatting tags can be used. Based on the locale selection process of WebSphere Portal, the translation of dates and currencies in the correct locale may not what be exactly what you expect/want. This article provides a portal wide solution to handle locales in a consistent and transparent way.

Language selection process
WebSphere Portal server 6.x uses the following language selection process taken from the portal documentation:

  1. The language encoded in the URL takes highest priority. The portal does not encode a locale into the URL by default.
  2. If the user has logged in, the portal displays in the preferred language selected and stored in the user repository by the user.
  3. If no preferred user language can be found, the portal looks for the language defined in the user's browser. If the portal supports that language, it displays the content in that language. If the browser has more than one language defined, the portal uses the first language in the list to display the content.
  4. If no browser language can be found, for example if the browser used does not send a language, the portal resorts to its own default language.
  5. If the user has a portlet that does not support the language that was determined by the previous steps, that portlet is shown in its own default language.

By looking at step 3, the portal should accept the browser language if it supports this language. The same is true for the portlet itself. Unfortunately, it is not clear how the portal determines if a given language is supported or not. The documentation is not clear about this either.

By executing extensive tests (removing languages with XML access and removing the resource bundles of those specific language from portal) with different locales sent from the browser, the portal always took the language from the browser if the user did not have a specific language set in its user profile. This is not an issue with the resource bundles since the application falls back to its default resource bundle if the language is not supported. The JSTL tags however did not use the proper language which resulted in dates and currencies formatted in the locale of the browser. Since we wanted tight control of the language used, this behaviour was not an option for us. We wanted a Portal wide solution which did not impact application design/implementation. 

The portal documentation mentions something about a locale filter. Portal itself provides two implementations of this filter: ExtendedLocaleFilter and SortingLocaleFilter. It is also possible to implement a custom filter.

The code of the provided locale filters can be found in C:\IBM\WP61\PortalServer\base\wp.engine.impl\shared\app\wp.engine.impl.jar file.

Decompiling those filters you can see that the implementation reflects the above language selection process. The filters use the Puma API to determine the user’s locale. Also, by looking at this implementation you get a good idea of how to efficiently build a custom locale filter.

The following filter is an example filter which always fixes the locale to en_US regardless of the user profile or browser setting.



   1:  public class FixedLocaleFilter implements Filter {
   2:      public void init(final FilterConfig aFilterConfig) throws ServletException {
   3:      }
   4:   
   5:      public void doFilter(final ServletRequest aServletRequest, final ServletResponse aResponse, final FilterChain aFilterChain) throws IOException, ServletException {
   6:          if (aServletRequest instanceof HttpServletRequest) {
   7:              aFilterChain.doFilter(new FixedLocaleHttpServletRequest((HttpServletRequest) aServletRequest), aResponse);
   8:          } else {
   9:              aFilterChain.doFilter(aServletRequest, aResponse);
  10:          }
  11:      }
  12:   
  13:      public void destroy() {
  14:   
  15:      }
  16:  }
  17:   
  18:  public class FixedLocaleHttpServletRequest extends HttpServletRequestWrapper {
  19:      private static final Locale EN = new Locale("en", "US");
  20:      private static final Vector<Locale> LOCALES = new Vector<Locale>() {{
  21:          add(EN);
  22:      }};
  23:      private static final Vector<String> ACCEPT_LANGUAGE_EN_US = new Vector<String>() {{
  24:          add("en-US");
  25:      }};
  26:   
  27:      public FixedLocaleHttpServletRequest (HttpServletRequest request) {
  28:          super(request);
  29:      }
  30:   
  31:      @Override
  32:      public Locale getLocale() {
  33:          return EN;
  34:      }
  35:   
  36:      @Override
  37:      public Enumeration getLocales() {
  38:          return LOCALES.elements();
  39:      }
  40:   
  41:      public String getHeader(String header) {
  42:          if (isAcceptLanguageHeader(header))
  43:              return "en-US";
  44:          else
  45:              return super.getHeader(header);
  46:      }
  47:   
  48:      public Enumeration getHeaders(String s) {
  49:          if (isAcceptLanguageHeader(s))
  50:              return ACCEPT_LANGUAGE_EN_US.elements();
  51:          else
  52:              return super.getHeaders(s);
  53:      }
  54:   
  55:      private boolean isAcceptLanguageHeader(String s) {
  56:          return s.intern() == "Accept-Language" || s.equalsIgnoreCase("Accept-Language");
  57:      }
  58:  }

The above FixedLocaleFilter just wraps the incoming request in a FixedLocaleHttpServletRequest. The next step is to configure this filter in the web.xml of the Portal application web.xml. The web.xml can be found in wp_profile_root/config/cells/node-name/applications/wps.ear/deployments/wps/wps.war/WEB-INF.

See the following example configuration:



   1:  <filter>
   2:          <filter-name>Locale Filter</filter-name>
   3:          <!--<filter-class>com.ibm.wps.engine.ExtendedLocaleFilter</filter-class>-->
   4:          <filter-class>FixedLocaleFilter</filter-class>
   5:      </filter>

Please note that the above sample code is just an example unless you want a fixed locale of en_US for the whole profile where the portal is deployed. A practical scenario would be a custom filter which uses the following language selection process:
  1. If the user has set a locale in its profile use that one.
  2. If the user has not set a locale use the browsers locale if the locale is supported.
  3. If the browser locale is not supported use the default locale of the portal.
The above steps can easily be implemented using a custom locale filter. You can also use init parameters to make the filter configurable.

Conclusion
Letting all applications in a WebSphere portal behave the same regarding locale resolution can be hard/impossible if you do not want to implement custom locale handling code within the applications itself. By using a custom locale filter in WebSphere portal, the locale resolution code is kept in one place. This makes locale resolution transparent and clear to all applications running in the portal. 


Monday, June 6, 2011

search engine meta information

Microsoft, Google and Yahoo, the companies behind the three major search engines Bing, Yahoo and Google, have launched a new initiative to add meta data to an HTML document. This meta data is used by the aforementioned search engines to improve the displaying of search results.

Consider the following example:
<html>
    <div class="product">
        <!-- product information comes here. -->
    <div>
</html>

The reader of this HTML fragment immediately sees that this is something about product information. A computer program, like a search engine instead, cannot determine that this information is actually about products.

To help search engines, and potentially other software, understand the meta information behind the information, http://www.schema.org describes a shared vocabulary which can be used to add meta data to HTML tags.

Consider the revisited example:
<html>
    <div class="product" itemscope itemtype="http://schema.org/Product">
        <!-- product information comes here. -->
    <div>
</html>

By adding the itemscope attribute, you are telling the information between the div element is about a particular item. The itemtype attribute narrows this item further as a Product. This way, search engine can potentially add this information to an online product catalog making your products easier to find. Other types are available as wel, for example:
  • Movie
  • Event
  • Organisation
I implemented this meta tags for a new webshop I am building. These attributes are part of the HTML5 standard and therefore cannot be used by an XHTML1.1 strict syntax without passing the W3C validation. To use these attributes, just declare your document as HTML5. You can then use the W3C validator to fix any validation errors which may arise. I think this is worth the exercise.


One step further to the semantic web.