How to make the Apache redirect from http to https and vice versa automatically

There are some ways to do that, in this examples let’s use the module mod_rewrite.

Make sure that the module mod_rewrite is being loaded by your apache

We need tell apache the condiction to execute the redirect, edit the file $APACHE_HOME/conf/httpd.conf and add the following lines:

#Turn on the rewrite
RewriteEngine on

#Condiction and rule for redirect
RewriteCond %{REQUEST_URI} ^/(<YOUR URL>)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

Sample:
Let’s suppose you need to redirect the URL http://youserver/login.php to https://youserver/login.php, our configuration would be the follwing:

RewriteCond %{REQUEST_URI} ^/(login\.php)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

If there are a need to set up more than one URL, just copy and paste the 2 lines above and replace the name of the page.

Once the user request the url http://youserver/login.php he will remain in https even in pages that are not configured in httpd.conf, That happened because that configuration tell apache to get in https when the page login.php is requested, so we need tell Apache to get in http when some other page is requested, this is configured in the file $APACHE_HOME/conf.d/ssl.conf, do the same configuration done in file http.conf

Sample:
Let’s suppose that after the user pass througt the login he will get the home.php page, so add the following lines in the file $APACHE_HOME/conf.d/ssl.conf:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(home\.php)
RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [R,L]

Don’t forget to restart the apache service

It’s done, :-) !!!

Leave a Comment

Converting Entity Objects to SelectItem Objects using reflection

This method is very useful for development JSP using JSF. This method converts a list of Entity Objects or any class that contains the items for a JSF ListBox to SelectItem Object. The class must have at least two methods:

  1. The id method that return de id of the Item
  2. The description method that return the description of the Item
public List<SelectItem> entityToSelectItem(List _items, String _idMethod, String _descMethod)throws Exception {
  List<SelectItem> items = new ArrayList<SelectItem>();

  Method idMethod = null;
  Method descMethod = null;

  for (int i = 0; i < _items.size(); i++) {
    Object item = _items.get(i);
    // On the first run, initialize reflection methods for object
    if (idMethod == null) {
      Class obj = item.getClass();
      idMethod = obj.getMethod(_idMethod, new Class[]{});
      descMethod = obj.getMethod(_descMethod, new Class[]{});
    }
    // invoke Methods
    String id = (String) idMethod.invoke(item, new Object[]{});
    String name = (String) descMethod.invoke(item, new Object[]{});

    SelectItem selectItem = new SelectItem();
    selectItem.setLabel(name);
    selectItem.setValue(id.toString());
    items.add(selectItem);
  }
  return items;
}

Comments (1)

Compartmental Syndrome

I had my legs operated due a compartment syndrome!!! you should be asking your self … what fuck does compartment syndrome mean????
Compartment syndrome is very common in runners, footballers, usually in high level athelets like me!!hehehehehehe… our muscles are covered by a layer called faschia, compartment syndrome occurrs when the muscle tries to swell up bigger than the faschia, hence a pressure is put on the muscle, therefore a terrible pain will be felt, in my case it occurred  on anterior tibial muscle, this is the most common place to have it.
My surgery was yesterday, I was operated by Dr. Marcelo Castro from Hcor in Sao Paulo Brazil, the surgery toke about 40 minutes, to release the pressure he just cut open the faschia, and poof, I got better!!! I’ll be ready to back to phisical activities within a month, I am looking after to back to a football match and play without fell any pain.
I’d like to thank the doctor Marcelo Castro and your team for the great job realised.

 

Compartmental Syndrome OperationMy legs after operation

I had my legs operated due a compartmental syndrome!!! you should be asking yourself … what fuck does compartmental syndrome mean????

Compartment syndrome is very common in runners, footballers, usually in high level athletes like me!! LOL… our muscles are covered by a layer called faschia, compartment syndrome occurs when the muscle tries to swell up bigger than the faschia, hence a pressure is put on the muscle, therefore a terrible pain will be felt, in my case it occurred  on anterior tibial muscle, this is the most common place to occurs it.

My surgery was yesterday, I was operated by Dr. Marcelo Padro from HCor in Sao Paulo – Brazil, the surgery took about 40 minutes, to release the pressure he just cut open the faschia, and poof, I got better!!! I’ll be ready to back to phisical activities within a month, I am looking forward to play  a football match without felling any pain.

I’d like to thank the doctor Marcelo Prado and his team for the great job performed.
Leandro Abite

Leave a Comment

Running os commands from Oracle

I was looking for a way to execute os commands from Oracle, all solutions I found were very complex, had to create a C program or had to use the package dbms_scheduler to execute a job, besides to be complex these solutions, have to develop diferents codes for diferents operational systems… so I solved this problem using java without to use the package dbms_scheduler , the Java class executes the command in runtime, this solution works in Oracle 8,9,10 and 11 with all operation systems supported by Oracle. Basicly you need to follow 3 steps:

  1. Grant some java privileges to your Oracle database user.
  2. Compile java class on Oracle database.
  3. Create a Oracle function with the call to java class.

STEP 1 – GRANTS TO YOUR DATABASE USER

Logged as SYS execute the commands bellow:

SQL> EXEC dbms_java.grant_permission('<USERNAME>',
                                     'SYS:java.lang.RuntimePermission',
                                     'writeFileDescriptor', '');

SQL> EXEC dbms_java.grant_permission('<USERNAME>',
                                     'SYS:java.lang.RuntimePermission',
                                     'readFileDescriptor', '');

SQL> EXEC dbms_java.grant_permission('<USERNAME>',
                                     'SYS:java.io.FilePermission',
                                     '/bin/sh', 'execute');

Example:

SQL> EXEC dbms_java.grant_permission('labite',
                                     'SYS:java.lang.RuntimePermission',
                                     'writeFileDescriptor', '');

SQL> EXEC dbms_java.grant_permission('labite',
                                     'SYS:java.lang.RuntimePermission',
                                     'readFileDescriptor', '');

SQL> EXEC dbms_java.grant_permission('labite',
                                     'SYS:java.io.FilePermission',
                                     '/bin/sh', 'execute');

STEP 2 – CREATE AND COMPILE JAVA CLASS

Logged with your database user execute the command bellow:

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "OSCommand" AS
  /*
    Created by: Leandro Abite
    email: leandroabite@yahoo.com.br
  */
  import java.io.*;

  public class OSCommand {

    public static String executeCommand(String command) {
      StringBuffer sb = new StringBuffer();
      try {
        String[] finalCommand;
        if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
          finalCommand = new String[4];
          finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
          finalCommand[1] = "/y";
          finalCommand[2] = "/c";
          finalCommand[3] = command;
        } else { // Linux or Unix System
          finalCommand = new String[3];
          finalCommand[0] = "/bin/sh";
          finalCommand[1] = "-c";
          finalCommand[2] = command;
        }
        // Execute the command...
        final Process pr = Runtime.getRuntime().exec(finalCommand);
        // Capture output from STDOUT
        BufferedReader br_in = null;
        try {
          br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
          String buff = null;
          while ((buff = br_in.readLine()) != null) {
            sb.append(buff);
            sb.append("\n");
            try {Thread.sleep(100); } catch(Exception e) {}
          }
          br_in.close();
        } catch (IOException ioe) {
          System.out.println("Error printing process output.");
          ioe.printStackTrace();
        } finally {
          try {
            br_in.close();
          } catch (Exception ex) {}
        }
        // Capture output from STDERR
        BufferedReader br_err = null;
        try {
          br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
          String buff = null;
          while ((buff = br_err.readLine()) != null) {
            sb.append("stderr:");
            sb.append(buff);
            sb.append("\n");
            try {Thread.sleep(100); } catch(Exception e) {}
          }
          br_err.close();
        } catch (IOException ioe) {
          System.out.println("Error printing execution errors.");
          ioe.printStackTrace();
        } finally {
          try {
            br_err.close();
          } catch (Exception ex) {}
        }
      }
      catch (Exception ex) {
        System.out.println(ex.getLocalizedMessage());
      }
      return sb.toString();
    }
  };
/

STEP 3 – CREATE FUNCTION TO CALL JAVA

CREATE OR REPLACE FUNCTION oscomm (p_command   IN   VARCHAR2) RETURN VARCHAR2
  AS LANGUAGE JAVA NAME
    'OSCommand.executeCommand (java.lang.String) return java.lang.String';
/

EXECUTION TEST

To execute the os command you have to pass the complete path of the command:

it is wrong!!!!!
 SQL> select oscomm('ls -ltr') from dual;
 OSCOMM('LS-LTR')
 --------------------------------------------------------------------------------
 stderr:/bin/sh: ls: No such file or directory
it is right!!!!!
 SQL> select oscomm('/bin/ls -ltr') from dual;
 OSCOMM('/BIN/LS-LTR')
 --------------------------------------------------------------------------------
 total 44
 -rw-r--r-- 1 oracle oinstall  8385 Sep 11  1998 init.ora
 -rw-r--r-- 1 oracle oinstall 12920 May  3  2001 initdw.ora
 -rw-r----- 1 oracle oinstall    24 Nov 19 17:31 lkDB01
 -rw-rw---- 1 oracle oinstall  1544 Nov 19 17:31 hc_db01.dat
 -rw-r----- 1 oracle oinstall  1536 Feb 10 17:08 orapwdb01
 -rw-r----- 1 oracle oinstall  2560 Feb 18 12:42 spfiledb01.ora

Comments (1)

Lançamento do Teiid – Metamatrix open source

teiid_logo_200pxA Red Hat acaba de disponibilizar a versão open source do Metamatrix a ferramenta de data service lider de mercado, o nome da versão free é Teiid o site oficial é www.teiid.org, no site além de baixar a ferramenta tem documentações e tutoriais!!!

Teiid é uma ferramenta para fazer integração de fontes de dados distintas, com o uso desta é possível fazer a integração entre Oracle, SQLServer, Arquivo Texto, WebService e Etc.. E o melhor de tudo isso!!! é  possível fazer em minutos sem nenhuma linha de codigo, os dados consolidados podem ser acessados por JDBC, ODBC ou Webservices através de um banco de dados virtual.

80% dos projetos de sucesso SOA em grandes empresas fizeram o uso de alguma ferramenta de Data Service, O Metamatrix é o lider disparado entre as ferramentas de Data Service disponiveis no mercado, e agora temos a versão open source desta excelente ferramenta.

Leave a Comment