Technical Blog about Weblogic Portal,Webcenter,BPM and SOA Suite,Spring Framework issues and solutions - for Beginners, Intermediate professionals. In feature we will make it for Advanced level professionals also.
Thursday, April 18, 2013
Sunday, April 14, 2013
Saturday, April 13, 2013
Filetype(MIME type) check Using JMimeMagic
Checking the file extension is not a very strong way to determine the file type. A more robust solution is possible with theJMimeMagic library. JMimeMagic is a Java library (LGLP licence) that retrieves file and stream mime types by checking magic headers.
See the below implementation of JMimeMagic to check the file MIME type
private String VIRUS_FILE_MIME_TYPE = "???";
private String RTF_FILE_MIME_TYPE = "rtf";
private String MSWORD_FILE_MIME_TYPE = "msword";
private String MIME_TYPE_NOTAVAILABLE = "text/plain";
//file extension check
byte[] buf = new byte[1024];
if(multipartFile.getBytes().length > 100){
if(match != null) {
mimeType = match.getMimeType();
}
logger.debug("MagicMatch mimeType(contenttype):"+mimeType);
String mimeTypeFirstSubStr="";
String mimeTypeSecondSubStr="";
if(mimeType != null && mimeType.length() >0){
int index = mimeType.indexOf("/");
if(index >0){
// In File MIMETYPE first part (ex. in application/rtf first part application and rtf is second part)
mimeTypeFirstSubStr = mimeType.substring(0, index);
// In File MIMETYPE second part
mimeTypeSecondSubStr = mimeType.substring(index+1, mimeType.length());
}
}
String contentType = multipartFile.getContentType();
logger.debug("File extension content type:"+contentType);
String contentTypeFirstSubStr="";
String contentTypeSecondSubStr="";
if(contentType != null && contentType.length() >0){
int index = contentType.indexOf("/");
if(index >0){
// In File CONTENTTYPE first part (ex. in application/rtf first part application and rtf is second part)
contentTypeFirstSubStr = contentType.substring(0, index);
// In File CONTENTTYPE second part
contentTypeSecondSubStr = contentType.substring(index+1, contentType.length());
}
}
logger.info("File original content type "+ mimeType + " extension content type:"+contentType);
//MIME TYPE check logic
if(mimeType != null && !"".equalsIgnoreCase(mimeType) && !MIME_TYPE_NOTAVAILABLE.equalsIgnoreCase(mimeType)){
if(!"".equalsIgnoreCase(mimeTypeFirstSubStr)&&!"".equalsIgnoreCase(contentTypeFirstSubStr)){
if(!mimeTypeFirstSubStr.equalsIgnoreCase(contentTypeFirstSubStr)){
if((!"".equalsIgnoreCase(mimeTypeSecondSubStr) && !"".equalsIgnoreCase(contentTypeSecondSubStr)) && (!mimeTypeSecondSubStr.equalsIgnoreCase(contentTypeSecondSubStr))){
//If RTF file is converted to MSWORD or MSWORD file is converted to RTF
if(!(RTF_FILE_MIME_TYPE.equalsIgnoreCase(mimeTypeSecondSubStr) && MSWORD_FILE_MIME_TYPE.equalsIgnoreCase(contentTypeSecondSubStr)) &&
!(MSWORD_FILE_MIME_TYPE.equalsIgnoreCase(mimeTypeSecondSubStr) && RTF_FILE_MIME_TYPE.equalsIgnoreCase(contentTypeSecondSubStr))){
notAllowedFile = true;
}
}
}
//For virus files
}else if(mimeType != null && !"".equalsIgnoreCase(mimeType) && VIRUS_FILE_MIME_TYPE.equalsIgnoreCase(mimeType)){
notAllowedFile = true;
}
}
if(notAllowedFile){
String message = String.valueOf(XMLConfigurationManager.getInstance().getConfig().getList("CustomerMessage.Errors.DocNotAllowedFileTypeMsg"));
message = message.substring(1,message.length()-1);
customerMessageService.setErrorMessage(message);
}
See the below implementation of JMimeMagic to check the file MIME type
private String VIRUS_FILE_MIME_TYPE = "???";
private String RTF_FILE_MIME_TYPE = "rtf";
private String MSWORD_FILE_MIME_TYPE = "msword";
private String MIME_TYPE_NOTAVAILABLE = "text/plain";
//file extension check
byte[] buf = new byte[1024];
if(multipartFile.getBytes().length > 100){
fileIS.read(buf, 0, 100);
}else{
fileIS.read(buf, 0, multipartFile.getBytes().length);
}
MagicMatch match = null;
String mimeType = null;
try{
match = Magic.getMagicMatch(buf, false);
} catch (MagicParseException mpe){
logger.error("MagicParseException-->"+mpe);
} catch (MagicMatchNotFoundException mmf){
logger.error("MagicMatchNotFoundException-->"+mmf);
} catch (MagicException me){
logger.error("MagicException-->"+me);
}catch (Exception e){
logger.error("Magic Exception-->"+e);
}
if(match != null) {
mimeType = match.getMimeType();
}
logger.debug("MagicMatch mimeType(contenttype):"+mimeType);
String mimeTypeFirstSubStr="";
String mimeTypeSecondSubStr="";
if(mimeType != null && mimeType.length() >0){
int index = mimeType.indexOf("/");
if(index >0){
// In File MIMETYPE first part (ex. in application/rtf first part application and rtf is second part)
mimeTypeFirstSubStr = mimeType.substring(0, index);
// In File MIMETYPE second part
mimeTypeSecondSubStr = mimeType.substring(index+1, mimeType.length());
}
}
String contentType = multipartFile.getContentType();
logger.debug("File extension content type:"+contentType);
String contentTypeFirstSubStr="";
String contentTypeSecondSubStr="";
if(contentType != null && contentType.length() >0){
int index = contentType.indexOf("/");
if(index >0){
// In File CONTENTTYPE first part (ex. in application/rtf first part application and rtf is second part)
contentTypeFirstSubStr = contentType.substring(0, index);
// In File CONTENTTYPE second part
contentTypeSecondSubStr = contentType.substring(index+1, contentType.length());
}
}
logger.info("File original content type "+ mimeType + " extension content type:"+contentType);
//MIME TYPE check logic
if(mimeType != null && !"".equalsIgnoreCase(mimeType) && !MIME_TYPE_NOTAVAILABLE.equalsIgnoreCase(mimeType)){
if(!"".equalsIgnoreCase(mimeTypeFirstSubStr)&&!"".equalsIgnoreCase(contentTypeFirstSubStr)){
if(!mimeTypeFirstSubStr.equalsIgnoreCase(contentTypeFirstSubStr)){
if((!"".equalsIgnoreCase(mimeTypeSecondSubStr) && !"".equalsIgnoreCase(contentTypeSecondSubStr)) && (!mimeTypeSecondSubStr.equalsIgnoreCase(contentTypeSecondSubStr))){
//If RTF file is converted to MSWORD or MSWORD file is converted to RTF
if(!(RTF_FILE_MIME_TYPE.equalsIgnoreCase(mimeTypeSecondSubStr) && MSWORD_FILE_MIME_TYPE.equalsIgnoreCase(contentTypeSecondSubStr)) &&
!(MSWORD_FILE_MIME_TYPE.equalsIgnoreCase(mimeTypeSecondSubStr) && RTF_FILE_MIME_TYPE.equalsIgnoreCase(contentTypeSecondSubStr))){
notAllowedFile = true;
}
}
}
//For virus files
}else if(mimeType != null && !"".equalsIgnoreCase(mimeType) && VIRUS_FILE_MIME_TYPE.equalsIgnoreCase(mimeType)){
notAllowedFile = true;
}
}
if(notAllowedFile){
String message = String.valueOf(XMLConfigurationManager.getInstance().getConfig().getList("CustomerMessage.Errors.DocNotAllowedFileTypeMsg"));
message = message.substring(1,message.length()-1);
customerMessageService.setErrorMessage(message);
}
Sorting problem with Displaytag + Webflow
Please modify the display tag implementation like below .
excludedParams="*"
defaultsort="1" defaultorder="ascending" sort="page" requestURI="${myURL}_eventId=redisplay" pagesize="${fileupload_table_pagesize}">There is -no- problem with this. Sorting links will work fine, paging links will work fine, no javascript, no hassle, just plain elegant code.
It Solves the below errorError
Caused by:
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0):
Field or property 'd' cannot be found on object of type
'com.test..model.entity.Application'
at
org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208)
Sunday, April 29, 2012
JSR 168 VS JSR 286
Simple format
The major improvements from JSR 168, (as noted in the JSR 286 document)
- Events – enabling a portlet to send and receive events and perform state changes or send further events as a result of processing an event.
- Public render parameters – allowing portlets to share parameters with other portlets.
- Resource serving – provides the ability for a portlet to serve a resource.
- Portlet filter – allowing on -the -fly transformations of information in both the request to and the response from a portlet.
Apart for these major differences,there are many minor changes like
- getNamespace() – this method gives unique value for the portlet window
- getWindowsID()- this method returns portlet window ID
- Portlet Cookies- Can beset on particular phase and retrieved on the subsequest phase
- Additions to PortletRequestDispatcher
- Portlet container runtime options
- New CSS classess
JSR168 vs JSR 286
JSR-168 – What is missing?
• inter-portlet communication
• serving non-html resources (pdf, doc, images etc.)
• contributing javascript or css to , using cookies
• proper support for common web frameworks
• portlet filters
Inter-portlet communication
• only supported within the same portlet application
using session attributes
• target portlets will only “see” messages during next
render request
• portlets cannot (should not) update their state during a
render request: “event” handling not really possible
Serving non-html resources
• A portlet can only render html fragments
• Have to fallback/delegate to the servlet container
• Requires coordination between portlet and servlet
Contributing to , setting cookies
• javascript or css can only be embedded withing the
content markup; no body onLoad handling hooks
• API forbids adding cookies: only client side setting of
cookies using javascript is possible
Proper support for common web frameworks
• Most web frameworks are Servlet API only
• Servlet dispatching not supported from processAction
• Needs Portals Bridges or similar solutions
• JSTL support very limited:
ut value=”<%= ((FooBean)renderRequest.getSession()
.getAttribute("fooBean",PortletSession.PORTLET_SCOPE))
.getBeanValue() %>"/>
JSR-286 - Coming up
• Portlet Specification 2.0
• Expert Group started January 2006
• 1st Early Public Draft released August 2006
covering most, but not yet all, planned features
• 2nd Early Public Draft November 2006
covering all features
• 1st Public Draft December 2006
• Final Release May 2007
• RI will be done under Apache Pluto umbrella with help
from a group at University of Jena
• Binary compatible with JSR-168
• Alignment with J2EE 1.4, WSRP 2.0
• Portlet coordination
• Public render parameters
• Shared session state across applications (maybe)
• Portlet events
• Resource serving
• AJAX support
• Portlet filters
• Extended cache support
• Improved support for common web frameworks
• ... and more
• inter-portlet communication
• serving non-html resources (pdf, doc, images etc.)
• contributing javascript or css to , using cookies
• proper support for common web frameworks
• portlet filters
Inter-portlet communication
• only supported within the same portlet application
using session attributes
• target portlets will only “see” messages during next
render request
• portlets cannot (should not) update their state during a
render request: “event” handling not really possible
Serving non-html resources
• A portlet can only render html fragments
• Have to fallback/delegate to the servlet container
• Requires coordination between portlet and servlet
Contributing to , setting cookies
• javascript or css can only be embedded withing the
content markup; no body onLoad handling hooks
• API forbids adding cookies: only client side setting of
cookies using javascript is possible
Proper support for common web frameworks
• Most web frameworks are Servlet API only
• Servlet dispatching not supported from processAction
• Needs Portals Bridges or similar solutions
• JSTL support very limited:
.getAttribute("fooBean",PortletSession.PORTLET_SCOPE))
.getBeanValue() %>"/>
JSR-286 - Coming up
• Portlet Specification 2.0
• Expert Group started January 2006
• 1st Early Public Draft released August 2006
covering most, but not yet all, planned features
• 2nd Early Public Draft November 2006
covering all features
• 1st Public Draft December 2006
• Final Release May 2007
• RI will be done under Apache Pluto umbrella with help
from a group at University of Jena
• Binary compatible with JSR-168
• Alignment with J2EE 1.4, WSRP 2.0
• Portlet coordination
• Public render parameters
• Shared session state across applications (maybe)
• Portlet events
• Resource serving
• AJAX support
• Portlet filters
• Extended cache support
• Improved support for common web frameworks
• ... and more
Wednesday, November 2, 2011
WebCenter Quick Install Guide
You can get all the software from the following link - http://www.oracle.com/technology/software/products/middleware/htdocs/fmw_11_download.html
1.Oracle Database 10g Express
2.Repository Creation Utility (RCU 11.1.1.2.0) - used to create the necessary repositories
3.WebLogic Server (10.3.2) - wls1032_linux32.bin
4.Web Tier Utilities (11.1.1.2.0) - Oracle Apache installer
5.WebCenter Suite (11.1.1.2.0) - WebCenter installer
6.Content Management for WebCenter (10.1.3.5.1) - directory with Content Server install - to be used during WebCenter installation
Before you Continue...
Check out George Maggessy's great post about installation, with lots of screenshots that help visualize the steps below.
1.Oracle Database 10g Express
2.Repository Creation Utility (RCU 11.1.1.2.0) - used to create the necessary repositories
3.WebLogic Server (10.3.2) - wls1032_linux32.bin
4.Web Tier Utilities (11.1.1.2.0) - Oracle Apache installer
5.WebCenter Suite (11.1.1.2.0) - WebCenter installer
6.Content Management for WebCenter (10.1.3.5.1) - directory with Content Server install - to be used during WebCenter installation
Before you Continue...
Check out George Maggessy's great post about installation, with lots of screenshots that help visualize the steps below.
Monday, August 15, 2011
Missing em.ear file while installing 11gR2 in Windows XP
I downloaded the files from OTN with following names:
win64_11gR2_database_1of2.zip
win64_11gR2_database_2of2.zip
Extracted both into the SAME directory with these names
C:\Oracle\Disk1
C:\Oracle\Disk2
Started the installation from C:\Oracle\Disk1\database\setup.exe
And the Installation failed due to file not found of {C:\app\11g\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\WFMLRSVCApp.ear and some other files too}
I went through the http://download.oracle.com/docs/cd/E11882_01/install.112/e10843/toc.htm but there was nothing which mentioned where or how to rename the directories.
All my downloaded files were in the same directory but still I was facing the problem.
As both zip files contained database folder so I couldn't override the files.
I solved the file not found issue by coping all the folders under C:\Oracle\Disk2\database\stage\Components to C:\Oracle\Disk1\database\stage\Components
After restarting the installation it went like a charm and without any issues.
Thanks,
Venkata Sarvabatla
win64_11gR2_database_1of2.zip
win64_11gR2_database_2of2.zip
Extracted both into the SAME directory with these names
C:\Oracle\Disk1
C:\Oracle\Disk2
Started the installation from C:\Oracle\Disk1\database\setup.exe
And the Installation failed due to file not found of {C:\app\11g\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\WFMLRSVCApp.ear and some other files too}
I went through the http://download.oracle.com/docs/cd/E11882_01/install.112/e10843/toc.htm but there was nothing which mentioned where or how to rename the directories.
All my downloaded files were in the same directory but still I was facing the problem.
As both zip files contained database folder so I couldn't override the files.
I solved the file not found issue by coping all the folders under C:\Oracle\Disk2\database\stage\Components to C:\Oracle\Disk1\database\stage\Components
After restarting the installation it went like a charm and without any issues.
Thanks,
Venkata Sarvabatla
Friday, August 12, 2011
administrator password reset procedure in weblogic
hi,
I have followed the following steps on WLS 11g and I was able to start the AdminServer with new username/password.
Steps:
1: open a command prompt.
2: go to the %BEA_HOME%/user_projects/domains/base_domain/bin dir
cd %BEA_HOME%/user_projects/domains/base_domain/bin
3: run the setDomainEnv.cmd file.
4: This will bring you to base_domain dir. Now run the following command:
java weblogic.security.utils.AdminAccount weblogic welcome1 .
Do not forget to use the last "." which is going to inform the utility to create the DefaultAuthenticatorInit.ldift in the Domain_Home dir.
5: Also try to use a password with atleast 8 chars and with at least one numeric digit.
6: then rename the DefaultAuthenticatorInit.ldift that is already present in the %Domain_Home %/security dir to
DefaultAuthenticatorInit_old.ldift and place the newly generated DefaultAuthenticatorInit.ldift file in the %Domain_Home %/security dir.
7: Also delete the %Domain_Home %/servers/AdminServer/security/boot.properties file.
8: Rename the %Domain_Home %/servers/AdminServer/data/ldap/DefaultAuthenticatormyrealmInit.initialized file to DefaultAuthenticatormyrealmInit_old.initialized
9: Now you can try to start the Admin Server with through the command prompt using startWeblogic.cmd file.
Let me know if this resolves the issue or not.
I have followed the following steps on WLS 11g and I was able to start the AdminServer with new username/password.
Steps:
1: open a command prompt.
2: go to the %BEA_HOME%/user_projects/domains/base_domain/bin dir
cd %BEA_HOME%/user_projects/domains/base_domain/bin
3: run the setDomainEnv.cmd file.
4: This will bring you to base_domain dir. Now run the following command:
java weblogic.security.utils.AdminAccount weblogic welcome1 .
Do not forget to use the last "." which is going to inform the utility to create the DefaultAuthenticatorInit.ldift in the Domain_Home dir.
5: Also try to use a password with atleast 8 chars and with at least one numeric digit.
6: then rename the DefaultAuthenticatorInit.ldift that is already present in the %Domain_Home %/security dir to
DefaultAuthenticatorInit_old.ldift and place the newly generated DefaultAuthenticatorInit.ldift file in the %Domain_Home %/security dir.
7: Also delete the %Domain_Home %/servers/AdminServer/security/boot.properties file.
8: Rename the %Domain_Home %/servers/AdminServer/data/ldap/DefaultAuthenticatormyrealmInit.initialized file to DefaultAuthenticatormyrealmInit_old.initialized
9: Now you can try to start the Admin Server with through the command prompt using startWeblogic.cmd file.
Let me know if this resolves the issue or not.
Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
Error :
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Answer :
Cause of the error is : Heap size is larger than your computer's physical memory.
try with the below heap sizes
set DEFAULT_MEM_ARGS=-Xms1024m -Xmx1024m
set PORT_MEM_ARGS=-Xms768m -Xmx1536m
if "%JAVA_VENDOR%" == "Oracle" goto OracleJVM
set DEFAULT_MEM_ARGS=%DEFAULT_MEM_ARGS% -XX:PermSize=256m -XX:MaxPermSize=256m
set PORT_MEM_ARGS=%PORT_MEM_ARGS% -XX:PermSize=256m -XX:MaxPermSize=512m
see the below link also :
http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Answer :
Cause of the error is : Heap size is larger than your computer's physical memory.
try with the below heap sizes
set DEFAULT_MEM_ARGS=-Xms1024m -Xmx1024m
set PORT_MEM_ARGS=-Xms768m -Xmx1536m
if "%JAVA_VENDOR%" == "Oracle" goto OracleJVM
set DEFAULT_MEM_ARGS=%DEFAULT_MEM_ARGS% -XX:PermSize=256m -XX:MaxPermSize=256m
set PORT_MEM_ARGS=%PORT_MEM_ARGS% -XX:PermSize=256m -XX:MaxPermSize=512m
see the below link also :
http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html
Wednesday, August 10, 2011
Difference between JSR 168 and JSR 286 portlets
Java Portlet spefication168 (v1.0) has very basic portlet porgramming model and had lot of limitations for portlet development. Java Portlet spefication286 (v2.0) was developed to overcome the shortcomings on v1.0 specs(JSR 168) such as:
1. Inter portlet communicaiton (IPC) - IPC through events and public render parameters
2. Support for WSRP 2.0
3. Public render paremeters - Allows portlets to share parameters with other portlets.
4. Portlet filters and listeners.
5. Resource serving - Provide ability for portlets to server a resource
6. AJAX support
Subscribe to:
Posts (Atom)