Structure of the IBAN (International Bank Account Number)

An IBAN may contain up to 34 alphanumeric characters and is composed of the following parts:

  • Double-digit alphabetic code according to ISO3166
  • Two-digit numeric check digit over the whole IBAN under Modulo 97-10 (ISO7064)
  • Maximum 30-digit Basic Bank Account Number (BBAN), consisting of the Institute identification (IID) and Bank Account Number (BAN)

The IBAN in electronic form contains no spaces, but  in a printed form it is usually presented into groups of four characters with spaces . The last group of characters contains the remaining characters of the IBAN. In this way the IBAN is easier to read. By validating the check digit in the IBAN the frequent cross-border payments misdirections can virtually ruled out. The Basic Bank Account Number is used by the financial institutions identified in the respective countries and the customer account at a bank. The IBAN can be derived, although usually from the domestic bank account number, but it is not always reliable. Therefore the European Committee for Banking Standards (ECBS) has indicated that an IBAN should in principle only be made by the account-holding financial institution. The software-calculation of the IBAN bank account number and ID is not recommended and may lead to incorrect results. A check of the check digit is useful to prevent input errors.

Check digit for IBAN

For the IBAN check digit calculation method, the modulus is used 97-10 (ISO7064). The purely numerical check digit consists of two bodies and is for all participating countries are following the country code at position 3 and 4. In order to calculate and validate the check digit, the alpha characters of the IBAN must be converted using the conversion table below, in double-figures.

A = 10 B = 11 C = 12 D = 13 E = 14 F = 15
G = 16 H = 17 I = 18 J = 19 K = 20 L = 21
M = 22 N = 23 O = 24 P = 25 Q = 26 R = 27
S = 28 T = 29 U = 30 V = 31 W = 32 X = 33
Y = 34 Z = 35

Swiss Interbank Clearing AG has described an example of the check digit for IBAN. The starting point is the IBAN CH10002300A1023502601. The presentation in paper form would be: CH10 0023 00A1 0235 0260 1. Thus, the check digit is 10. First, the first four characters of the IBAN must be moved to the right end of the IBAN: 002300A1023502601CH10. Subsequently, the alpha characters are converted using the conversion table in numeric characters: 002300101023502601121710. This number is divided by 97. If the check digit is correct, the residual value is always 1.

Terminating processes with delphi

Windows processes can be terminated from a delphi application using Win32 API calls. To terminate processes not owned by the current user the SE_DEBUG_NAME privilege must be set for the current process.

All sample code must include unit TlHelp32.

Sample code for activating SE_DEBUG_NAME privilege

function NTSetPrivilege(sPrivilege: string; bEnabled: Boolean): Boolean;
var
  hToken: THandle;
  TokenPriv: TOKEN_PRIVILEGES;
  PrevTokenPriv: TOKEN_PRIVILEGES;
  ReturnLength: Cardinal;
begin
  Result := True;
  // Only for Windows NT/2000/XP and later.
  if not (Win32Platform = VER_PLATFORM_WIN32_NT) then
    Exit;

  Result := False;

  // obtain the processes token
  if OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
  begin
    try
      // Get the locally unique identifier (LUID) .
      if LookupPrivilegeValue(nil, PChar(sPrivilege),TokenPriv.Privileges[0].Luid) then
      begin
        TokenPriv.PrivilegeCount := 1; // one privilege to set

        case bEnabled of
          True: TokenPriv.Privileges[0].Attributes  := SE_PRIVILEGE_ENABLED;
          False: TokenPriv.Privileges[0].Attributes := 0;
        end;

        ReturnLength := 0; // replaces a var parameter
        PrevTokenPriv := TokenPriv;

        // enable or disable the privilege
        AdjustTokenPrivileges(hToken, False, TokenPriv, SizeOf(PrevTokenPriv),PrevTokenPriv, ReturnLength);
      end;
    finally
      CloseHandle(hToken);
    end;
  end;

  // test the return value of AdjustTokenPrivileges.
  Result := GetLastError = ERROR_SUCCESS;
  if not Result then
    raise Exception.Create(SysErrorMessage(GetLastError));
end;</pre>
<span style="text-decoration: underline;">Sample code for terminating processes by name of executable file</span>
<pre lang="delphi">procedure Killprocess(Name:String);
var
  PEHandle,hproc: cardinal;
  PE: ProcessEntry32;
begin
  NTSetPrivilege(SE_DEBUG_NAME,True);
  PEHandle := CreateTOOLHelp32Snapshot(TH32cs_Snapprocess,0);
  if PEHandle &lt;&gt; Invalid_Handle_Value then
  begin
    PE.dwSize := Sizeof(ProcessEntry32);
    Process32first(PEHandle,PE);

    repeat
      if Lowercase(PE.szExeFile) = Lowercase(Pchar(Name)) then
      begin
        hproc := openprocess(Process_Terminate,false,pe.th32ProcessID);
        TerminateProcess(hproc,0);
        closehandle(hproc);
      end;
    until Process32next(PEHandle,PE)=false;
  end;
  closehandle(PEHandle);
end;

Load balancing with Apache 2.2 mod_proxy_ajp

The Apache 2.2 webserver has a module for proxiing AJP requests (mod_proxy_ajp). This module is delivered with the Apache webserver by default.

Activating modules

The following modules must be enabled to use the AJP proxy functionallity:

  • mod_proxy
  • mod_proxy_ajp
  • mod_proxy_balancer

To activate the modules uncomment the following lines in your httpd.conf configuration file (e.g. /opt/apache/conf/httpd.conf):

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

Configuring modules

To configure the modules we create a new configuration file conf/ajp_proxy.conf in the apache directory and add the following line to our httpd.conf file:

Include conf/ajp_proxy.conf

First of all we put all configuration directives in <IfModule/> blocks to ensure that all needed modules are loaded:

<IfModule mod_proxy>
  <IfModule mod_proxy_ajp>
    <IfModule mod_proxy_balancer>
      # configuration of AJP proxy
    </IfModule>
  </IfModule>
</IfModule>

Creating Load Balancer Cluster

The load balancer cluster is created with the ProxyPass directive. The syntax for this directive is

ProxyPass <path> balancer://<name-of-cluster> <options>

The <path> argument stays for the logical path on the apache server, <name-of-cluster> for the name of your cluster and <options> for the options for this load balacer cluster (see documentation for description of options).

Example:

ProxyPass /myapp balancer://mycluster/myapp stickysession=JSESSIONID nofailover=On

In the next step we must define the workers for our cluster and your application server must support the JServ AJP protocol, e.g. Tomcat. For glassfish aka Sun Java System Application Server see my mod_jk tutorial for implementing the JServ protocol into the server.

The workers are definded into a <Proxy/> directive. The syntax for this directive is

<Proxy balancer://<name-of-cluster>
  BalancerMember ajp:<hostname>:<port> <options>
</Proxy>

You can define multiple workers in one proxy directive.

Example for two worker nodes:

<Proxy balancer://mycluster>
  BalancerMember ajp://node1.mydomain.com:8009 route=node1
  BalancerMember ajp://node2.mydomain.com:8009 route=node2
</Proxy>

ObjectListDataProvider Tutorial

This is a tutorial for using the ObjectListDataProvider in a Visual Web Project. A ObjectListDataProvider is useful if the underlaying data is from a datasource not supported by NetBeans. Some samples for such datasources are a JPA or hibernate connection, other legacy systems such SAP or Lotus Notes and files in various formats.

In this tutorial we use a text file with customer records as datasource for our application.

Creating the project

In the first step you create a normal VWP project named OldpSample:

Project settings OLDP

Address POJO

For data storage we use a simple POJO object. Right click the oldpsample package under «Source Packages» and select «New -> Java Class». Name the class Address.

Create Address class

package oldpsample;

public class Address {

  private String id;
  private String title;
  private String lastname;
  private String firstname;
  private String street;
  private String city;
  private String state;
  private String country;

/** Creates a new instance of Address */
  public Address() {
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getLastname() {
    return lastname;
  }

  public void setLastname(String lastname) {
    this.lastname = lastname;
  }

  public String getFirstname() {
    return firstname;
  }

  public void setFirstname(String firstname) {
    this.firstname = firstname;
  }

  public String getStreet() {
    return street;
  }

  public void setStreet(String street) {
    this.street = street;
  }

  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

  public String getState() {
    return state;
  }

  public void setState(String state) {
    this.state = state;
  }

  public String getCountry() {
    return country;
  }

  public void setCountry(String country) {
    this.country = country;
  }

}

Create AddressDataProvider

Now we create the class AddressDataProvider. We create a new class and derive it from ObjectListDataProvider. Right click the oldpsample package under «Source Packages» and select «New -> Java Class».

Create AdressDataProvider class

Our class stores all data in a ArrayList, so we need a member variable of type ArrayList. In the constructor we must tell the underlying ObjectListDataProvider where the data comes from (method setList) and of which type the data is (method setObjectType). We also need methods to load the data from file or stream.

package oldpsample;

import com.sun.data.provider.impl.ObjectListDataProvider;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class AddressDataProvider extends ObjectListDataProvider {

  private ArrayList addressList = new ArrayList();

  /** Creates a new instance of AddressDataProvider */
  public AddressDataProvider() {
    setList( addressList );
    setObjectType( Address.class );
  }

  public void load(InputStream istream ) {
      try {
      InputStreamReader sr = new InputStreamReader( istream );
      BufferedReader br = new BufferedReader( sr );

      while ( br.ready() ) {
        String line = br.readLine();
        String[] cols = line.split( ";" );

        if ( cols.length == 8 ) {
          Address address = new Address();
          address.setId( cols[0] );
          address.setTitle( cols[1] );
          address.setLastname( cols[2] );
          address.setFirstname( cols[3] );
          address.setStreet( cols[4] );
          address.setCity( cols[5] );
          address.setState( cols[6] );
          address.setCountry( cols[7] );
          getList().add( address );
        }
      }

    } catch ( Exception e ) {
      e.printStackTrace();
    }
  }

  public void load(String filename) {
    try {
      FileInputStream fs = new FileInputStream( filename );
      load( fs );
    } catch ( Exception e ) {
      e.printStackTrace();
    }
  }

}

Add AddressDataProvider to SessionBean1

In the outline view right click on SessionBean1 and select «Add->Property» from the context menu. Name the property «addressDataProvider» and enter «AddressDataProvider» as Type. Leave all other options on the default values.

New Property addressDataProvider

Double click SessionBean1 in the outline view. Find the line

private AddressDataProvider addressDataProvider;

and change it to

private AddressDataProvider addressDataProvider = new AddressDataProvider();

You must build, close and reopen your VWP project now (as of NetBeans 5.5.1). If not, NetBeans doesn’t detect our ObjectListDataProvider. This should hopefully not been necessary in future NetBeans releases.

Design Web Page

The project wizard has generated a default web page Page1.jsp. Open this page and the visual designer starts.

Select a table component from the palette and drop it onto your page. Right click the table component and select «Bind to Data…». Select «addressDataProvider (SessionBean1)» from the dropdown list. Reorder the fields with the «Up» and «Down» buttons, so it look like this:

Select Data Provider

Press «OK» and our page has a table component bound to the AddressDataProvider.

To show some data in the table component we let the user upload a CSV file. Drop a File Upload and a Button component from the palette onto the page. Set the text property of the button to «Upload file». Your page should look like this:

Page Design

Double click on the «Upload file» button and enter the following code into the event handler:

public String button1_action() {
  if ( fileUpload1.getUploadedFile().getSize() > 0 ) {
    try {
      getSessionBean1().getAddressDataProvider().load(
        getFileUpload1().getUploadedFile().getInputStream() );
    } catch ( Exception e ) {
      e.printStackTrace();
    }
  }
  return null;
}

Run your project. Use this sample CSV data file to test the application:

1;Mr.;Able;Tony;216 King St;San Francisco;CA;USA
2;Mr.;Black;Tom;655 Divisadero St;San Francisco;CA;USA
3;Mr.;Kent;Richard;509 Valencia St;San Francisco;CA;USA
4;Mr.;Chen;Larry;407 Ellis St;San Francisco;CA;USA
5;Mrs.;Donaldson;Sue;314 Columbus Ave;San Francisco;CA;USA
6;Mr.;Murrell;Tony;4124 Geary Blvd;San Francisco;CA;USA

This sample project can also be downloaded.

Use Tomcat Connector for Load Balancing Glassfish or SJSAS

In this tutorial i describe how you can use the Tomcat Connector (mod_jk module) as a load balancer for the Glassfish or Sun Java System Application Server (SJSAS). It’s availabe as a loadable module for the Apache webserver and for the Microsoft IIS.

The Tomcat Connector uses the packet oriented binary AJP13 protocol for the communication between the servlet container and the webserver. This architecture is optimized for speed and is much faster as a proxy configuration.

Download components

  1. Download the actual mod_jk distribution for either Apache or IIS webserver.
  2. Download the actual Tomcat 5.5 distribution.
  3. Download commons-logging and commons-modeler from the Jakarta Project.

Installation for Apache Webserver

Copy the mod_jk distribution files to your apache libexec directory, e.g. /srv/apache/libexec under Linux OS.

Edit the server configuration file httpd.conf and add the following configuration options:

# Load mod_jk module
LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c

<IfModule mod_jk.c>
  # Tells the module the location of the workers.properties file
  JkWorkersFile /srv/apache/conf/workers.properties

  # Specifies the location for this module's specific log file
  JkLogFile /var/log/mod_jk.log

  # Sets the module's log level to info
  JkLogLevel info

  # Sets the module's log time stamp format
  JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

  # JkOptions for SSL
  JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

  # Set mount points for load balancer
  JkMount /app1   loadbalancer1
  JkMount /app1/* loadbalancer1
  JkMount /app2   loadbalancer1
  JkMount /app2/* loadbalancer1
</IfModule>

Installation for Microsoft IIS

  1. In the registry, create a new registry key named “HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0”
  2. Add a string value with the name extension_uri and a value of /jakarta/isapi_redirect.dll.
  3. Add a string value with the name log_file and a value pointing to where you want your log file to be (for example c:\mod_jk\isapi.log).
  4. Add a string value with the name log_level and a value for your log level (can be debug, info, error or emerg).
  5. Add a string value with the name worker_file and a value which is the full path to your workers.properties file (for example c:\mod_jk\workers.properties)
  6. Add a string value with the name worker_mount_file and a value which is the full path to your uriworkermap.properties file (for example c:\mod_jk\uriworkermap.properties)
  7. Using the IIS management console, add a new virtual directory to your IIS/PWS web site. The name of the virtual directory must be jakarta. Its physical path should be the directory where you placed isapi_redirect.dll (in our example it is c:\mod_jk). While creating this new virtual directory assign it with execute access.
  8. Using the IIS management console, add isapi_redirect.dll as a filter in your IIS/PWS web site. The name of the filter should reflect its task (I use the name glassfish), its executable must be our c:\mod_jk\isapi_redirect.dll. For PWS, you’ll need to use regedit and add/edit the “Filter DLLs” key under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3SVC\Parameters. This key contains a “,” separated list of dlls (full paths) – you need to insert the full path to isapi_redirect.dll.
  9. Restart IIS (stop + start the IIS service), make sure that the tomcat filter is marked with a green up-pointing arrow. Under Win98 you may need to cd WINDOWS\SYSTEM\inetsrv and type PWS /stop ( the DLL and log files are locked – even if you click the stop button, PWS will still keep the DLLs in memory. ). Type pws to start it again.

Setup uriworkermap.properties (IIS only)

In the uriworkermap.properties file you define the mappings for URL’s which should be connected to your load balancer:

# Mapping for app1
/app1=loadbalancer1
/app1/*=loadbalancer1

# Mapping for app2
/app2=loadbalancer1
/app2/*=loadbalancer1

Configuration of Tomcat Connector

Edit the file workers.properties which you have specified in your webserver configuration file:

# Define all worker nodes
worker.list=loadbalancer1

# Set properties for server1 (ajp13)
worker.server1.type=ajp13
worker.server1.host=server1
worker.server1.port=8009
worker.server1.lbfactor=50
worker.server1.cachesize=10
worker.server1.cache_timeout=600
worker.server1.socket_keepalive=1
worker.server1.socket_timeout=300

# Set properties for server2 (ajp13)
worker.server2.type=ajp13
worker.server2.host=server2
worker.server2.port=8009
worker.server2.lbfactor=50
worker.server2.cachesize=10
worker.server2.cache_timeout=600
worker.server2.socket_keepalive=1
worker.server2.socket_timeout=300

# Set properties for loadbalancer1
worker.loadbalancer1.type=lb
worker.loadbalancer1.balance_workers=server1,server2
worker.loadbalancer1.sticky_session=true
worker.loadbalancer1.sticky_session_force=false
worker.loadbalancer1.method=request
worker.loadbalancer1.lock=optimistic
worker.loadbalancer1.retries=3

Restart your Apache webserver.

Installing AJP13 connector into application server

To install the AJP13 connector into your application server you must copy the file

$TOMCAT_HOME/server/lib/tomcat_ajp.jar

from the Tomcat server distribution to your application server’s lib directory. It seems that the actual Tomcat 5.5.25 tomcat_ajp.jar doesn’t work and throws a java.lang.NoSuchMethodError exception. So use the library bundled with Tomcat 5.5.16 and all works ok. You also need to copy the downloaded commons-logging.jar and commons-modeler.jar to this directory.

To activate the connector use the console application to add the following JVM option to your server instance:

-Dcom.sun.enterprise.web.connector.enableJK=8009

Restart your application server.

All requests to the definded mount points on the webserver should now be delegated to one of your application servers.

You can download the sample configuration files, jar archives and mod_jk modules for windows and linux here.