Liferay 6.2 installation on JBoss 7.1 (Not Bundle)

Posted on

I used this document to install the Liferay War within JBoss 7.1.1

// Installation path of JBoss Not Bundle
JBOSS_HOME=/u02/liferay_portal/jboss-as-7.1.1.Final
export JBOSS_HOME

// Dependency directory, copy all jar into this folder
mkdir -p $JBOSS_HOME/modules/com/liferay/portal/main
// copy .jar
cp *.jar $JBOSS_HOME/modules/com/liferay/portal/main

// I use Oracle as Database, so move the jar file into the folder
cp ojdbc6.jar $JBOSS_HOME/modules/com/liferay/portal/main

//Edit / Create module.xml file 
vim $JBOSS_HOME/modules/com/liferay/portal/main/module.xml

// Append <resource-root path="ojdbc6.jar" /> into the resources tag
<?xml version="1.0"?>
<module xmlns="urn:jboss:module:1.0" name="com.liferay.portal">
    <resources>
        <resource-root path="ojdbc6.jar" />
        <resource-root path="portal-service.jar" />
        <resource-root path="portlet.jar" />
    </resources>
    <dependencies>
        <module name="javax.api" />
        <module name="javax.mail.api" />
        <module name="javax.servlet.api" />
        <module name="javax.servlet.jsp.api" />
        <module name="javax.transaction.api" />
    </dependencies>
</module>

// Edit $JBOSS_HOME/standalone/configuration/standalone.xml
vim $JBOSS_HOME/standalone/configuration/standalone.xml

// Append into
<system-properties>
    <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8" />
    <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true" />
</system-properties>

// Edit timeout parameter
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
    <deployment-scanner deployment-timeout="240" path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000"/>
</subsystem>

// Search urn:jboss:domain:security:1.1 and edit.
<security-domain name="PortalRealm">
    <authentication>
        <login-module code="com.liferay.portal.security.jaas.PortalLoginModule" flag="required" />
    </authentication>
</security-domain>

// Disable welcome root // replace all the tag.
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <virtual-server name="default-host" enable-welcome-root="false">
       <alias name="localhost" />
       <alias name="example.com" />
    </virtual-server>
<configuration>
<jsp-configuration development="true" />
</configuration>
</subsystem>

// Edit file $JBOSS_HOME/bin/standalone.conf
vim $JBOSS_HOME/bin/standalone.conf
// At the begining of the file, i have installed 3 JDK version so i need to setup.
JAVA_HOME="/u01/installers/jdk1.7.0_79"
JBOSS_HOME="/u02/liferay_portal/jboss-as-7.1.1.Final"

// At the end of the file
JAVA_OPTS="$JAVA_OPTS -Xms8g -Xmx8g -XX:MaxPermSize=3g -XX:+UseParNewGC -XX:ParallelGCThreads=2"
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true  -Duser.timezone=GMT"

// Edit the JAVA options.
vim $JBOSS_HOME/modules/sun/jdk/main/module.xml

// Insert into paths
<path name="com/sun/crypto" />
<path name="com/sun/crypto/provider" />
<path name="com/sun/image/codec/jpeg" />
<path name="com/sun/org/apache/xml/internal/resolver" />
<path name="com/sun/org/apache/xml/internal/resolver/tools" />

// Setup the Oracle datasource.
//en $JBOSS_HOME/standalone/configuration/standalone.xml search urn:jboss:domain:datasources:1.0

vim $JBOSS_HOME/standalone/configuration/standalone.xml

Replace all the tah with

<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:/jdbc/LiferayPool" pool-name="LiferayPool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:oracle:thin:@192.168.2.231:1521:xe</connection-url>
<driver>ojdbc6</driver>
<pool>
            <min-pool-size>16</min-pool-size>
            <max-pool-size>32</max-pool-size>            
        </pool>
<security>
<user-name>oracle_user</user-name>
<password>oracle_password</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="ojdbc6" module="com.liferay.portal"/>
</drivers>
</datasources>

// edit or create portal-ext.properties one path below the JBOSS_HOME
jdbc.default.jndi.name=java:jdbc/LiferayPool

// Edit
vim $JBOSS_HOME/bin/server.policy

// Append
grant {
    permission java.security.AllPermission;
};

// Updating JSF version, copy the new version of JSF into.
cp jsf-api-2.1.21.jar $JBOSS_HOME/modules/javax/faces/api/main/

// Edit
vim $JBOSS_HOME/modules/javax/faces/api/main/module.xml

// The resource should look like.
<!-- <resource-root path="jboss-jsf-api_2.1_spec-2.0.1.Final.jar"/>-->
<resource-root path="jsf-api-2.1.21.jar"/>

// Append into dependences.
<module name="com.sun.jsf-impl"/>

// Copy the JSF implementation jar
cp jsf-impl-2.1.21.jar $JBOSS_HOME/modules/com/sun/jsf-impl/main/

// Edit $JBOSS_HOME/modules/com/sun/jsf-impl/main/module.xml
vim $JBOSS_HOME/modules/com/sun/jsf-impl/main/module.xml

// The resource should looks like.
<!--<resource-root path="jsf-impl-2.1.7-jbossorg-2.jar"/>-->
<resource-root path="jsf-impl-2.1.21.jar"/>

// Update LiferayFaces
// Copy the jar
cp weld-core-1.1.10.Final.jar $JBOSS_HOME/modules/org/jboss/weld/core/main/

// Edit $JBOSS_HOME/modules/org/jboss/weld/core/main/module.xml
vim $JBOSS_HOME/modules/org/jboss/weld/core/main/module.xml

// tag resources will be like
<!-- <resource-root path="weld-core-1.1.5.AS71.Final.jar"/>-->
<resource-root path="weld-core-1.1.10.Final.jar"/>

// Deploy the Liferay WAR and create folder
mkdir -p $JBOSS_HOME/standalone/deployments/ROOT.war
// Unzip liferay war
unzip liferay-portal-6.2-ce-ga4-20150416163831865.war -d $JBOSS_HOME/standalone/deployments/ROOT.war

// Edit WEB-INF/jboss-deployment-structure.xml inside the extracted file.

<module meta-inf="export" name="com.liferay.portal">
    <imports>
        <include path="META-INF" />
    </imports>
</module>

// Create a empy file to start a new liferay deployLiferay
vim $JBOSS_HOME/standalone/deployments/ROOT.war.dodeploy

// Remove eclipselink for use hibernate as JPA
cd $JBOSS_HOME/standalone/deployments/ROOT.war/WEB-INF/lib
rm eclipselink.jar

Install Wireless Lenovo G410 Fedora 22 Broadcom Corporation BCM43142

Posted on

Instalar Repositorio.

yum localinstall –nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Instalar paquetes

yum update
yum install broadcom-wl
yum install kmod-wl

Ejecutar

modprobe wl

Screenshot from 2015-10-07 21-27-35

JBoss 7 HTTPS Using SSL Certificate / Certificado SSL

Posted on

Setup of enviroment variables

export JAVA_HOME=/usr/java/jdk1.7.1-8
export JBOSS_HOME=/opt/liferay-portal-6.2-ce-ga4/jboss-7.1.1/

Directory where will be store the cert

mkdir -p /opt/security/keystore
cd /opt/security/keystore

Next lines are use for create a new local cert and import into the local keystore

keytool -v -genkey -alias jbosskeys -keyalg RSA -keysize 1024 -keystore jbosskeys.jks -keypass changeit -storepass changeit -validity 365 -dname "CN=localhost"

keytool -v -export -rfc -alias jbosskeys -file localfile.crt -keystore jbosskeys.jks -keypass changeit -storepass changeit

keytool -v -import -keypass changeit -noprompt -trustcacerts -alias localhost -file localfile.crt -keystore cacerts.jks -storepass changeit

Setup JBoss configuration

cd $JBOSS_HOME
vim bin/standalone.conf

Add to the editing file

JAVA_OPTS="$JAVA_OPTS \-Djavax.net.ssl.keyStorePassword=changeit"
JAVA_OPTS="$JAVA_OPTS \-Djavax.net.ssl.trustStorePassword=changeit"
JAVA_OPTS="$JAVA_OPTS \-Djavax.net.ssl.keyStoreType=JKS"
JAVA_OPTS="$JAVA_OPTS \-Djavax.net.ssl.trustStoreType=JKS"
JAVA_OPTS="$JAVA_OPTS \-DCLIENT_KEY_ALIAS=jbosskeys"
JAVA_OPTS="$JAVA_OPTS \-Djavax.net.ssl.keyStore=/opt/security/keystore/jbosskeys.jks"
JAVA_OPTS="$JAVA_OPTS \-Djavax.net.ssl.trustStore=/opt/security/keystore/cacerts.jks"

Edit

vim standalone/configuration/standalone.xml

Add next to the http scheme

<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="connect" secure="true">
 <ssl name="ssl"
     protocol="TLSv1"
     password="changeit"
     certificate-key-file="/opt/security/keystore/jbosskeys.jks"
     ca-certificate-file="/opt/security/keystore/cacerts.jks"
     verify-client="true o false" />
</connector>
vim standalone/configuration/standalone.xml
<socket-binding name="connect" port="12000"/>

Base on the http://www.thegeekstuff.com/2014/03/install-jboss-ssl/ guide.

Asignar @GeneratedValue y @SequenceGenerator a secuencias Oracle luego de Remapear

Posted on

Luego de remapear entidades, todas aquellas tablas que usen llave primaria asignada mediante secuencia, necesitar las anotaciones @GeneratedValue y @SequenceGenerator para poder ser asignadas, cuando el remapeo es constante y y son muchas tablas, lo mejor es un script que asigne todas las secuencias, basadas en que la secuencia de base de datos se llame igual a la tabla usando el prefijo SQ_, usted puede cambiar la lógica según sus necesidades.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.io.IOUtils;

/**
 * Utiliadad para asignar las anotaciondes de las secuencias a todas las
 * entidades.
 *
 * @author Andres Rivera
 * @version 1.0
 * @since JDK1.7
 */
public class ValueHibernateSequenceGenerator {

    public static void main(String... args) {
        System.out.println("Iniciando" + new Date());
        try {
            String rutaBase = "C:\\Users\\Andres Rivera\\Documents\\NetBeansProjects\\SApplication\\SAApplication-ejb\\src\\main\\java\\co\\gov\\empresa\\proyecto\\model\\entity";
            String anotacion;

            File folder = new File(rutaBase);
            File[] listOfFiles = folder.listFiles();

            for (File file : listOfFiles) {
                anotacion = "    @GeneratedValue(generator = \"!SQLNOMBRE\")\n"
                          + "    @SequenceGenerator(name = \"!SQLNOMBRE\", sequenceName = \"!SQLNOMBRE\")";
                if (file.isFile() && file.getName().endsWith("java")) {
                    System.out.println("Analizando archivo : " + file.getName());
                    InputStream in;
                    List<String> lines;
                    in = new FileInputStream(file);
                    lines = IOUtils.readLines(in);
                    int counter = 0;
                    int indexAnotation = 0;
                    String tabla = "";
                    List<String> finalLines = new ArrayList<String>();
                    for (String line : lines) {
                        finalLines.add(line);
                        if (line.contains("Table(name =")) {
                            tabla = line.split("\"")[1];
                            if (tabla.length() > 27) {
                                tabla = tabla.substring(0, 27);
                            }
                        }
                        if (line.contains("@Id")) {
                            anotacion = anotacion.replaceAll("!SQLNOMBRE", ("SQ_" + tabla).toLowerCase());
                            finalLines.add(anotacion);
                            indexAnotation = counter;
                        }
                        counter++;
                    }

                    System.out.println("Entidad:" + tabla + " en " + indexAnotation + " - " + anotacion);
                    for (String g : finalLines) {
                        System.out.println(g);
                    }

                    FileWriter f0 = new FileWriter(file, false);
                    boolean valImp = false;
                    for (String g : finalLines) {
                        if (!valImp) {
                            if (g.startsWith("import javax.persistence")) {
                                f0.write("import javax.persistence.GeneratedValue;\n");
                                f0.write("import javax.persistence.SequenceGenerator;\n");
                                valImp = true;
                            }
                        }
                        f0.write(g + "\n");
                    }
                    f0.close();
                }
            }
        } catch (Exception e) {
            System.out.println("Error generando secuencias, causado por "+e);
        }
        System.out.println("Finalizado " + new Date());
    }
}

Java Dinamyc WS Client using Apache AXIS and Complex Types.

Posted on Actualizado enn

I have to invoke a WebService that return a complex type (Object), and i tried to use Apache CXF but the server that constains the wsdl uses https with a SSL certificate expired so I had a lot of problems.

This is the solution i have found.

in the pom.xml

<dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency> 
 
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
  
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
       
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-wsdl4j</artifactId>
            <version>1.2</version>
        </dependency>

My DynamicWSClient.java class

import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.LinkedHashMap;
import javax.xml.namespace.QName;
import javax.xml.rpc.NamespaceConstants;

import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;

/**
 * Cliente para llamado dinamico de servicio web.
 *
 *
 * @author Andres Rivera
 * @since JDK1.6
 * @version 1.0
 */
public class DynamicWSClient implements Serializable {

    String address;
    String namespaceURI;
    private Class complexClass;

    /**
     * Constructor dynamic ws client.
     *
     * @param address
     * @param namespaceURI
     * @param serviceName
     */
    public DynamicWSClient(String address, String namespaceURI) {
        this.address = address;
        this.namespaceURI = namespaceURI;
    }
    /**
     * Contructor para llamado de WS con Marshall a clase compleja.
     * @param address
     * @param namespaceURI
     * @param complexClass 
     */
    public DynamicWSClient(String address, String namespaceURI,Class complexClass) {
        this.address = address;
        this.namespaceURI = namespaceURI;
        this.complexClass=complexClass;
    }
    
    /**
     * Invocar servicio web.
     *
     * @param operation
     * @param parameters
     * @return
     * @throws java.lang.Exception
     */
    public Object invoke(String operation, LinkedHashMap<String, Object> parameters) throws Exception {
        Object salida = invoke(operation, parameters, null);
        return salida;
    }

    /**
     * Invocar servicio web con extraccion de indice en la posicion indicada.
     *
     * @param operation
     * @param parameters
     * @param complexObject
     * @return
     * @throws java.lang.Exception
     */
    public Object invoke(String operation, LinkedHashMap<String, Object> parameters, Boolean complexObject) throws Exception {
        Object salida = null;
        
        try {
            String soapAction = this.namespaceURI + operation;

            Service service = new Service();
            Call call = (Call) service.createCall();

            call.setEncodingStyle(NamespaceConstants.NSURI_SOAP_ENCODING);
            call.setTargetEndpointAddress(new URL(this.address));
            call.setOperationName(new QName(this.namespaceURI, operation));

            //call.setReturnType(XMLType.XSD_STRING);
            int parametersSize = 0;
            for (String paramKey : parameters.keySet()) {
                call.addParameter(new QName(this.namespaceURI, paramKey), XMLType.XSD_STRING, ParameterMode.IN);
                parametersSize++;
            }

            call.setSOAPActionURI(soapAction);

            Object[] paramValues = new Object[parametersSize];

            int counter = 0;
            for (String paramKey : parameters.keySet()) {                                                           
                paramValues[counter] = parameters.get(paramKey);
                counter++;
            }

            if(complexObject==null){
                complexObject=false;
            }
            
            if (!complexObject) {
                salida = call.invoke(paramValues);
            } else {
                if(this.getComplexClass()==null){
                    throw new Exception("Debe definir el Tipo de clase Compleja, para poder realizar el Marshall.");
                }
                else{
                    QName qNameRes = new QName(this.namespaceURI, operation+"Response");
                    call.registerTypeMapping(this.getComplexClass(), qNameRes, new BeanSerializerFactory(this.getComplexClass(), qNameRes), new BeanDeserializerFactory(this.getComplexClass(),qNameRes));                
                    call.setReturnClass(this.getComplexClass());
                    call.setReturnType(qNameRes);
                    salida = call.invoke(paramValues);
                }
            }
        } catch (ServiceException | MalformedURLException | RemoteException e) {
            throw e;
        }
        return salida;
    }

    public Class getComplexClass() {
        return complexClass;
    }
    public void setComplexClass(Class complexClass) {
        this.complexClass = complexClass;
    }
}

And the class that uses this one, but first we need to defined the class that will be Serialized, for my example is EntidadPersonaInformacionBasica

import java.io.Serializable;
import java.util.Date;
import org.apache.axis.description.TypeDesc;
import javax.xml.namespace.QName;
import org.apache.axis.description.ElementDesc;
import org.apache.axis.encoding.Serializer;
import org.apache.axis.encoding.Deserializer;
import org.apache.axis.encoding.ser.BeanSerializer;
import org.apache.axis.encoding.ser.BeanDeserializer;
/**
 *
 * @author Andres Rivera
 */
public class EntidadPersonaInformacionBasica implements Serializable {

    private String codigoTipoIdentificacion;
    private Date fechaNacimiento;

    // Type metadata
    private static final TypeDesc typeDesc
            = new TypeDesc(EntidadPersonaInformacionBasica.class, true);

    static {
        typeDesc.setXmlType(new QName("http://site.com/","SeleccionarProcesoResponse"));

        ElementDesc elemField;
        elemField = new ElementDesc();
        elemField.setFieldName("codigoTipoIdentificacion");
        elemField.setXmlName(new QName("http://site.com/", "CodigoTipoIdentificacion"));
        elemField.setXmlType(new QName("http://www.w3.org/2001/XMLSchema", "string"));
        elemField.setNillable(false);
        typeDesc.addFieldDesc(elemField);

        elemField = new ElementDesc();
        elemField.setFieldName("fechaNacimiento");
        elemField.setXmlName(new QName("http://site.com/","FechaNacimiento"));
        elemField.setXmlType(new QName("http://www.w3.org/2001/XMLSchema", "dateTime"));
        elemField.setNillable(false);
        typeDesc.addFieldDesc(elemField);
         
        /// All the definition for each field.


    }

    /**
     * Return type metadata object
     *
     * @return
     */
    public static TypeDesc getTypeDesc() {
        return typeDesc;
    }

    /**
     * Get Custom Serializer
     *
     * @param mechType
     * @param _javaType
     * @param _xmlType
     * @return
     */
    public static Serializer getSerializer(
            String mechType,
            Class _javaType,
            QName _xmlType) {
        return new BeanSerializer(_javaType, _xmlType, typeDesc);
    }

    /**
     * Get Custom Deserializer
     *
     * @param mechType
     * @param _javaType
     * @param _xmlType
     * @return
     */
    public static Deserializer getDeserializer(
            String mechType,
            Class _javaType,
            QName _xmlType) {
        return new BeanDeserializer(_javaType, _xmlType, typeDesc);
    }

    public String getCodigoTipoIdentificacion() {
        return codigoTipoIdentificacion;
    }

    public void setCodigoTipoIdentificacion(String codigoTipoIdentificacion) {
        this.codigoTipoIdentificacion = codigoTipoIdentificacion;
    }

    public Date getFechaNacimiento() {
        return fechaNacimiento;
    }

    public void setFechaNacimiento(Date fechaNacimiento) {
        this.fechaNacimiento = fechaNacimiento;
    }
    // .......................
    // You should implement all getter and setters
}

And now the code that invoke the Service.

EntidadPersonaInformacionBasica informacion = null;
DynamicWSClient wsCliente = new DynamicWSClient("https://site.com.co/service.wsld", "http://site.com/");
LinkedHashMap<String, Object> paramsInfoBasica = new LinkedHashMap<>();
paramsInfoBasica.put("UsuarioServicio", "usuario");
paramsInfoBasica.put("ContrasenaServicio", "clave");
paramsInfoBasica.put("IdProceso", "1234");
wsCliente.setComplexClass(EntidadPersonaInformacionBasica.class);
informacion = (EntidadPersonaInformacionBasica) wsCliente.invoke("SeleccionarProceso", paramsInfoBasica, true);

All the data returned by the service method is now serialized into informacion field

NVIDIA 9500GT Ubuntu Samsung B2230 Monitor change to 1920×1080 Resolution.

Posted on

If you have face this problem, you should run this command with root user.

xrandr --newmode "1920x1080_60VGA" 148.35 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync
xrandr --verbose --addmode DVI-I-1 1920x1080_60VGA
xrandr --verbose --output DVI-I-1 --mode 1920x1080_60VGA

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Posted on

Detailed message sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

When you are getting this error trying to work with SSL Certificates in WebServices, its probably because your JRE does not recognize the root certificate authority, and your Glassfish server neither.

You need to follow this steps to solve this problem:

1. Go to your webservice through any explorer, i recommend Firefox, the navigator prompt about security of conection, add exception, next in Cert State go to More Details, in the details tab export to Certificate X.509(PEM) (Default option) with the .cer extension.

2. Now you need to add that certificate to your system, just open it and validate.

3. Open a new console and go to $JAVA_HOME/jre/lib/security.

4. Execute this command as root or administrator:
keytool -import -noprompt -trustcacerts -alias ALIAS -file YOURDOWNLOADEDCERT.cer -keystore cacerts -storepass changeit

5. You are going to get the following message: Certificate was added to keystore.

6. Now you need to add the same file to your cacerts in the Glassfish server, first locate your glassfish and go to the path: $GLASSFISH_SERVER/glassfish/domains/domain1/config.

7. And again execute the same keytool command but this time changing the cacerts name to cacerts.jks.

8. Next reload your glassfish server and the problem should be solved.