Tuesday, July 24, 2012

Resolved: Cannot Google Calendar API



When calling the Google Calendar API  via Java, the following error may occured.
錯誤:redirect_uri_mismatch
The redirect URI in the request: http://localhost:54973/Callback did not match a registered redirect URI
Resolution:
Go to the following link:https://code.google.com/apis/console/
For Windows application, Create another client ID -> Installed Application -> Other



Saturday, July 14, 2012

[How-to] Install Maven with Eclipse

This article shows you how to use Maven with Eclipse.

1. Open Eclipse, Click Help -> Install New Software in the menu tool bar

2. Select Maven in the drop down list.
If it does not exist, click "Add" to input the Maven link
http://download.eclipse.org/technology/m2e/releases 


3. Select m2e - Maven Integration for Eclipse and click Next button.

4. Click Next for the installation

5. Accept the license.

6. Download and install the software

7. Restart the Eclipse

8. Installation Completed!



Thursday, July 12, 2012

[RESOLVED] MySQL Workbench installation

No response after clicking the MySQL Workbench program.


Resolve:

Make sure the following components are installed in your machine.


1. Microsoft .NET Framework 4 Client Profile (Web Installer)
http://www.microsoft.com/en-us/download/details.aspx?id=17113


2. Microsoft Visual C++ 2010 Redistributable Package (x86)
http://www.microsoft.com/en-us/download/details.aspx?id=5555
 

3. In some cases, Windows Imaging Component is required
http://www.microsoft.com/en-us/download/details.aspx?id=32

Reference:

Download the MySQL workbench
http://dev.mysql.com/downloads/workbench/


Keywords:
MSSQL Studio, toad

Wednesday, July 4, 2012

Eclipse Development Platform Setup



The following tutorial shows how to setup the development environment for Java Application
You have to install the following software in your machine.
- JAVA SDK
- Eclipse
Steps by steps1. Download and Install the latest version of the Java SDK. 


2. Download Eclipse, either IDE for Java Developer or Java EE Developer is okay.

3. Unzip the eclipse, Open it with selecting a workspace

4. Done


java.lang.UnsupportedClassVersionError: Bad version number in .class file


This is due to the incorrect Java Version for the complication & execution.

Resolution:
Download the correct Java Version for the complication.

HTTP Status 500 -


type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Bad version number in .class file
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.UnsupportedClassVersionError: Bad version number in .class file
 java.lang.ClassLoader.defineClass1(Native Method)
 java.lang.ClassLoader.defineClass(ClassLoader.java:620)
 java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1812)
 org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:866)
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1319)
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
 org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1325)
 org.apache.jasper.compiler.Parser.parseElements(Parser.java:1573)
 org.apache.jasper.compiler.Parser.parse(Parser.java:126)
 org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
 org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:155)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.

Wednesday, June 27, 2012

[Resolved] WARNING: getRGBImage returned NULL PDFToImage: Rendered Blank Image

Problem:
System returns the following message when converting a PDF file to Image using PDFBox,


Jun 27, 2012 3:45:07 PM org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap getRGBImage
SEVERE: Something went wrong ... the pixelmap doesn't contain any data.
Writing: output1.jpg
Jun 27, 2012 3:45:07 PM org.apache.pdfbox.util.operator.pagedrawer.Invoke process
WARNING: getRGBImage returned NULL
result: true



A blanked image will be generated in this case.

Resolution
1. You may try to add Java Advanced Image library I/O Tools to your project for the fix.
http://www.oracle.com/technetwork/java/current-142188.html


2. Include the JAR jai_imageio.jar to your project and execute the project again.


3. Though there is still an WARNING message of EOC marker not found. Codestream is corrupted. shown in the output console, the image is generated successfully.

The usage of PDFBox can be found in the following URL:
http://yp-javadev.blogspot.hk/2012/06/useful-api-converting-pdf-to-image.html

Useful API converting PDF to image

1. Download the tool PDFBox (e.g. pdfbox-app-1.7.0.jar) via the following URL:


2. Include the library in your java program. The following source code is attached for your reference.



package com.test;

import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFImageWriter;

public class PDFBoxPreviewTest {

       /**
        * @param args
        */
       public static void main(String[] args) {
              try {
                     String path = "D:\\temp\\a.pdf";
                     PDFBoxPreviewTest t = new PDFBoxPreviewTest();
                     t.getDocument(path);
              } catch (Exception e) {

                     System.out.println(e.getMessage());
              }
       }

       private PDDocument getDocument(String path) throws Exception {
              PDDocument document = null;

              document = PDDocument.load(path);

              PDFImageWriter writer = new PDFImageWriter();
              boolean success = writer.writeImage(document, "jpg", "", 1, 1,
                           "myFileName", BufferedImage.TYPE_INT_RGB, Toolkit
                                         .getDefaultToolkit().getScreenResolution());
              System.out.println(success);

              return document;
       }
}

3. myFileName.jpg will be generated!


Source Code can be found here:
http://test-pdfbox.googlecode.com/svn/trunk/

Monday, June 18, 2012

[RESOLVED] A Java Runtime Environment (JRE) or Java Development Toolkit (JDK) must be available in order to run Eclipse

A Java Runtime Environment (JRE) or Java Development Toolkit (JDK) must be available in order to run Eclipse.


Solution:

Java must be installed in your Windows in order to run eclipse.
http://java.com/en/download/index.jsp

After installed Java, set the JAVA PATH in System Variable.

Thursday, April 12, 2012

[Resolved] Download CSV with UTF-8 handling

System generates garbage characters or question marks ??? when exporting a CSV file with Chinese character, Japanese Character..



It is okay to view the Chinese / Japanese character in notepad, but cannot be shown correctly in Excel.
It is because Excel does not handle the unicode well.


Solution
It can be solved by adding addition header (BOM, Byte order Mask) to the downloaded CSV file.

response.setContentType("application/vnd.ms-excel:UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=myOutputFile.csv");

// Excel does not recongize the UTF-8, add additional header (BOM) for excel
OutputStream outputStream = response.getOutputStream();
outputStream.write(0xEF);  
outputStream.write(0xBB);
outputStream.write(0xBF);  


BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));

// Your method that generate the CSV content
writeSth(writer);

writer.flush();
writer.close();

Monday, March 26, 2012

request.getparameter returns corrupted characters

When inputs non-unicode characters (such as Japanese, Traditional Chinese),  system may returns corrupted characters during request.getParameter("XXX")

It is because the tomcat uses ISO-8859-1 as the default encoding...

Solutions:
1. By declaring page directive
<%@ page contentType="text/html;charset=UTF-8"%>

OR
2. Set the encoding before calling request.getParameter("XXX") in the page
<% 
request.setCharacterEncoding("UTF-8"); 
request.getParameter("XXX");
request.getParameter("YYY");
%>

Tuesday, March 13, 2012

Code Snippnet: Converting java.util.Date to java.sql.Date


 java.util.Date today = new java.util.Date();
long t = today.getTime();
java.sql.Date dt = new java.sql.Date(t);

Wednesday, February 22, 2012

Small Technique on using Java Decompiler in Eclipse

Here's my common use way on the Java Decompiler..

Method 1: Direct Access to the class by shortcut
1. Click Ctrl + T, and then input the class and input the class name

2. Eclipse will bring you to the class implementation.


Method 2: Direct Access to the class by Open Declaration (F3)
1. Mouse over to the corresponding class in the Java File and click F3
For example, mouse over javax.ejb.SessionBean and then  click F3


2. Eclipse will bring you to the class implementation.





Method 3: Use Java Browsing Perspective
1. Click the icon in the Red Box below to Open a new perspective


 2. Choose Java Browsing

3. You may find your class implementation as below.

Monday, February 20, 2012

Install Decompiler in Eclipse Indgio

This article will show you how to install a Java Decompiler to Eclipse.. We will use JadClipse in this example. 

  JadClipse
Maintainer:Vladimir Grishchenko, Johann Gyger
Platform:Platform independent
Genre:Java, Decompiler, Eclipse plug-in
License:CPL
Languages:English, Russian
Website:JadClipse.sf.net
 
1. Download JAD

http://www.softpedia.com/progDownload/JAD-Download-85911.html

2. Download JADEclipse in sourceforge


http://sourceforge.net/projects/jadclipse/

3. Put the JAR to Eclipse Plugin Folder
For example: D:\eclipse_indigo\plugins\net.sf.jadclipse_3.3.0.jar


4. Start and Configure Eclipse for the JAD Plugin
In Eclipse, Click Window –> Preference –> Java –> Jadclipse
For example: 
Path to decompiler: D:\warez\JAD\jadnt158\jad.exe
Directory for temporary files: D:\tmp\Decompiler


5. Done and test
Open a file, mouse over the javax.ejb.SessionBean, click F3 to go to the class definition.

 The Decompiled Java file will be shown.

Thursday, February 16, 2012

The project was not built due to "Could not delete 'XXXXXX'". Fix the problem, then try refreshing this project and building it since it may be inconsistent.

The project was not built due to  "Could not delete 'XXXXXX'". Fix the problem, then try refreshing this project and building it since it may be inconsistent.


This problem is due to the cache of the old class file in eclipse, to clean the cache..

1. Project -> Clean

2. Clean all projects

3. The error is gone.

How to avoid calling huge number of Java program

Background
When the mail server receive email, it would trigger a java program by calling a shell script.
However, as the volumne of email is large, the java program will be triggered serveral times...

Better Design

Wednesday, February 15, 2012

[Resolved] Do not use APIs from sun.* packages (WAS Upgrade)

This is a short note for my WAS upgrade project V6.0 to V7.0

Recommendation by the WebSphere Application Migration Tool:
Do not use APIs from sun.* packages

Package: sun.misc.BASE64Encoder

*** Code changes as below:

Before
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;