viernes, 3 de febrero de 2012

Integrar Glassfish con Apache Web Server

1.- Descargamos el MOD JK
http://mirrors.sonic.net/apache//tomcat/tomcat-connectors/jk/

2.- Copiar el mod_jk.so a /usr/lib64/httpd/modules
3.- Dar permisos al mod_jk.so
chmod 775 mod_jk.so

4.- Copiar el workers.properties a /etc/httpd/conf

------------------------------------
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
------------------------------------

5.- En el workers.properties cambiar el host

6.- Modificar el httpd.conf y agregar estas lineas al comienzo

_____________________
LoadModule jk_module modules/mod_jk.so

JkWorkersFile "/etc/httpd/conf/workers.properties"

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T %U %q"

# Send all jsp requests to GlassFish
JkMount /*.jsp worker1

# Send all /TestWeb/ requests to GlassFish
JkMount /TestWeb/* worker1
___________________________

7.- Agregamos el siguiente listener en el glassfish
asadmin --user admin --host localhost --port 4848 create-http-listener --listeneraddress 0.0.0.0 --listenerport 8009 --defaultvs server jk-connector-8009

8.- Activamos el listener

asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true

9.- Cambiar el Owner del /var/www/html a tu usuario con el que utilizas el levantas el Glassfish
chown -R usrgf /var/www/html

10.- Reiniciar el apache y ver el log
/var/log/httpd
/etc/init.d/httpd start

lunes, 30 de marzo de 2009

Creacion de Reportes en Excel con POI

bueno para la creación de un reporte en excel utilizaremos la api de apache POI http://poi.apache.org/ en este pequeño ejemplo documentado se podrá observar la creación de un reporte para 2 versiones de Excel.

Veamos la creación del reporte para el primer caso usando versiones de excel menores a la del 2007 utilizando POI HSSF:


package com.kaox.poi;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

import org.apache.poi.hssf.record.formula.functions.Cell;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

public class Ejemplo {
public static void main(String[] args)
{
try
{
//Creamos el libro Excel
HSSFWorkbook wb = new HSSFWorkbook();

//Creamos una nueva hoja
HSSFSheet sheet = wb.createSheet("Clientes");

//Se crea una fila dentro de la hoja
HSSFRow row = sheet.createRow(1);

//Se crea una celda
HSSFCell cell=null;

HSSFCellStyle cellStyle1 = wb.createCellStyle();
cellStyle1.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
cellStyle1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

HSSFCellStyle cellStyle2 = wb.createCellStyle();
cellStyle2.setFillForegroundColor(HSSFColor.WHITE.index);
cellStyle2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

//Creamos celdas de varios tipos
row.createCell(1).setCellValue("usersId");
row.createCell(2).setCellValue("rut");
row.createCell(3).setCellValue("passwordCreation");
row.createCell(4).setCellValue("status");
row.createCell(5).setCellValue("genero");
row.createCell(6).setCellValue("estadoCivil");
row.createCell(7).setCellValue("empresa");

for(int i=2;i<20;i++){

row = sheet.createRow(i);

//Creamos celdas con dos colores d fondos distintos

if(i%2==0){
cell =row.createCell(1);
cell.setCellValue(3502);
cell.setCellStyle(cellStyle1);

cell =row.createCell(2);
cell.setCellValue("01/09/2009");
cell.setCellStyle(cellStyle1);

cell =row.createCell(3);
cell.setCellValue("19/11/2007 05:31:58 p.m.");
cell.setCellStyle(cellStyle1);

cell =row.createCell(4);
cell.setCellValue(1);
cell.setCellStyle(cellStyle1);

cell =row.createCell(5);
cell.setCellValue("M");
cell.setCellStyle(cellStyle1);

cell =row.createCell(6);
cell.setCellValue("P");
cell.setCellStyle(cellStyle1);

cell =row.createCell(7);
cell.setCellValue("");
cell.setCellStyle(cellStyle1);
}else{
cell =row.createCell(1);
cell.setCellValue(3502);
cell.setCellStyle(cellStyle2);

cell =row.createCell(2);
cell.setCellValue("01/09/2009");
cell.setCellStyle(cellStyle2);

cell =row.createCell(3);
cell.setCellValue("19/11/2007 05:31:58 p.m.");
cell.setCellStyle(cellStyle2);

cell =row.createCell(4);
cell.setCellValue(1);
cell.setCellStyle(cellStyle2);

cell =row.createCell(5);
cell.setCellValue("M");
cell.setCellStyle(cellStyle2);

cell =row.createCell(6);
cell.setCellValue("P");
cell.setCellStyle(cellStyle2);

cell =row.createCell(7);
cell.setCellValue("");
cell.setCellStyle(cellStyle2);
}
}

//Escribimos los resultados a un fichero Excel
FileOutputStream fileOut = new FileOutputStream("C:/libro1.xls");

wb.write(fileOut);
fileOut.close();
}
catch(IOException e)
{
System.err.println("Error al escribir el archivo");
}

}

}


El resultado de ejecutar correr el ejemplo nos saldra algo asi:


jueves, 19 de marzo de 2009

IText: plantilla de reporte

¿Como podemos crear plantillas de reportes en iText?

Bueno aca les indico una forma. Para empezar creamos la clase MyReport.java y extendemos