samaxes

samaxes logo

Ramblings about Open Source, Java and other Web technologies by Samuel Santos

Run PHP on Google App Engine

By adding Java to their App Engine, Google has opened the door for a whole slew of languages that have been implemented on the JVM, now including PHP via Quercus.

This weekend I decided to give it a try and deploy a (very) old tutorial of mine - PHP Tutorial - on GAE.

I must admit that I was very pleasantly surprised by how effortless it was. OK, it’s a very rudimentary PHP application, the only PHP code used was to run the examples described on the code blocks and do some includes; nevertheless I didn’t feel the need to change a single line of code.

Also, deploying a Java application to GAE is simpler than a Python one. Not only because you have a very handy Eclipse plugin, but you will also find configuring the file appengine-web.xml a lot easier when compared to app.yaml.

All you need to do in order to deploy a PHP application, at least as simple as the one I’ve tried, is to follow these steps:
Read the rest of this entry »

W3C Widgets Compatibility Matrix for Packaging and Configuration

Daniel Silva, Marcos Caceres and myself have completed Phase 1 of Widgets 1.0: Packaging and Configuration compatibility testing. We have also detailed the results as part of the conformance matrix.
We would like to publish the results as a working group note. Phase 2 will begin in about 3 weeks, in which we are hoping to start working with vendors to improve overall conformance.

We need help with Phase 2: if you know a team contact for any of the targeted products that are claiming conformance to W3C Widgets, then would appreciate your help in making them aware of the results of the testing - Widgets 1.0: Compatibility Matrix for Packaging and Configuration.

Java Web Development with Stripes

Stripes Framework presentation for the Portuguese Java User Group session on the JavaPT09 event.

The used source code is also available.

Unit Testing JBoss 5 Services

The JBoss Microcontainer is a refactoring of JBoss’s JMX Microkernel to support direct POJO deployment and standalone use outside the JBoss application server.
It allows the creation of services using simple Plain Old Java Objects (POJOs) to be deployed into a standard Java SE runtime environment.

JBoss Microcontainer uses dependency injection to wire individual POJOs together to create services. Configuration is performed using either annotations or XML depending on where the information is best located.

The goal of this article is to show how easy it is to test these services using TestNG testing framework.
Read the rest of this entry »

Maven Minify Plugin using YUI Compressor

Following the previous article Combine and minimize JavaScript and CSS files for faster loading, I implemented a similar solution as a Maven plugin.

This plugin combines and minimizes JavaScript and CSS files using YUI Compressor for faster page loading.

More details can be found on the Maven Minify Plugin page.

Combine and minimize JavaScript and CSS files for faster loading

Reduce HTTP requests

On most sites, the major component of download time is not the base HTML file itself, but the number of subsequent HTTP requests to load the page’s supporting files - CSS, JavaScript, images, etc.
Each of those are extra HTTP requests, and each unique request takes a relatively long time.
The fewer requests to the server that the browser has to make, the faster the page will load.
There is an inherent overhead in each HTTP request. It takes substantially less time to serve one 60K file than it does three 20K files and a lot less than it does six 10K files.

Combine and minimize files

This post will explain how to combine and minimize CSS and JavaScript files using YUI Compressor and Ant.

This can be done by just concatenating all files into two combined files (one for CSS and one for JavaScript) and minimize them. You can quickly go from 10 or more files down to 2, and their size can be greatly reduced.

To keep the modularity that comes with splitting these files out by section (or business unit), keep them split in your development process, and combine them in your build process. A first Ant task will combine them and a second task will generate their minimized versions.

This technique has been successfully used in libraries such as jQuery, MooTools, Dojo, ExtJS, YUI, etc, allowing developers to better organize their code.
Read the rest of this entry »

Cross Browser Testing

No matter how anxiously expected, the release of IE8 hasn’t resulted in the end of the support for the old, deprecated, IE6 rendering engine. Giving us, the web developers, need to test against yet another version of IE.

Hopefully the eighth version is going to be a lot easier to test and support since it’s more standards compliant and in that perspective, much closer to the other modern browsers. It’s also comes with easier debugging functionality as it has an integrated set of developer tools available by pressing F12 or by clicking ‘Developer Tools’ under Tools menu.

But right now, together with other major players (Firefox, Opera, Safari and Chrome) you can end up with a total of 7 browsers to test. You might even want to test different versions of individual browsers, transforming this task into a nightmare. Fortunately tools, allowing you to compare different rendering engines in a single unified interface, are emerging and can really save the day. Two great examples are:

  1. Microsoft Expression Web SuperPreview
  2. DebugBar IETester

For a complete list of browser’s compatibility, check the great Compatibility Master Table from QuirksMode.

Axis 1.4 Read timed out and HTTP 1.1

For those getting a SocketTimeoutException when calling an Axis 1.4 Web Service.
This may be a solution for your problem.

If your log show an error similar to this:

12:38:51,693 ERROR [TerminalSessionHelper] ; nested exception is: 
	java.net.SocketTimeoutException: Read timed out
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.net.SocketTimeoutException: Read timed out
 faultActor: 
 faultNode: 
 faultDetail: 
	{http://xml.apache.org/axis/}stackTrace:java.net.SocketTimeoutException: Read timed out
...

And your call looks like this:

TerminalSessionService terminalSessionService = new TerminalSessionServiceLocator();
 
TerminalSession_PortType terminalSession_PortType = terminalSessionService.getTerminalSession();
 
((TerminalSessionSOAPBindingStub) terminalSession_PortType).setTimeout(15000);

Try to use CommonsHTTPSender as the Transport Sender of the Axis client:

BasicClientConfig basicClientConfig = new BasicClientConfig();
SimpleChain simpleChain = new SimpleChain();
 
simpleChain.addHandler(new CommonsHTTPSender());
basicClientConfig.deployTransport("http", simpleChain);
 
TerminalSessionService terminalSessionService = new TerminalSessionServiceLocator(basicClientConfig);
 
TerminalSession_PortType terminalSession_PortType = terminalSessionService.getTerminalSession();
 
((TerminalSessionSOAPBindingStub) terminalSession_PortType).setTimeout(15000);

This also has the advantage to use HTTP 1.1 instead of HTTP 1.0.
Note: You will need to add the common-httpclient.jar and common.codec.jar to the jar directory for this to work.

Still want to use HTTP 1.0? No problem, just add the following line of code:

((TerminalSessionSOAPBindingStub) terminalSession_PortType)._setProperty(
        MessageContext.HTTP_TRANSPORT_VERSION, HTTPConstants.HEADER_PROTOCOL_V10);

Hope this can save your time. Axis can be really painful…

JBoss PojoCache configuration

Everyone knows that documentation is not one of JBoss strengths.
This article is meant to fill this gap. It describes and exemplifies how to configure JBoss PojoCache as a MBean service, using loadtime transformations with JBossAop framework, so you don’t need precompiled instrumentation.

Introduction

This section gives you an introduction about PojoCache and its advantages over TreeCache (a plain cache system).

PojoCache is an in-memomy, transactional, and replicated POJO (plain old Java object) cache system that allows users to operate on a POJO transparently without active user management of either replication or persistency aspects. PojoCache, a component of JBossCache (uses PojoCache class as an internal implementation, the old implementation TreeCacheAop has been deprecated.), is the first in the market to provide a POJO cache functionality. JBossCache by itself is a 100% Java based library that can be run either as a standalone program or inside an application server.

TreeCache limitations:

  • Users will have to manage the cache specifically; e.g., when an object is updated, a user will need a corresponding API call to update the cache content.
  • If the object size is huge, even a single field update would trigger the whole object serialization. Thus, it can be unnecessarily expensive.
  • The object structure can not have a graph relationship. That is, the object can not have sub-objects that are shared (multiple referenced) or referenced to itself (cyclic). Otherwise, the relationship will be broken upon serialization.

PojoCache advantages:

  • No need to implement Serializable interface for the POJOs.
  • Replication (or even persistency) is done on a per-field basis (as opposed to the whole object binary level).
  • The object relationship and identity are preserved automatically in a distributed, replicated environment. It enables transparent usage behavior and increases software performance.

Read the rest of this entry »

Internationalization of the File Upload Form Field

Internationalization, or i18n, is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language. Localization refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a “locale”).

Adapting application to various languages is for me, as a Java and HTML developer, more than a common task. Usually the solution involves a set of supported locales, which is very often different from the system locale and/or browser configuration. Majority of such cases are covered by the scenario when user chooses particular language settings and the only place where the locale setting can be stored is the HTTP Session.

Support for this behavior is now handled by majority of frameworks; nevertheless there is still one HTML element that you can’t effectively change - the file upload form field.
Read the rest of this entry »

Sponsors