Using JQuery and Prototype

Yesterday I had a very interesting bug. When migrating a Wordpress Template from a site I have made I get a no function defined error in JS. The issue was with using both prototype and JQuerry to do a simple page animation.
The solution is trivial (redefine jQuery accessor):







Tags:
Posted in Uncategorized by dido. No Comments

Intercepting test methods with TestNG

In my integration test project I use TestNG and SeamTest and JBoss MicroContainer to simulate real server environment during the tests. To run a particular integration test I have to wrap it inside ComponentTest instance and call the run() method on it like described here, but i need this for all my tests. To fix it i needed something like AOP interceptors for TestNG. Appearantly there is such API in TestNG but it’s not yet documented. To use it you have to implement an interface called IHookable (which source can be found here) in the class containing the tests and put your stuff inside its run() method.  I created an abstract class that implements IHookable and made all my test classes extend this class. The final code looks something like this:

public abstract class IntegrationTest extends SeamTest implements IHookable {

  @Override
  @Test(enabled = false)
  public void run(final IHookCallBack callBack, final ITestResult result) {
    try {
      new ComponentTest() {
        @Override
        protected void testComponents() {
          callBack.runTestMethod(result);
        }
      }.run();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
  }
}

P.S. Remember to set @Test(enabled = false) on the run() method because it’s public and if you use @Test on the class, TestNG will consider the method for a test.

Tags:
Posted in Uncategorized by amitev. No Comments

Security considerations when using the KeyStore object

When we load a KeyStore object from a certain provider (KeyStore.getInstance(TYPE).load(null, PIN_CODE), the session of this provider stays valid in the JVM of the applet. Noy only that but when you enter a wrong PIN after that, your KeyStore, still gets the private key from the Smart Card. Due to the reason that all applets run in a single JVM this is a security flaw, which can lead to a situation where an untrusted applet steals the KeyStore object and uses it to authenticate on part of the user.
To prevent this behaviour, we should always call Provider.logout() after we have finished working with the keystore to destroy the object.

((AuthProvider) keyStore.getProvider()).logout();
keyStore.load(null, PIN_CODE);

Tags: , ,
Posted in Uncategorized by dido. No Comments

Download a file using JSF

To download a file from a JSF page use the following code:

public String download() {
    HttpServletResponse response = (HttpServletResponse)extCtx.getResponse();
    response.setContentType("application/octet-stream");
    response.addHeader("Content-Disposition","attachment;filename=" + FILE_NAME);
    PrintWriter writer = response.getWriter();

    /* DO YOUR THING (like writer.write) */

    writer.flush();
    facesContext.responseComplete();
    writer.close();

    return "result;
}
Tags: ,
Posted in Uncategorized by dido. No Comments

Defining PaaS

PaaS (Platform-as-a-Service) should provide the following features.

1) Develop, Test, Deploy, Host and Maintain on the Same Integrated Environment
It’s time to stop developing “here” and running “there”. Today, most applications are coded in one environment (usually custom-built for that project by a developer), then tested in another, and redeployed to yet another for production. In addition to the costs of building, configuring and maintaining these separate environments, applications almost always need to change and get re-factored to overcome roadblocks as they proceed through the software lifecycle, which incurs even more costs along the way. In the conventional on-premise model, these cost and attendant risks fall on the application owner, and are considered part of the cost of deploying a web-scale application. In a completely-realized PaaS, the entire software lifecycle is supported on the same computing environment, dramatically reducing costs of development and maintenance, time-to-market and project risk. A PaaS should let developers spend their time creating great software, rather than building environments and wrestling with configurations just to make their applications run–let alone testing, tuning and debugging them.

Read the rest of Defining PaaS

Tags:
Posted in Uncategorized by dido. No Comments

Defining IaaS (Infrastructure as a Service)

Philosophy of IaaS

As a term, IaaS is generally associated with hosting business applications and obtaining resources such as hardware, software and facilities for a monthly fee instead of a capital purchase. This is also known in the common vernacular as “leasing”, but is hereby assigned a more arcane acronym so that technology vendors can market an old idea as something new. Assets generally belong to the hosting provider which could be an outsourced service provider or a progressive internal IT department using IaaS as a charge back model.

Key characteristics of infrastructure delivered by IaaS

The key characteristics of IaaS Infrastructure include:

  • Application resources such as servers, network equipment, memory, CPU, disk space, data center facilities, are provided as a monthly service
  • Infrastructure scales up and down dynamically based on application resource needs
  • Service is provided as a variable monthly cost using fixed prices per resource component
  • Multiple applications or customers may or may not co-habit on the same infrastructure resources
Tags:
Posted in Uncategorized by dido. No Comments

Eclipse and Seam Hot Redeployment

Seam Hot redeployment

Seam supports incremental redeployment of JavaBean components. To make use of this functionality, you must deploy the JavaBean components into the WEB-INF/dev directory, so that they will be loaded by a special Seam classloader, instead of by the WAR or EAR classloader.

This functionality has the following limitations:

  • The components must be JavaBean components, they cannot be EJB3 beans (we are working on fixing this limitation)
  • Entities can never be hot-deloyed
  • Components deployed via components.xml may not be hot-deployed
  • the hot-deployable components will not be visible to any classes deployed outside of WEB-INF/dev
  • Seam debug mode must be enabled and jboss-seam-debug.jar must be in WEB-INF/lib
  • You must have the Seam filter installed in web.xml
  • You may see errors if the system is placed under any load and debug is enabled.

Configuring Eclipse project to depoy hot-redeployable classes in WEB-INF/dev

  1. Create new Source Folder which will contain the hot-redeployable classes.
  2. Open .classpath file of the web project and add the following line:
    <classpathentry kind="src" output="WebContent/WEB-INF/dev" path="action"/>

    Where “action” is the name of the source folder for the hot-redeployable classes.

With this change, Eclipse will deploy the classes in WEB-INF/dev directory which is parsed by the Seam hot redeploy classloader.

Tags: , ,
Posted in Uncategorized by dido. No Comments

The keyword “final”

The Many Meanings of final

The final modifier can be applied to four Java constructs:

1. variables: a final variable can be set once and only once.
2. fields: a final field can also be set only once, by the constructor of the class which defines it.
3. methods: a final method cannot be overridden nor hidden.
4. classes: a final class cannot be extended.

Notice how using final is an entirely negative act. The final keyword works by subtracting, limiting default language mechanisms: the ability to override a method, to set a variable or a field. The motivations behind using final fall into three broad categories: correctness, robustness, and finally performance.

Read the rest of The keyword “final”

Static vs. dynamic polymorphism vs. method hiding

In Java there are two types of polymorphism – static and dynamic. In general, the difference between two types is that the static polymorphism determines the type of object at compile time which means that at the time of compilation it is definitely supposed to known the type of object, which is used. Static polymorphism is used when overloading methods. In contrast, dynamic polymorphism determine the type of object at run-time which mean that at the time of compilation it is not known the concrete type of object. Dynamic polymorphism is used when overriding methods. Next example approves the words above:

Read the rest of Static vs. dynamic polymorphism vs. method hiding

Tags: ,
Posted in Uncategorized by dido. No Comments

Enumerations

In Java 5, as all good Java developers will know, Sun introduced the enum type. Since I’m sure anyone who is interested in what will follow knows that already, I won’t bore you with the details but there’s some decent historical information on Sun’s reasons available. I’m going to be talking a little bit about operations on enums, so let’s get started by defining one:

Read the rest of Enumerations

Tags: ,
Posted in Uncategorized by dido. No Comments