Getting started with JACOB. An Example with Source Code

UPDATED: 28 December 2013
JACOB Library + jacob-project
The JACOB Project
JACOB stands for JAva COM Bridge. The JACOB project started in 1999 by Dan Adler. It allows java programs to make native calls to system. JACOB supports on window x86 and x64 based native call.

Well its very useful library, however there are very few support article available on internet. We'll first understand basic java program that uses JACOB library and interacts with windows program that allows COM bridge support.

What JACOB actually do?
JACOB creates ActiveXObject of program identified using Program ID, Version independent Program ID or CLSID (Class ID aka Globally Unique Identifier) Read more about How to find CLSID or Program ID of program?

First Program With JACOB
package javaQuery.jacob;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.LibraryLoader;
import com.jacob.com.Variant;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * @author vicky.thakor
 * @date 28th December, 2013
 * http://sourceforge.net/projects/jacob-project/
 * First Program to understand how to use JACOB library
 */
public class JACOBGettingStarted {

    public static void main(String[] args) {
        /**
         * `System.getProperty("os.arch")`
         * It'll tell us on which platform Java Program is executing. Based on that we'll load respective DLL file.
         * Placed under same folder of program file(.java/.class).
         */
        String libFile = System.getProperty("os.arch").equals("amd64") ? "jacob-1.17-x64.dll" : "jacob-1.17-x86.dll";
        try {
            /* Read DLL file*/
            InputStream inputStream = jacobExample.class.getResourceAsStream(libFile);
            /**
             *  Step 1: Create temporary file under <%user.home%>\AppData\Local\Temp\jacob.dll 
             *  Step 2: Write contents of `inputStream` to that temporary file.
             */
            File temporaryDll = File.createTempFile("jacob", ".dll");
            FileOutputStream outputStream = new FileOutputStream(temporaryDll);
            byte[] array = new byte[8192];
            for (int i = inputStream.read(array); i != -1; i = inputStream.read(array)) {
                outputStream.write(array, 0, i);
            }
            outputStream.close();
            /**
             * `System.setProperty(LibraryLoader.JACOB_DLL_PATH, temporaryDll.getAbsolutePath());`
             * Set System property same like setting java home path in system.
             * 
             * `LibraryLoader.loadJacobLibrary();`
             * Load JACOB library in current System.
             */
            System.setProperty(LibraryLoader.JACOB_DLL_PATH, temporaryDll.getAbsolutePath());
            LibraryLoader.loadJacobLibrary();

            /**
             * Create ActiveXComponent using CLSID. You can also use program id here.
             * Next line(commented line/compProgramID) shows you how you can create ActiveXComponent using ProgramID.
             */
            ActiveXComponent compCLSID = new ActiveXComponent("clsid:{00024500-0000-0000-C000-000000000046}");
            /*ActiveXComponent compProgramID = new ActiveXComponent("Excel.Application");*/

            System.out.println("The Library been loaded, and an activeX component been created");
            
            /**
             * This is function/method of Microsoft Excel to use it with COM bridge.
             * Excel methods and its use can be found on
             * http://msdn.microsoft.com/en-us/library/bb179167(v=office.12).aspx
             * 
             * Understand code:
             * 1. Make Excel visible
             * 2. Get workbook of excel object.
             * 3. Open 1test.xls1 file in excel
             */
            Dispatch.put(compCLSID, "Visible", new Variant(true));
            Dispatch workbook = compCLSID.getProperty("Workbooks").toDispatch();
            Dispatch.call(workbook, "Open", new Variant("D:\\test\\test.xls"));

            /* Temporary file will be removed after terminating-closing-ending the application-program */
            temporaryDll.deleteOnExit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Other Resources
1. JACOB Library
2. Microsoft Excel methods for COM bridge interaction
- For other Programs you've to Google it.

What's Next?
I'm gonna help you to learn How you can create your own DLL file for your customized system request and An applet example with source code. Well you've to wait for my next article. Subscribe to catch updates.

Other Resources:
Jacob + Visual Studio. Your custom .DLL to use in Java.

0 comments :


How to find CLSID or Program ID of program?

UPDATED:
Its very common for .Net guys but for Java Developer its hard as rocket science. I'm one of 'em until dig into it. This article for those who don't know how to find CLSID, Program ID and Version independent program ID.

All you need is one tool called OLE/COM Object Viewer by Microsoft. Its provided with Visual Studio but you don't have to download visual studio just to get OLE/COM Object Viewer. Its is standalone graphical utility which can be downloaded from free of cost.

Download : http://www.softpedia.com/get/System/System-Miscellaneous/OLE-COM-Object-Viewer.shtml

Step 1: You know what to do. Install it.

Step 2: Object Classes > All Objects

OLE/COM Object Viewer

Step 3: Find your program from hierarchy. Select application in right pane you'll find you required details.

OLE/COM Object Viewer

Its simple as that. All information you need to know about your program. Check out how you can interact with Windows program using java : Getting started with JACOB. An Example with Source Code



0 comments :


How to create Hibernate query log?

UPDATED: 23 December 2013

What is Hibernate?
Hibernate is framework that provides object oriented interaction with database. Now a days  it is used widely to handle large database.

If you are working behind large application which uses hibernate for all of its transaction, I think you might need to configure query log and tune up your hibernate criteria.

Use of hibernate with proper criteria/queries is like a life boat for application but amateur use of hibernate is like hole in life boat.

Problem: JOIN is one creates massive overload in hibernate criteria. To get your desired output you always use JOIN in your criteria. You should be careful while using JOIN in any of your hibernate criteria or queries (HQL).  Single JOIN will load tons of database records and create overhead on your application.

Why you need to configure query log?
For development purpose it will be very useful to track down each query execution through hibernate. I'm not talking about hibernate.show_sql property. It'll only show you query with ? but won't print actual input and output of that query.

We'll configure log4j to get input query parameter and output values. You should turn off this mechanism at production server of will create IO overhead on server.

Step 1: Creating log4j.properties file. I already created one for you all you need to do is place it in your project.
log4j.logger.org.hibernate=INFO
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
# Set the DatePattern
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd-HH-mm

# Set the append to false, should not overwrite
log4j.appender.FILE.Append=true

# Set the name of the file.
# It'll be created every minute with different filename(appnded with yyyy-MM-dd-HH-mm) and placed under log4j folder.
log4j.appender.FILE.File=log4j/QueryLog.log

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern= %d{HH:mm:ss} %-5p %c - %m%n
Step 2: Configure this log4j.properties file before you perform any database transaction (Select, Insert, Update, Delete). Note: Download log4j [http://www.findjar.com/jar/log4j/jars/log4j-1.2.15.jar.html]
import org.apache.log4j.PropertyConfigurator; // import required
/** 
  * In below code I placed log4j.properties as string. 
  * Its file path, I placed log4j.properties in root directory/default package. You need to change path. 
  * If you are working with web application place it in war folder for below code to work.
  */
PropertyConfigurator.configure("log4j.properties");
Output:
17:43:45 DEBUG org.hibernate.SQL - select this_.UID as UID0_0_, this_.FIRSTNAME as FIRSTNAME0_0_, this_.Lastname as Lastname0_0_ from user_master this_ where this_.UID=?
17:43:45 TRACE org.hibernate.type.IntegerType - binding '1' to parameter: 1
17:43:45 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
17:43:45 TRACE org.hibernate.type.IntegerType - returning '1' as column: UID0_0_
17:43:45 TRACE org.hibernate.type.StringType - returning 'Vicky' as column: FIRSTNAME0_0_
17:43:45 TRACE org.hibernate.type.StringType - returning 'Thakor' as column: Lastname0_0_
As you can see it shows what is value of input parameter where this_.UID=? with binding '1' to parameter: 1 and return values of fired query.

Conclusion: We have to be very careful about what we are trying to fetch from database and what will be fetched by frameworks. So configure it in your application and tune it up!

0 comments :


java.lang.SecurityException: JVM Shared, not allowed to set security manager

UPDATED: 21 December 2013
Java, Applet
I created custom security manager for Applet to get all permission. In below code I'm allowing applet to exit and its not good practice but situation driving me that way for while. I'm also searching for better option. If you guys have solution please comment it.
class customSecurityManager extends SecurityManager{
    SecurityManager original;

    customSecurityManager(SecurityManager original) {
      this.original = original;
    }

    /** Deny permission to exit the VM(uncomment line).*/
    public void checkExit(int status) {
      //throw(new SecurityException("Not allowed"));
    }

    /* Allow this security manager to be replaced,in fact allow pretty much everything. */
    public void checkPermission(Permission perm) {
    }

    public SecurityManager getOriginalSecurityManager() {
       return original;
    }
}
It works pretty well in many systems but one system was throwing an exception as follow...
java.lang.SecurityException: JVM Shared, not allowed to set security manager
 at sun.plugin2.applet.SecurityManagerHelper.checkPermissionHelper(Unknown Source)
 at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
 at java.lang.System.setSecurityManager0(Unknown Source)
 at java.lang.System.setSecurityManager(Unknown Source)
 at SecurityApplet.init(SecurityApplet.java:103)
 at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at j ava.lang.Thread.run(Unknown Source)
After doing lots of search over internet and trying different options finally found solution for applet. Loading applet in separate JVM did the job.
<applet>
...
<param name="separate_jvm" value="true">
...
</applet>

0 comments :


java.lang.IllegalStateException: More than the maximum number of request parameters (GET plus POST) for a single request ([512]) were detected.

UPDATED: 12 December 2013

This is very unusual error thrown by Jboss server. Error it self explain that you are passing more than 512 parameters in request. Which is not good practice but if situation drives you in that way. There is solution available for it.

"To change this limit, set the maxParameterCount attribute on the Connector." this message seems informative but actually its wrong message in case of JBoss 7 or may be in future versions.

Error message you've
java.lang.IllegalStateException: More than the maximum number of request parameters (GET plus POST) for a single request ([512]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
 org.apache.tomcat.util.http.Parameters.addParameter(Parameters.java:199)
 org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:383)
 org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:229)
 org.apache.catalina.connector.Request.parseParameters(Request.java:2874)
 org.apache.catalina.connector.Request.getParameter(Request.java:1291)
 org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:363)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
Solution:
We need to use org.apache.tomcat.util.http.* library to solve this error. You don't need to import or download this library. It already available in Jboss. All you need to increase value of Parameter Count.

Jboss 7
Step 1: Open standalone.xml file available in "jboss7\standalone\configuration" folder.
Step 2: Paste below code after </extensions> tag and change value as per your requirement.
<system-properties>
   <property name="org.apache.tomcat.util.http.Parameters.MAX_COUNT" value="2000"/>
</system-properties>
Jboss 6 or lower (I didn't try but it has to work in lower version of Jboss as suggested by informative message)
Step 1: Open standalone.xml file available in "jboss6\standalone\configuration" folder.
Step 2: Find connector tag same as follow and add maxParameterCount attribute.
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" maxParameterCount="1000" /> 

0 comments :


com.jacob.com.ComFailException: Can't get object clsid from progid

UPDATED: 03 December 2013
JACOB + jacob-project

Exception Stacktrace:
com.jacob.com.ComFailException: Can't get object clsid from progid
 at com.jacob.com.Dispatch.createInstanceNative(Native Method)
 at com.jacob.com.Dispatch.(Dispatch.java:99)
 at com.jacob.activeX.ActiveXComponent.(ActiveXComponent.java:58)
ActiveXComponent comp = new ActiveXComponent("ABCXYZ");
This exception thrown by JACOB library when you try to create ActiveXComponent. Its coming because you are trying to create ActiveXComponent of program that is not installed in your system.


Solution:
You need to find proper CLSID or ProgID or VersionIndependentProgID for your program. Lets create Microsoft Excel's ActiveXComponent
ActiveXComponent comp = new ActiveXComponent("clsid:{00024500-0000-0000-C000-000000000046}");
ActiveXComponent comp = new ActiveXComponent("Excel.Application.14");
ActiveXComponent comp = new ActiveXComponent("Excel.Application");
1. Create ActiveXComponent using CLSID.
2. Create ActiveXComponent using version specific program id.
3. Create ActiveXComponent using version independent program id.

If you want to find CLSID or ProgID or VersionIndependentProgID for your program. Download OLEViewer and browser Object Classes > All Objects


OLEViewer


0 comments :


GWT (Google Web Toolkit) review

UPDATED: 02 December 2013
GWT(Google Web Toolkit) project started by Google back in 2005 - 2006. Its an open source set of tools that allows web developers to build Javascript front-end applications in Java. It is licensed under the Apache License version 2.0. Now its enough talk about its history. Today will give review of GWT from level of programmer.

What drives me to write good part of GWT?
The only things I observed for good part of Google Web Toolkit. If there is something do comment for other viewer.

  • It converts whole front-end website in complex JavaScript code. Thats the best part of Google Web Toolkit. It create bunch of complex JavaScript code that event hard for you to understand. 
  • Provide table, tree structure and other stuff by just writing 30-40 lines of code. 

What drives me to write bad part of GWT?
Yeah, I'm eagerly waiting for this part to write. Only by converting front-end website into JavaScript doesn't mean its good for develop small or large application.

Web security
Converting front-end website into JavaScript not only thing provide security to website. Security always depends on quality code. Properly handled validation leads to secure website.

Hard to understand (Time Consumption Factor)
Its very hard for new developer to understand its flow. You need to train your developer for Google Web Toolkit. Can't find help on Google also.

Pain for developer (Time Consumption Factor)
Its my personal experience that sometime just for CSS change you've to compile whole code.

- You can't access localhost website running in eclipse from other machine. You need to compile and create war and have to up in server. [In JSP, Servlet, Struts, etc... you can access localhost website running in eclipse from other system directly. Not required to compile and up it in server]

- You can't use all java package at client level. Check link to see which class supported by Google Web Toolkit http://www.gwtproject.org/doc/latest/RefJreEmulation.html#Package_java_io

- In some case GWT store cache in browser and website stops working and throws unexpected errors. You need to clean history of browser to let it work.

- To use some library you have to configure tons of thing in it. To use simple JSON library you have to waste more than 2-3 hours. Sometime works and sometime compilation error for just JSON. So you can imagine how hard to use external libraries.

- Last but not least. You can't use jQuery directly.


Conclusion
I would recommend not to use Google Web Toolkit at all. Even Google is not using GWT for their wide range of products. You may find very rare companies working on GWT.

@Developer: Don't do Job or Work for GWT.
@Manager, @Company: Just throw GWT and start working on other technologies. That may save your time and can work on other features for your product.

0 comments :


jd-gui best Java Decompiler ever...

UPDATED: 19 November 2013
What is de-compiling?
Its a process of extracting original code from its compiled code ("*.class", "*.jar", "*.dll", etc... files).

Some of you may not know that any code which is not obfuscate can be de-compile. It sounds disappointing for the first time however helpful in some situation. It might possible your system gets crash but you uploaded yout jar bundle on web. So you can de-compile that code and get your original code back. Now lets move to the jd-gui Java Decompiler.

JD-GUI
JD-GUI is a standalone graphical utility that displays Java source codes of ".class",".jar" files. You can have your own free copy of jd-gui.

Features:
      1. Drag and drop file open.
      2. Search within code.
      3. Line number of code.
      4. Save Source file.
      5. Multi tab.

Download : http://jd.benow.ca/

jd-gui


For best practice open reference libraries and class files by drag and drop or by simply opening file from menubar. Methods using reference libraries or class file will be referenced by navigator itself. Methods/objects with underline is one whose reference available in navigator.

0 comments :


How to increase PermSize/MaxPermSize in JBoss?

UPDATED: 07 November 2013

Quick definition of PermSize:
The permanent generation is used to hold reflective data of the VM itself such as class objects and method objects. These reflective objects are allocated directly into the permanent generation, and it is sized independently from the other generations

If you are working around big Enterprise Application, you may face memory issues in Jboss. In order to solve this you need to increase JVM PermSize for Jboss. Lets see the steps to increase Jboss PermSize.

Note: I tested this settings under jboss-as-7.1.1.Final

For Windows:

Step 1:
Goto bin folder of Jboss

Step 2: Open standalone.conf.bat file in notepad or other editor.

Step 3: Find set "JAVA_OPTS=-Xms64M -Xmx512M -XX:MaxPermSize=256M" and change the MaxPermSize as per your requirement and save it.

Step 4: Restart the Jboss.


For Linux:

Step 1:
Goto bin folder of Jboss either terminal or places.

Step 2: Open standalone.conf file in gedit(Ubuntu) or in terminal.

Step 3: Find JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000" and change the MaxPermSize as per your requirement and save it.

Step 4: Restart the Jboss.

Jboss console log :
Caused by: java.lang.OutOfMemoryError: PermGen space
        at sun.misc.Unsafe.defineClass(Native Method) [rt.jar:1.6.0_24]
        at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:45) [rt.jar:1.6.0_24]
        at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:381) [rt.jar:1.6.0_24]
        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.6.0_24]
        at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:377) [rt.jar:1.6.0_24]
        at sun.reflect.MethodAccessorGenerator.generateMethod(MethodAccessorGenerator.java:59) [rt.jar:1.6.0_24]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:28) [rt.jar:1.6.0_24]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_24]
        at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_24]
        at net.sf.beanlib.provider.BeanPopulator.invokeMethodAsPrivileged(BeanPopulator.java:221) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.doit(BeanPopulator.java:194) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.processSetterMethod(BeanPopulator.java:172) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.populate(BeanPopulator.java:270) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.populateBean(ReplicatorTemplate.java:174) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:173) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate3.Hibernate3JavaBeanReplicator.replicateBean(Hibernate3JavaBeanReplicator.java:71) [beanlib-hibernate-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:125) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:120) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:224) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.doit(BeanPopulator.java:201) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.processSetterMethod(BeanPopulator.java:172) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.populate(BeanPopulator.java:270) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.populateBean(ReplicatorTemplate.java:174) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:173) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate3.Hibernate3JavaBeanReplicator.replicateBean(Hibernate3JavaBeanReplicator.java:71) [beanlib-hibernate-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:125) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:120) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:224) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate.HibernateBeanReplicator.copy(HibernateBeanReplicator.java:133) [beanlib-hibernate-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate.HibernateBeanReplicator.copy(HibernateBeanReplicator.java:111) [beanlib-hibernate-5.0.1beta.jar:]

0 comments :


Developer Info: If you are using jsupload and you do not need cross-domain, try version compiled with standard linker?

UPDATED: 01 November 2013
I worked around gwtupload plugin created by "Manolo Carrasco". Sample application : gwtupload custom package with sample application


I was getting same message popup so many time. I dig down and found the solution for this alert box with gwt environment. I haven't tried jsupload so it may not work for it.

Unable to auto submit the form, it seems your browser has security issues with this features.
Developer Info: If you are using jsupload and you do not need cross-domain, try version compiled with standard linker?

Solution: I checked my lib folder and found there are two jars of commons-io and commons-fileupload with different version. Old version that don't support gwtupload plugin's requirement. I removed old version of commons-io and commons-fileupload from lib folder and everything working fine.

0 comments :


How to attach MANIFEST.MF file in jar in/using Netbeans?

UPDATED: 30 October 2013

Step 1: Open build.xml file in notepad or other editor and paste below code within <project>...</project>
<target name="-pre-init">
        <property name="project.name" value="Name of your llibrary"/>
        <property name="version.num" value="1.4.1"/>
        <tstamp>
            <format pattern="yyyy-MM-dd HH:mm:ss z" property="NOW"></format>
        </tstamp>

    <!--
    <exec outputproperty="svna.version" executable="svnversion">
     <arg value="-c" />
     <redirector>
      <outputfilterchain>
       <tokenfilter>
        <replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
        <replaceregex pattern="M" replace="" flags="g"/>
       </tokenfilter>
      </outputfilterchain>
     </redirector>
    </exec>
    -->
        <manifest file="MANIFEST.MF">
            <attribute name="Codebase" value="*"/>           
            <attribute name="Permission" value="all-permissions"/>
            <attribute name="Application-Library-Allowable-Codebase" value="javaquery.com"/>
            <attribute name="Caller-Allowable-Codebase" value="www.javaquery.com javaquery.com"/>
            <attribute name="Application-Name" value="javaQuery"/>
            <attribute name="Bundle-Name" value="${project.name}"/>           
            <attribute name="Bundle-Version" value="${version.num}"/>
            <attribute name="Bundle-Date" value="${NOW}"/>
            <attribute name="Implementation-Title" value="${project.name}"/>
            <attribute name="Implementation-Version" value="${version.num}"/>
            <attribute name="Implementation-URL" value="http://www.javaquery.com"/>
            <!--<attribute name="Bundle-Revision" value="${svna.version}" />-->
        </manifest>
 </target>

Step 2: Edit your required details in attributes. Uncomment the SVN version code if you want to put SVN version details in MANIFEST.MF file

Step 3: Save build.xml file

Step 4: Set your project as main project in netbeans. Now Go to RUN > Clean and build main project

Step 5: Find your output jar file in dist folder of project.

Other Resources:
How to attach MANIFEST.MF file in jar in/using eclipse?
How to create .jar file in netbeans?

0 comments :


How to attach MANIFEST.MF file in jar in/using eclipse?

UPDATED: 23 October 2013
Every jar file you create using editor it explicitly attach MANIFEST.MF file in it. That contains basic information of that jar file. I was also generating jar file using editor regardless its MANIFEST.MF file. After major security changes in Java 1.7.0_45 its mandatory to specify some attribute in MANIFEST.MF in Applet jar. But its good practice to add this MANIFEST.MF file with proper information in it, whether its applet or simple jar file.

Step 1: Open up simple notepad or other text editor. Add your required attribute in it and save as "MANIFEST.MF" . Here is all attribute information of MANIFEST.MF file. This is my sample MANIFEST.MF file.
Manifest-Version: 1.0
Codebase: *
Permissions: all-permissions
Application-Library-Allowable-Codebase: *
Caller-Allowable-Codebase: *
Application-Name: Digital Certificate
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)

Step 2: Copy MANIFEST.MF file in your project's folder.

jar, applet, manifest, eclipse

Step 3: Right click on project / file and click on Export.

jar, applet, manifest, eclipse

Step 4: Select JAR file in dialog box and click Next.

jar, applet, manifest, eclipse

Step 5: Select your output file and its location. And click Next.

jar, applet, manifest, eclipse

Step 6: Click Next in JAR Packaging option.
Step 7: Select "Use existing manifest from workspace" and browse your MANIFEST.MF file and click on finish. 

jar, applet, manifest, eclipse

Other Resources:
How to attach MANIFEST.MF file in jar in/using Netbeans?

0 comments :


How to convert database rows to column in mssql?

UPDATED:
This time I decided to write informational article. This database operation used very rare in real time application however its important for us to keep our self up to date with technology. Many of you knows it very well and other don't. So this is revision for those who knows it and informational for newbie.

Note: This question was asked in interview of one of my friend. So just read it properly and may I'll help you out some day.

PIVOT
PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output.You can read more about on Microsoft website.

Lets come straight to the example. This is my basic table structure and its value.

mssql, database

We all do basic operation with simple query like below and will give you output as
SELECT
  gender,
  COUNT(*) AS 'count'
FROM
  user_master
GROUP BY
  gender

mssql, database

Now below query will convert your rows to column.
select Female as Female,Male as Male from
(select distinct gender, count(gender) as Total from user_master group by gender)as p
pivot 
(
max(Total)
for Gender in ( [Female],[Male]) 
)as pvt
mssql, database

0 comments :


This application will be blocked in a future Java security update because the JAR file manifest does not contain the Permissions attribute. Please contact the Publisher for more information.

UPDATED: 17 October 2013
Applet security


The new Java update "1.7.0_45" shows permission warning in applet. If you want to get rid of that warning you must have MANIFEST.MF file in your applet/jar with attribute called Permissions.

Sample MANIFEST.MF file
Manifest-Version: 1.0
Codebase: *
Permissions: all-permissions
Application-Library-Allowable-Codebase: *
Caller-Allowable-Codebase: *
Application-Name: Digital Certificate
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)

Other Resources:
How to attach MANIFEST.MF file in jar in/using eclipse?
How to attach MANIFEST.MF file in jar in/using Netbeans?
For more details on MANIFEST attribute: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html

0 comments :


gwtupload custom package with example/sample application

UPDATED: 14 October 2013
Uploading file(s) on the server is always important part of any web application. Today we are talking about uploading file(s) in GWT application along with the progress bar. Before we begin lets have look at the source of this plugin.


gwtupload
Its originally coded by "Manolo Carrasco". I made few changes regarding maximum upload size in original source code. The plugin works fine but when you want dynamic upload size for your each uploader. This facility not provided in current version. By using my custom gwtupload plugin you'll have that flexibility.

Prerequisites (Available in sample application)
1. gwtupload-custom.jar
2. commons-fileupload-1.2.2.jar
3. commons-io-2.3.jar
4. log4j-1.2.15.jar

I attached sample project at the end of the article. Lets have look at the important snippet of code...

GwtuploadSample.java
package com.javaquery.client;

import gwtupload.client.IFileInput.FileInputType;
import gwtupload.client.IUploadStatus.Status;
import gwtupload.client.IUploader;
import gwtupload.client.IUploader.OnChangeUploaderHandler;
import gwtupload.client.IUploader.OnFinishUploaderHandler;
import gwtupload.client.IUploader.OnStartUploaderHandler;
import gwtupload.client.MultiUploader;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define onModuleLoad().
 */
public class GwtuploadSample implements EntryPoint {
 /**
  * This is the entry point method.
  */
 public void onModuleLoad() {
  final Label responseLabel = new Label();
  
  MultiUploader multiUploader = new MultiUploader(FileInputType.BUTTON);
  multiUploader.setAutoSubmit(true);
  multiUploader.setEnabled(true);
  multiUploader.avoidRepeatFiles(false);
  multiUploader.addOnChangeUploadHandler(new OnChangeUploaderHandler() {
   @Override
   public void onChange(IUploader uploader) {
    if(uploader.getStatus() == Status.CHANGED){
     System.out.println("File input changed, can be handled before upload begin");
     /**
      * If you want to validate something at your side before upload.  
      * Check it here and you can cancel uploading.
      * Uncomment below line if you need it.
      * /
      
     /* uploader.cancel(); */
    }
   }
  });
  multiUploader.addOnStartUploadHandler(new OnStartUploaderHandler() {
   @Override
   public void onStart(IUploader uploader) {
    /**
     * This is where you can pass the hidden value to servlet.
     */
    uploader.add(new Hidden("param1", "value"));
    uploader.add(new Hidden("param2", "value"));
   }
  });
  multiUploader.addOnFinishUploadHandler(new OnFinishUploaderHandler() {
   @Override
   public void onFinish(IUploader uploader) {
    /**
     * Before processing output check the status of upload.
     */
    if(uploader.getStatus() == Status.SUCCESS){
     /**
      * If you passed details in JSONObject. You have to use subtring function of String to get your JSON String.
      */
     System.out.println(uploader.getServerResponse());
     responseLabel.setText(uploader.getServerRawResponse());
    }else{
     System.out.println(uploader.getStatus());
    }
   }
  });  
  //10485760 = 10 MB x 1024 x 1024
  multiUploader.setServletPath(GWT.getModuleBaseURL()+"upServlet?maxUpload=10485760");
  
  // Add the nameField and sendButton to the RootPanel
  // Use RootPanel.get() to get the entire body element
  RootPanel.get("MultiUpload").add(multiUploader);
  RootPanel.get("infoLabel").add(responseLabel);
 }
}

uploadServlet.java
package com.javaquery.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;

import gwtupload.server.UploadAction;
import gwtupload.server.exceptions.UploadActionException;

public class uploadServlet extends UploadAction{
 private static final long serialVersionUID = -4035393951562844790L;

 @Override
 public String executeAction(HttpServletRequest request, List sessionFiles) throws UploadActionException {
  String response = "";
  for (FileItem item : sessionFiles) {
   if (false == item.isFormField()) {
    String fileNameWithExt = item.getName();
    String fileName = fileNameWithExt.substring(0, fileNameWithExt.lastIndexOf("."));
    String fileExt = fileNameWithExt.substring(fileNameWithExt.lastIndexOf("."), fileNameWithExt.length());
    String uploadDir = getServletContext().getRealPath("/") + "gwtuploadFiles" + File.separatorChar;
    try {
     /**
      * Creating temporary file at "C:\Users\javaQuery\AppData\Local\Temp"
      * File.createTempFile(arg1,arg2)
      * arg1 : prefix you want to set. 
      *      Why "_projectName" used?
      *      - Say if filename length is 2 character then it'll throws error. 
      *        So for safe side we added "_projectName" to ensure that it must be long name.
      * arg2 : postfix you want to set. Whether its and extension or anything you like
      */
     File tempFile = File.createTempFile(fileName+"_projectName", ".bin");
     item.write(tempFile);

     /**
      * Before writing file to server folder you can scan temporary file (with antivirus on server) if you want.
      * Write it to server at your desired location. 
      */
     File createDir = new File(uploadDir);
     if (!createDir.exists()) {
      createDir.mkdir();
     }
     File saveOnserver = new File(uploadDir + File.separatorChar + item.getName());
     /**
      * Copy temporary file to original file.
      */
     FileInputStream inStream = new FileInputStream(tempFile);
     FileOutputStream outStream = new FileOutputStream(saveOnserver);
     byte[] buffer = new byte[1024];
     int length;
     while ((length = inStream.read(buffer)) > 0) {
      outStream.write(buffer, 0, length);
     }
     inStream.close();
     outStream.close();
     
     /**
      * Set response message you want at client side.
      * Say if you want extended details of your upload. Create JSON object, put values in it and pass it as String.
      */
     response += "File saved as " + saveOnserver.getAbsolutePath();
    } catch (Exception e) {
     throw new UploadActionException(e);
    }
   }else{
    /**
     * You can get the other parameter of your request here.
     */
    String hiddenFieldName = item.getFieldName();
    String hiddenFieldValue = item.getString();
    System.out.println("{param: "+hiddenFieldName+"; value: "+hiddenFieldValue+"}");
   }
  }

  // Remove files from session because we have a copy of them
  removeSessionFileItems(request);

  // Send your customized message to the client.
  return response;
 }
}

web.xml
<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
  <servlet>
    <servlet-name>uploadServlet</servlet-name>
    <servlet-class>com.javaquery.server.uploadServlet</servlet-class>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>uploadServlet</servlet-name>
    <url-pattern>/gwtuploadsample/upServlet</url-pattern>
  </servlet-mapping>
  
  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>GwtuploadSample.html</welcome-file>
  </welcome-file-list>

</web-app>

Now you are good to go for multiple file upload in GWT with progress bar. Don't forget to check official project website. For any queries and latest updates.

Download Sample Application

0 comments :


How to determine MIME type of file in java?

UPDATED: 01 October 2013
MIME type, File Type

Hello folks! How are you doing? Hope you are working hard on your code. Here I came up with the new article on how to determine the file type. This code will change your perspective about checking file types. If you are working on web application then it might help you.

Why file type filter is required?
When you deal with the file upload you have to be very careful on what type of file(s), user(s) allowed to upload. Usually we restrict our user to upload .exe, .msi, .bat, etc... executable file(s). Now think at different point of view. What if user change file extension from .exe to .png? This may create chaos.

Usual filter installed in our system.
Usually when user upload file(s) to server we check file type using something like fileItemTemp.getContentType(). This will give you file type which is determined using file extension but in real case its .exe file. You won't be able to determine the exact file type.

What is Magic header/array?
Magic Header is like identity of any file. You can't change it in any way for selected file(s) like .exe, .msi, .png, etc... This is what help us to determine the exact file type. At the very beginning of file you'll find this Magic Header sometime called Magic Array. However I didn't tested it for all file type so in some case it may not work. Java 7 built with solution of this issue so use it only when you are working below Java 7.
Java 7: Files.probeContentType(path)

Let have a look at the code.
import java.io.File;
import java.io.FileInputStream;

public class MIMECheck {
    public final int[] exeMagicHeader = new int[]{ 0x4d, 0x5a, 0x90, 0x00, 0x3, 0x00, 0x00, 0x00 };
    public final int[] msiMagicHeader = new int[]{ 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 }; 

    public static void main(String[] args) {
        MIMECheck mC = new MIMECheck();
        String rootPath = "D:\\javaQuery\\";

        File OriginalTempFile = new File(rootPath + File.separatorChar + "mysql-installer-5.5.25.0.msi");
        System.out.println(mC.isExe(OriginalTempFile));
        System.out.println(mC.isMsi(OriginalTempFile));
    }

    /**
     * Return true or false based on your input file
     * @param file
     * @return 
     */
    public boolean isExe(File file) {
        try {
            FileInputStream ins = new FileInputStream(file);
            for (int i = 0; i < 8; i++) {
                if (ins.read() != exeMagicHeader[i]) {
                    return false;
                }
            }
            ins.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    
    /**
     * Return true or false based on your input file
     * @param file
     * @return 
     */
    public boolean isMsi(File file) {
        try {
            FileInputStream ins = new FileInputStream(file);
            for (int i = 0; i < 8; i++) {
                if (ins.read() != msiMagicHeader[i]) {
                    return false;
                }
            }
            ins.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    /**
     * Generate Magic Array String of your input file
     * @param file 
     */
    public void generateMagicArray(File file) {
        String createMagicArray = "public final int[] MagicHeader = new int[] { ";
        try {
            FileInputStream ins = new FileInputStream(file);
            for (int i = 0; i < 8; i++) {
                createMagicArray += "0x" + Integer.toHexString(ins.read()) + ",";
            }
            ins.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        createMagicArray = createMagicArray.substring(0, createMagicArray.length() - 1);
        createMagicArray += " };";
        System.out.println(createMagicArray);
    }
}

Above code it self says a lot however lets understand each function.

- generateMagicArray will help you to create Magic Array any input file.
Note : You'll get different Magic Array of .txt, .bat, .reg, etc... for different input file. Reason behind it is Encoding method used by user to save file. You'll get same Magic Header for all .txt file which is created using ANSI. Same way for UTF-8 and UNICODE. Encode format decide the Magic Header.

- isExe and isMsi is used to compare the first 8 character of file and based on that will return true and false.

Now hope this article will solve your question regarding....
1) How to get file type in java?
2) How to determine MIME type in java?
3) How to get real file type in java?
4) How to verify file type in java?

0 comments :


Microsoft SQL Function : lastIndexOf

UPDATED: 14 September 2013
I was working around Stored Procedure in MSSQL mean while I get to know that there ain't any function called lastIndexOf(). So I coded it and thought let me share it with you guys. Its one time execution for each database and you can use it in queries, stored procedure, etc...

lastindexof , database

CREATE FUNCTION [dbo].[lastIndexOf] (@String VARCHAR(max) ,@Find VARCHAR(100))
RETURNS INT
AS
BEGIN
 DECLARE @SPLITTED_STRING VARCHAR(500);
 DECLARE @INDEX INT;
 DECLARE @PREVIOUS_INDEX INT;
 DECLARE @LEN INT;
 
 SET @INDEX = 0;
 SET @PREVIOUS_INDEX = 0;
 SET @SPLITTED_STRING = @String;
 
 WHILE ((SELECT CHARINDEX(@Find, @SPLITTED_STRING)) > 0)
  BEGIN
   SELECT @PREVIOUS_INDEX = CHARINDEX(@Find, @SPLITTED_STRING);
   SELECT @LEN = LEN(@SPLITTED_STRING);
   SELECT @SPLITTED_STRING = SUBSTRING(@SPLITTED_STRING, @PREVIOUS_INDEX+1, @LEN);
   SET @INDEX = @PREVIOUS_INDEX + @INDEX;
  END
  
 RETURN @INDEX - 1;
END

How to run this script in MSSQL?
Just copy the above script and paste it in SQL query editor. Press F5 or execute it.

How to use lastIndexOf function?
To get index of specified text execute your query like...
DECLARE @location int;
SET @location = [dbo].[lastIndexOf] ('ABCXYZ','C');
PRINT @location
//output : 2
DECLARE @location int;
SET @location = [dbo].[lastIndexOf] ('ABCXYZ','A');
PRINT @location
//output : 0
DECLARE @location int;
SET @location = [dbo].[lastIndexOf] ('ABCXYZ','F');
PRINT @location
//output : -1
DECLARE @location int;
SET @location = [dbo].[lastIndexOf] ('ABCXYZ','AT');
PRINT @location
//output : -1

0 comments :


Solved: Applet crashes unexpectedly...

UPDATED: 09 September 2013
I came to across strange issue of applet. One of our client facing issue of applet not loading properly in any browsers. Sometime it loads and sometime don't. I manage to figure out the problem. Lets discuss it very briefly...

java applet

Problem / Issue : When browser request for an applet it start communication with local system's Java Virtual Machine. The communication last for 10 sec to respond. If browsers's virtual machine and local system's java virtual machine can't communicate with in 10 sec for that thread. Local machine's JVM kills that thread and that leads to crash/close of applet or console.

You may get the following error log in your console before it crashes...
cache: Initialize resource manager: com.sun.deploy.cache.ResourceProviderImpl@1d6399b
security: property package.access value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.
security: property package.access new value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.definition value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.
security: property package.definition new value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.access value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.access new value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
security: property package.definition value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.definition new value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
security: property package.access value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
security: property package.access new value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss,com.sun.browser,com.sun.glass,com.sun.javafx,com.sun.media.jfxmedia,com.sun.media.jfxmediaimpl,com.sun.openpisces,com.sun.prism,com.sun.scenario,com.sun.t2k,com.sun.webpane,com.sun.pisces,com.sun.webkit
security: property package.definition value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
security: property package.definition new value sun.,com.sun.xml.internal.,com.sun.imageio.,com.sun.istack.internal.,com.sun.jmx.,com.sun.proxy.,com.sun.org.apache.bcel.internal.,com.sun.org.apache.regexp.internal.,com.sun.org.apache.xerces.internal.,com.sun.org.apache.xpath.internal.,com.sun.org.apache.xalan.internal.extensions.,com.sun.org.apache.xalan.internal.lib.,com.sun.org.apache.xalan.internal.res.,com.sun.org.apache.xalan.internal.templates.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.apache.xalan.internal.xslt.,com.sun.org.apache.xalan.internal.xsltc.cmdline.,com.sun.org.apache.xalan.internal.xsltc.compiler.,com.sun.org.apache.xalan.internal.xsltc.trax.,com.sun.org.apache.xalan.internal.xsltc.util.,com.sun.org.apache.xml.internal.res.,com.sun.org.apache.xml.internal.serializer.utils.,com.sun.org.apache.xml.internal.utils.,com.sun.org.apache.xml.internal.security.,com.sun.org.glassfish.,org.jcp.xml.dsig.internal.,com.sun.java.accessibility.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss,com.sun.browser,com.sun.glass,com.sun.javafx,com.sun.media.jfxmedia,com.sun.media.jfxmediaimpl,com.sun.openpisces,com.sun.prism,com.sun.scenario,com.sun.t2k,com.sun.webpane,com.sun.pisces,com.sun.webkit
security:  --- parseCommandLine converted : -Djava.net.preferIPv4Stack=true
into:
[-Djava.net.preferIPv4Stack=true]
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@f56959
basic: Plugin2ClassLoader.addURL parent called for http://demo.digi-corp.com:82/vishal/vicky_test/encryptionApplet80.jar
basic: Plugin2ClassLoader.addURL parent called for http://demo.digi-corp.com:82/vishal/vicky_test/json-rpc-1.0.jar
security: Blacklist revocation check is enabled
security: blacklist: created: NEED_LOAD, lastModified: 1376464928710
security: blacklist: hasBeenModifiedSince 1378286011099 (we have 1376464928710)
security: Trusted libraries list check is enabled
network: Cache entry found [url: http://demo.digi-corp.com:82/vishal/vicky_test/encryptionApplet80.jar, version: null] prevalidated=false/0
cache: Adding MemoryCache entry: http://demo.digi-corp.com:82/vishal/vicky_test/encryptionApplet80.jar
cache: Resource http://demo.digi-corp.com:82/vishal/vicky_test/encryptionApplet80.jar has expired.
network: Connecting http://demo.digi-corp.com:82/vishal/vicky_test/encryptionApplet80.jar with proxy=HTTP @ ISA-SERVER2006/10.192.192.4:8080
java.io.IOException: Error 0 writing to WindowsNamedPipe: server: false; readPipe: jpi2_pid3096_pipe2, readBufferSz: 4096; writePipe: jpi2_pid3096_pipe3, writeBufferSz: 4096: numWritten 0, WriteFile ts: 10732770661, now ts: 10732770769, dT 108
 at sun.plugin2.ipc.windows.WindowsNamedPipe.write(Unknown Source)
 at sun.plugin2.message.transport.NamedPipeTransport$SerializerImpl.flush(Unknown Source)
 at sun.plugin2.message.transport.NamedPipeTransport.signalDataWritten(Unknown Source)
 at sun.plugin2.message.transport.SerializingTransport.write(Unknown Source)
 at sun.plugin2.message.Pipe.send(Unknown Source)
 at sun.plugin2.main.client.MessagePassingExecutionContext.doCookieOp(Unknown Source)
 at sun.plugin2.main.client.MessagePassingExecutionContext.getCookie(Unknown Source)
 at sun.plugin2.main.client.PluginCookieSelector.getCookieFromBrowser(Unknown Source)
 at com.sun.deploy.net.cookie.DeployCookieSelector.getCookieInfo(Unknown Source)
 at com.sun.deploy.net.cookie.DeployCookieSelector.get(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.setCookieHeader(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.writeRequests(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
 at com.sun.deploy.net.HttpUtils.followRedirects(Unknown Source)
 at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
 at com.sun.deploy.net.BasicHttpRequest.doGetRequestEX(Unknown Source)
 at com.sun.deploy.cache.ResourceProviderImpl.checkUpdateAvailable(Unknown Source)
 at com.sun.deploy.cache.ResourceProviderImpl.isUpdateAvailable(Unknown Source)
 at com.sun.deploy.cache.DeployCacheHandler.get(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
 at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
 at sun.plugin.PluginURLJarFileCallBack.connect(Unknown Source)
 at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source)
 at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
 at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
 at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
 at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
 at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source)
 at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFileInternal(Unknown Source)
 at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFile(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath$JarLoader.getJarFile(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath$JarLoader.access$1000(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath$JarLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.sun.deploy.security.DeployURLClassPath$JarLoader.ensureOpen(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath$JarLoader.(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath$3.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source)
 at com.sun.deploy.security.DeployURLClassPath.getResource(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)
network: Cookie service is not available - use cache to determine "Cookie"

[ ... ]
JVMInstance (1.6.0.10) processing HeartbeatMessage, recv ts: 434920815362, send ts: 434920815390, dT: 28
[ ... ]
JVMInstance (1.6.0.10) processing HeartbeatMessage, recv ts: 434930816346, send ts: 434930816358, dT: 12
[ ... ]
JVMInstance for 1.6.0.10 killing sub-process because of no heartbeat reply
JVM instance for 1.6.0.10 exited
JVMInstance.unregisterApplet for applet ID 1
  LiveConnectSupport.shutdown(1)
  LiveConnectSupport: released [BrowserSideObject 0x2710ae8] for applet 1
  LiveConnectSupport: released [BrowserSideObject 0x2745200] for applet 1
java.io.IOException: Error closing named pipes
        at sun.plugin2.ipc.windows.WindowsNamedPipe.close(Unknown Source)
        at sun.plugin2.message.transport.NamedPipeTransport.shutdown(Unknown Source)
        at sun.plugin2.message.transport.NamedPipeTransportFactory.dispose(Unknown Source)
        at sun.plugin2.main.server.JVMInstance.disposePipe(Unknown Source)
        at sun.plugin2.main.server.JVMInstance.dispose(Unknown Source)
        at sun.plugin2.main.server.JVMInstance.access$2600(Unknown Source)
        at sun.plugin2.main.server.JVMInstance$Listener.jvmExited(Unknown Source)
        at sun.plugin2.jvm.JVMLauncher.fireJVMExited(Unknown Source)
        at sun.plugin2.jvm.JVMLauncher.access$300(Unknown Source)
        at sun.plugin2.jvm.JVMLauncher$JVMWatcher.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Terminating Java Plug-In Pipe Worker Thread (Server-Side) due to exception:
java.io.IOException: Error 0 reading from named pipe, numRead 0, ReadFile ts: 43
4962650222, now ts: 434962680979, dT 30757
        at sun.plugin2.ipc.windows.WindowsNamedPipe.read(Unknown Source)
        at sun.plugin2.message.transport.NamedPipeTransport$SerializerImpl.read(Unknown Source)
        at sun.plugin2.message.transport.NamedPipeTransport$SerializerImpl.readByte(Unknown Source)
        at sun.plugin2.message.AbstractSerializer.readInt(Unknown Source)
        at sun.plugin2.message.transport.SerializingTransport.read(Unknown Source)
        at sun.plugin2.message.Pipe$WorkerThread.run(Unknown Source)
IExplorerPlugin.OnFrameWindowActivate(cAxControl = 0x3561278, true)
IExplorerPlugin.OnFrameWindowActivate(cAxControl = 0x3561278, false)
IExplorerPlugin.SetObjectRects(cAxControl = 0x3561278, left = 2, right = 1272, top = 2, bottom = 995)
IExplorerPlugin.SetObjectRects(cAxControl = 0x3561278, left = 2, right = 1272, top = 2, bottom = 995)
IExplorerPlugin.OnFrameWindowActivate(cAxControl = 0x3561278, true)
IExplorerPlugin.OnSetFocus(cAxControl = 0x3561278)
IExplorerPlugin.OnFrameWindowActivate(cAxControl = 0x3561278, true)
IExplorerPlugin.OnFrameWindowActivate(cAxControl = 0x3561278, false)
[ ... ]

Solution is quite simple but you have to o it manually or create an executable file for that. You need to set environment variable in your system so it makes browsers's VM and local machine's JVM independent.

Set JPI_PLUGIN2_NO_HEARTBEAT = 1 system environment variable. (windows system only)

Referrals:
- https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Tivoli+Network+Manager/page/Browser+JRE
- http://prsync.com/oracle/script-to-set-noheartbeat-flag-490392/
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6953754
- http://stackoverflow.com/questions/18525908/certificate-loading-issue/18682680#18682680

0 comments :