Friday, September 28, 2012

Wednesday, September 26, 2012

Setting Environment variables and System properties for Tomcat Server


Setting Environment variables and System properties for Tomcat Server

Windows Environment:


Create a file called setenv.bat in tomcat bin directory
Example: tomacta/bin/ setenv.bat
Environment variables setting:
set <OptinName>=<option value>
Example:
set JAVA_OPTS=-Xms256m -Xmx512m -XX:MaxPermSize=256m
 System Properties Settings:
set JAVA_OPTS =-D<propertyName>=<propertyValue>
Example:
set "JRE_HOME=%CATALINA_HOME%/jre1.6.0_20/win"
Note: When you already configure some java option  again you want configure some you have to do following like this
set JAVA_OPTS=% JAVA_OPTS% -Djava.awt.headless=true

The following is example for setting multiple properties. 
if multiple properties separated by space.

set JAVA_OPTIONS=%JAVA_OPTIONS% -Duser.timezone=UTC -Duser.timezone=GMT -Dicescrum_config_location=/path/to/dir/where/i/can/write/config.groovy -Xmx512m -XX:MaxPermSize=256m



Linux Environment:


Create a file called setenv.sh in tomacat bin directory
Example: tomcat/bin/setenv.sh
Environment variables setting:
export  <OptinName>=”<option value>”
Example:
export JAVA_OPTS=”-Xms256m -Xmx512m -XX:MaxPermSize=256m” 
 System Properties Settings:
export JAVA_OPTS =”-D<propertyName>=<propertyValue>”
Example:
export JAVA_OPTS =”-Djava.awt.headless=true
Note: When you already configure some java option again you want configure some you have to do following like this
export JAVA_OPTS=”$ JAVA_OPTS -Djava.awt.headless=true"

The following is example for setting multiple properties. 
if multiple properties separated by space.

export JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"



Liferay CAS Issues and Solutions


1)      PKIX problem
2)      SSL handshaking problem
3)      No name matching your domain  and (www.localhost.com) found


Click following link you can get cas-web and its related files
Download


Steps to configure CAS in Life ray 6.0.6
1)      Build cas-web war file from CAS server source code with your data base credentials and your liferay  algorithm(QueryDatabaseAuthenticationSHA1Base64.java)

2)      Copy the cas-web.war or cas-web  web application to tomcat webapps directory.


3)      Create SSL certificate using key tool.

4)      Change the tomcat server.xml file to enable SSL port or htts protocol.


5)      Make sure key store file location. (Ex: localhost.kestore) is available in your java bin folder.

6)      Modify the CASFilter.java and CASAutologinFilter.java files according to your requirement.


7)      Deploy portal

8)      Run tomcat server and test.
Problems Solutions:
1)      PKIX problem

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


1)      This problem occurred, because of trusted certificate not available in JRE. Means whatever we created SSL certificate not available in jre/lib/security folder.

2)      Generally when we create SSL certificate from the key tool after that we will export this SSL certificate to JRE. I.e. we will import into cascerts file (this is default file to import SSL certificates in JRE) this file is available in jre/lib/security folder.


Solution:

1)      Make sure created SSL certificate exported into cacerts file or not.

Procedure to know this:

Step: 1

Go to jre/lib/security

Compile InstallCert.java file by using following command.

Javac InsertCert.jva   

After successfully compile run java class by using following command.

Java InstallCert localhost:8443

We need pass domain name and secure port number that’s your https port.
If you get following output then SSL hand shaking is filed i.e. your certificate is not imported properly into cacerts file means that is not trusted certificate.

Loading KeyStore \jre6\lib\security\cacerts...
Opening connection to localhost:8443...
Starting SSL handshake...

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


Step: 2

When you get PKIX problem means SSL hand shaking is failed for your certificate. Then do the following thing.

When you get above step enter 1 and press enter. Then you will get the following output.



Enter certificate to add to trusted keystore or 'q' to quit: [1]
1

  Version: V3
  Subject: CN=localhost, OU=vidyayug, O=vyug, L= hyd, ST=ap, C=In
  Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5

  Key:  Sun RSA public key, 1024 bits
  modulus: 1129473579651954554552730664834664064459539051598864058082387115962631728819634110255367718769683451438528187
923246533854744470790959477657386037636238098777089479256059697784394926741427654735994678054030193662669088404706890444
59364523220747231216704221781747262219695262340353839314222273672957748320603247
  public exponent: 65537
  Validity: [From: Tue Dec 14 15:13:51 SGT 2010,
               To: Mon Mar 14 15:13:51 SGT 2011]
  Issuer: CN=yong mook kim, OU=mkyong, O=mkyong, L=puchong, ST=PJ, C=my
  SerialNumber: [    4d07192f]

]
  Algorithm: [SHA1withRSA]
  Signature:
0000: 38 E4 F4 D9 51 B1 5F C1   01 13 32 79 DE 97 26 58  8...Q._...2y..&X
0010: 13 08 F1 A0 33 DB B9 90   AF EE 9E AE B9 9B 68 7D  ....3.........h.
0020: DF E8 7D 79 9D 92 24 4A   76 C9 4C 28 DA 68 B0 62  ...y..$Jv.L(.h.b
0030: FF AB 27 03 5C DD 1F C8   77 A2 25 18 DF 0C DC FD  ..'.\...w.%.....
0040: D3 39 5D 18 B4 BA 4B 36   8C FD C5 80 FF F2 E3 4D  .9]...K6.......M
0050: 0A 28 57 B9 04 D8 25 F6   FB CA DA 13 0C 36 FB 02  .(W...%......6..
0060: 9A B3 B1 28 46 D1 8E C7   D9 1A 5B CE BB A6 6F FD  ...(F.....[...o.
0070: 6D F2 35 D9 95 43 6E 38   2A 56 E7 31 21 D9 F0 90  m.5..Cn8*V.1!...

]

Added certificate to keystore 'jssecacerts' using alias 'localhost-1'

If you get above output then your certificate trusted. Here we need identify one thing. Generally when we export SSL certificate by using key tool by default it will insert into cacert file. But here if you observe the above screen you can find jssecacers file. It will automatically create when we run above program.
 Enter q to quit this process.
Step: 3
Run again InstallCerts.java program to pass inputs domain and SSL port
Java InstallCert localhost:8443
If you get following output then SSL hand shaking is successful and your certificate added to jaascaserts file and it is trusted certificate. Here you will get message certificate is already trusted.












Here we need identify the CN=localhost   this is very important. whatever the CN name you need give in CAS settings. Otherwise you will get No Name matching to the URL .

20:42:38,109 ERROR [CommonUtils:294] java.security.cert.CertificateException: No name matching www.localhost.com found
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching www.localhost.com found


Note: So whatever the CN name that is only your CAS settings.

Assume if your CN name is local host then the following are the your CAS settings


So we have the solutions for
1)      PKIX
2)      No Name matching to your domain name
Still you are getting PKIX problem?
Make sure which jre your application server is using means JVM used by your server. here we need consider location of jre and version of jre.
Whatever the JRE your server is using in that make sure trusted certificate is available or not means run above whole process from this JRE location (jre/lib/security)
How to know which jre our server is using?
From Eclipse(Windows Environment):
Generally Eclipse will create JRE in  the following location:
C:/Program Files/Java
If you create server from Eclipse it will use eclipse generated default JRE until you mention new jre. i.e.
C:/Program Files/Java/jre
So that you need to export SSL certificate into this jre by using key tool or you can run above whole process from this location.
In Eclipse you can find which jre your server is using
Go to Windows>>Preferense>>Java>>Installed JRE’s

By Using Cygwin:
If you are running portal without Eclipse then you can find JRE that is used by your Server (Tomcat)
Run which java command in cygwin prompt.
The following screen will specify the location of java.
Go to That location and make sure SSL had shaking is successful for your domain.


If you run server from cygwin  prompt also you can know the JRE is used by your Server(Tomcat)
Run the following command form your server bin directory.
Use   ./startup.sh
The following screen shot wil tells you which jre is using. In this location you need to have trusted certificates.
Pure windows Environment
In windows environment serve generally use the JRE that is mentioned in JAVA_HOME environment variable.
That JRE server is using. In this JRE we have trusted certificates.

Note:
ü     Identify the JRE and make sure SSL hand shaking is successful in this location for yor domain. jre/lib/security  from this folder we will have InsertCert.java run this program and give the appropriate domain name and SSL  port number.


ü   Make sure where ever the CN name that should be your CAS settings.

Ex:  CN=localhost
Your CAS setting should use localhost only.





Monday, September 24, 2012

Plugin portlet Custom JSON Services

Plugin portlet Custom JSON Services:
1) Create Service.xml for you required Entity.
2) Run ant build-service
3) Run build-wsdd
4) Write required method in EntityServiceImpl.
5) Please check this method signature will created in EntityServiceUtil
6) Call the following URL to Access the custom method and this will return JSON array or JSON object.
7) http://127.0.0.1:8080/JSONTest-portlet/json/?serviceClassName=com.meera.test.service.SongServiceUtil&serviceMethodName=getSongObject&serviceParameters=[songId]&songId=2



Note: 127.0.0.1 this is your host Name
JSONTest-portlet this is context path of your portlet.


The Following is Example:
Plugin Portlet Name: JSONTest-portlet
Service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.meera.test">
<author>meera</author>
<namespace>meera</namespace>

<entity name="Song" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="songId" type="long" primary="true" />
<!-- Audit fields -->
<column name="songName" type="String" />
<column name="songDesc" type="String" />
</entity>
</service-builder>



Method Name: getSongObject(long songId)

package com.meera.test.service.impl;
public class SongServiceImpl extends SongServiceBaseImpl {
public Song getSongObject(long songId) throws SystemException{
return SongUtil.fetchByPrimaryKey(songId);

}
}
}


Note: above method auto generate method after run service builder.
Write this Java script in view.jsp

Dynamic JqGrid with JSON Data


Hi I am sharing integration of Jqgrid into liferay plugin potlet.

 Click The following link to down load JqGrid Portlet.
Download


1) Create plugin portlet using Liferay IDE
2) Write service.xml according to ypur requirement

<service-builder package-path="com.meera">
<author>meera</author>
<namespace>jqgrid</namespace>
<entity name="Invheader" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="invId" type="long" primary="true" />
<!-- Audit fields -->
<column name="name" type="String" />
<column name="ammount" type="long" />
<column name="tax" type="long" />
<column name="total" type="long" />
<column name="notes" type="String" />
</entity>
</service-builder>


3) run service builder and you will get related data bese service clasess.
4)write custom method in EntityLocalServiceImpl.java

public class InvheaderLocalServiceImpl extends InvheaderLocalServiceBaseImpl {

public List<Invheader> getAllRecords() throws SystemException{
return InvheaderUtil.findAll();

}
}


5) Run service builder with ant build-service or from IDE ant view you will get method in EntitylocalServiceUtil
6) Implement serveResource(.....) in portlet class in the following way

package com.test;

import java.io.IOException;
import java.util.List;

import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.meera.model.Invheader;
import com.meera.service.InvheaderLocalServiceUtil;

/**
 * Portlet implementation class JQGridAction
 */
public class JQGridAction extends MVCPortlet {

public void serveResource(
ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws IOException, PortletException {

String jspPage = resourceRequest.getParameter("name");
System.out.println("jspPage"+jspPage);
try {
List<Invheader> objectList=InvheaderLocalServiceUtil.getAllRecords();
JSONObject recordsjsonObject=JSONFactoryUtil.createJSONObject();
JSONArray rowjsonObject=null;
JSONObject cell=null;
JSONArray recordsjsonArray=JSONFactoryUtil.createJSONArray();
recordsjsonObject.put("page","1");
double total_pages = Math.ceil(objectList.size()/10);
recordsjsonObject.put("total",String.valueOf(total_pages));
recordsjsonObject.put("records ", String.valueOf(objectList.size()));
if(!objectList.isEmpty()){
for(int i=0;i<objectList.size();i++){

Invheader invheaderObject=objectList.get(i);
rowjsonObject=JSONFactoryUtil.createJSONArray();
cell=JSONFactoryUtil.createJSONObject();
rowjsonObject.put( String.valueOf(invheaderObject.getInvId()));
rowjsonObject.put(String.valueOf(invheaderObject.getName()));
rowjsonObject.put( String.valueOf(invheaderObject.getAmmount()));
rowjsonObject.put( String.valueOf(invheaderObject.getTax()));
rowjsonObject.put( String.valueOf(invheaderObject.getTotal()));
rowjsonObject.put( String.valueOf(invheaderObject.getNotes()));
//recordsjsonArray.put(String.valueOf(invheaderObject.getInvId()));
//
cell.put("id", String.valueOf(invheaderObject.getInvId()));
cell.put("cell",rowjsonObject);
recordsjsonArray.put(cell);

}
//recordsjsonObject.put("id",String.valueOf(invheaderObject.getInvId()));
recordsjsonObject.put("rows",recordsjsonArray);
}
resourceResponse.getWriter().print(recordsjsonObject.toString());
System.out.println(recordsjsonObject.toString());
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}



7) write view.jsp in the following way

Recent Posts

Recent Posts Widget

Popular Posts