星期四, 九月 06, 2012

Primefaces fileDownload Component Issue.txt


I think there is a good way to fix such issue when using p:fileDownload component as below description.

Previously, I used below code in jsf page:


       


Used below method to download the generted report:
public StreamedContent getGeneratedInsertReport(){
//Generate report code...
StreamedContent file = new DefaultStreamedContent(...)
return file;
}

But in the progress of generating the report, when meet error, the error cannot be added to

FacesMessage. Or when meet a exception, also we cannot handle to display the infomation to page.


After researching, there is a possible way to implement it. It is that add ActionListener to the

CommandButton:


       


In the ManagedBean, I added validation code to this action listener:

public void generatedReportCheck(ActionEvent ae){
    List tempList = null;
    //Code
//tempList=...
   
    validateListSize(tempList);
if (exceedExcelMax){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage

(FacesMessage.SEVERITY_ERROR, MessageProvider.getMessage("error.report.exportExcel.exceedRecords",

MAX_EXCEL_SIZE), ""));
   
throw new AbortProcessingException();
}
     }

星期五, 八月 10, 2012

Smb File Utility Using Problem

When we using the Java CIFS Client Liberay (JCIFI), we may ignore a very important problem when writing file to remote share folder.

Notes: JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java. CIFS is the standard file sharing protocol on the Microsoft Windows platform (e.g. Map Network Drive ...). This client is used extensively in production on large Intranets. 


Usually, we use below code to new a instance of SmbFile:

   SmbFile sFile = new SmbFile(smbpath)

But when writing a file the destination path, this may caused when the file is wring in progress, the file can also be read, but the read a incomplete file is not correct. We'd better to set the file locked.

   SmbFile sFile = new SmbFile(destinationPath, "", null, SmbFile.FILE_NO_SHARE);

When use copyTo(SmbFile) method, we'd better to use such code to make the file locked also. 


星期二, 七月 31, 2012

Menu Redirect Prompt when developing in JSF+Primefaces +JQuery_20120731.txt

Enverionment:
JSF2 + Primefaces
Used JSF menu.

1. Import embeded jquery from primefaces.



2. jQuery('ul.wijmo-wijmenu-child > li > a.wijmo-wijmenu-link') get all the sub menu items
#{msg['label.confirmRedirectInCreateSubOrderDialog']} used for reading prompt message from resource properties.


                jQuery.noConflict();
              
                var menuOriginalOnclickEvent = [];
                jQuery('ul.wijmo-wijmenu-child > li > a.wijmo-wijmenu-link').each(function(index){              
                    menuOriginalOnclickEvent[index]=jQuery(this).attr('onclick');          
                    jQuery(this).unbind('click').removeAttr('onclick');
                    jQuery(this).bind('click', function(){if(confirm('#{msg['label.confirmRedirectInCreateSubOrderDialog']}')) { menuOriginalOnclickEvent[index]();}else{return false} });
                });
                

星期二, 六月 05, 2012

Configuration to access by HTTPS with SSL in Apache HTTP




Part One, https enable with SSL

1. eable module by remove "#"
 in file conf/http.conf:
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf

2. Modify conf/extra/httpd-ssl.conf:
SSLCertificateFile "C:/Apache2.2/conf/server.crt"
SSLCertificateKeyFile "C:/Apache2.2/conf/server.key"

3. Generate certificate and key file for Server Side:
server.key:
D:\local\apache2\bin\openssl genrsa -out server.key 1024
server.csr:
D:\local\apache2\bin>openssl req -new -out server.csr -key server.key -config ..\conf\openssl.cnf
Input the asked information.

4. Generate Signture Certificate  for CA Side:
Primary key, ca.key:
D:\local\apache2\bin\openssl genrsa -out ca.key 1024

Use CA to generate self signature certificate:
D:\local\apache2\bin\openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config ..\conf\openssl.cnf
Here may asked to input some information. Please input the infor. Common Name is server domain, if is local, it is local IP.

Uae CA to generate website serser signature certificate
D:\local\apache2\bin\openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config ..\conf\openssl.cnf
Here will enconter error. Create demoCA in current folder, and create below files:
index.txt, with content is serial:serial 01, other is null and create a folder: newcerts. then run agin.it will generate server.crt.

5. copy server.key and server.crt(not server.csr) to conf/

Part Two
Redirect http to https access
1. LoadModule rewrite_module modules/mod_rewrite.so

2. Add below configuration
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Part Three (optional) --- For 64Bit OS
1. System Event error log in system lever when start up with above configurations

The Apache service named  reported the following error:
>>> SSLSessionCache: Invalid argument: size has to be >= 8192 bytes     .

It is caused by line 62(original)
#SSLSessionCache "shmcb:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"
It recognized 86 as cache size. So we need to use another folder for such log. eg:
#SSLSessionCache "shmcb:C:/Program Files/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"

2. Error in log folder:
Init: SSLPassPhraseDialog builtin is not supported on Win32 (key file xxxx/conf/ssl/jfdscert.key)
Resolution:
a) Put "#" in front of SSLPassPhraseDialog to comment out the line.
b) remove the Pass Phrase for server.key with below command:
openssl rsa -in server.key.org -out server.key
Then use this one instead.

Part Three
Verify the private key and certificate whether can match.

View the certificate modulus using the following command:
openssl x509 -noout -text -in certfile -modulus
or
openssl x509 -noout -text -in certfile -modulus | openssl md5

View the key using the following command:
openssl rsa -noout -text -in keyfile -modulus
or
openssl rsa -noout -text -in keyfile -modulus | openssl md5


星期一, 五月 14, 2012

Jboss 5/6 Reading/File Encoding Problem


Jboss 5/6 Reading file encoding problem:


For Unicode file Reading, modify the file: Jboss_home\bin\run.conf.bat (havn't tested in the Linux Env. for run.conf)


Add below sample code marked red color:


"...
rem # Warn when resolving remote XML DTDs or schemas.
set "JAVA_OPTS=%JAVA_OPTS% -Dorg.jboss.resolver.warning=true -Dfile.encoding=utf-8"
...
"