2008年5月30日金曜日

[Firefox]blank page is displayed, not able to access to the localhost(127.0.0.1) when using Firefox browser.

Description
When I use the firefox browser in Windows Vista environment and access to my localhost environment to test my web page, I can't access to my localhost web page. blank page is found and firefox doesn't display my test page, and System has no response. However, Internet Explorer works fine in the same environment.

Resolution
  1. Start the firefox browser
  2. Type "about:config" in URL field, the configuration page is displayed.
  3. Type "ipv6" in Filter field located at the top of the config page.
  4. Check "network.dns.disableIPv6", the default value of this configuration is FALSE, change the value of this configuration to TRUE(doubleclick this field and system will change the value to TRUE.)

2008年5月26日月曜日

[Java>JavaMail] java.lang.SecurityException: "Access to default session denied" occures.

Description
This problem occures in my web application environment using tomcat server. When using the javamail library to send email from my application, sometimes the java.lang.SecurityException: "Access to default session denied" error occures and I can not send email from my application. After rebooting my application server(tomcat), javamail works fine for a while.

Error Details
Error message outputted by the javamail is java.lang.SecurityException: "Access to default session denied". After occuring this error, system always fails to send email, but system works fine after rebooting the tomcat server.

Cause
This error is raised in the getDefaultInstance method in javax.mail.Session.java. According to this source code, this error occures when the default session object is already initialized, but authenticator instance is renewed or changed, or the class loader of the default session object is different from the argument authentificator's. Maybe the java source code using the default session instance of the java mail is recompiled and reloaded, or duplicate javamail class libraries are included into the Classpath of the environment.
javax.mail.Session.java file
public static synchronized Session getDefaultInstance(Properties props,
Authenticator authenticator) {
if (defaultSession == null)
defaultSession = new Session(props, authenticator);
else {
// have to check whether caller is allowed to see default session
if (defaultSession.authenticator == authenticator)
; // either same object or both null, either way OK
else if (defaultSession.authenticator != null &&
authenticator != null &&
defaultSession.authenticator.getClass().getClassLoader() ==
authenticator.getClass().getClassLoader())
; // both objects came from the same class loader, OK
else
// anything else is not allowed
throw new SecurityException("Access to default session denied");
}

return defaultSession;
}

Resolution
  1. Recompile and restart application server to reload the new class file.
    After restarting the application server, does your system work fine?
    Do you use auto-deploy functionality? If yes, restart application server and use it without modifying and recompiling your java files.
  2. If the duplicate class files are included.
    Please check the class path directories and some jar files including the javamail class file is included. For example, please check common/lib directory and WEB-INF/lib in your application if you are using tomcat application server. If the duplicate class files are found, please remove the jar file.

2008年5月9日金曜日

[Groovy>Grails] IncompatibleClassChangeError error when starting jetty server in grails development environment

Description
I useally use the Java environment based on Sun's JDK when using grails and groovy, but sometimes I change the JDK from Sun's to IBM's to check the behavior and performance. After changing the IBM's JDK, following error occures when starting up the jetty application server on grails environment.

Error Detail
Failed startup of context org.mortbay.jetty.webapp.WebAppContext@3c003c{/test,/home/admin/test/web-app}
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for java.lang.Thread do not match. Expected 8 but got 9.

Solution
This error occures because the runtime of java version or provider(Sun, IBM or others) is different from the version of compiled jdk environment. In my case, I compile the grails source code based on Sun's jdk(Ver.1.5), and then I change the JDK from Sun to IBM(Ver.1.5) without recompiling my java source codes. Maybe the IBM internal classes using in the JDK is different from the Sun's. In this case, the error is resolved after clearing all old compiled class files and recompile all classes by using new java compiler.

2008年4月10日木曜日

[JAVA>Rome, Itunes RSS/XML] When using Rome ITunes RSS Reader, ParsingFeedException(Invalid XML) error occured.

When using Rome's itunes module, the error "com.sun.syndication.io.ParsingFeedException: Invalid XML" sometimes occures.The error stack is as follows. This error isn't related to the Rome core program, this error is depended on the itunes module.
The Podcast RSS feeds has itunes:duration attribute which means the duration of the podcast file. The value format of this field is always similar to "09:30", but some site are including the invalid value(Long type value).

References
  1. Same error, but the root cause is different from this problem.
    http://taapps-javalibs.blogspot.com/2008/04/javarome-rssxml-when-using-rome-rss.html
  2. Itunes module site
    http://wiki.java.net/bin/view/Javawsxml/ITunes
  3. Source Code repository
    https://rome.dev.java.net/source/browse/rome/
Error Stack
  • Caused by: java.lang.RuntimeException: Illegal time value: 9174935
    at com.sun.syndication.feed.module.itunes.types.Duration.(Duration.java:98)
    at com.sun.syndication.feed.module.itunes.io.ITunesParser.parse(ITunesParser.java:149)
    at com.sun.syndication.io.impl.ModuleParsers.parseModules(ModuleParsers.java:51)
    at com.sun.syndication.io.impl.BaseWireFeedParser.parseItemModules(BaseWireFeedParser.java:57)
    at com.sun.syndication.io.impl.RSS090Parser.parseItem(RSS090Parser.java:289)
    at com.sun.syndication.io.impl.RSS091UserlandParser.parseItem(RSS091UserlandParser.java:222)
    at com.sun.syndication.io.impl.RSS092Parser.parseItem(RSS092Parser.java:81)
    at com.sun.syndication.io.impl.RSS093Parser.parseItem(RSS093Parser.java:39)
    at com.sun.syndication.io.impl.RSS094Parser.parseItem(RSS094Parser.java:68)
    at com.sun.syndication.io.impl.RSS090Parser.parseItems(RSS090Parser.java:263)
    at com.sun.syndication.io.impl.RSS090Parser.parseChannel(RSS090Parser.java:178)
    at com.sun.syndication.io.impl.RSS091UserlandParser.parseChannel(RSS091UserlandParser.java:84)
    at com.sun.syndication.io.impl.RSS092Parser.parseChannel(RSS092Parser.java:49)
    at com.sun.syndication.io.impl.RSS094Parser.parseChannel(RSS094Parser.java:45)
    at com.sun.syndication.io.impl.RSS090Parser.parse(RSS090Parser.java:82)
    at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:252)
    at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:179)
The reason why this error occures.
When system reads the RSS, Rome and itunes module parses the rss feed. In Duration field, ITuneParser tries to check whether the duration value includes the ":" character or not. But some duration field doesn't include the ":" character, ITuneParser will raise the ParseException.

Solution
Please download the latest source code from the CVS repository, this problem has already solved. I downloaded the latest source code and compiled it. You can get the jar file I compiled.
URL is http://groups.google.com/group/taapps-sourcecode-libraries/web/itunes-0.4-tafix2.jar
(I recompiled itues-0.4.jar file again at 2008/04/14)

2008年4月4日金曜日

[JAVA>Rome, RSS/XML] When using Rome RSS Reader, ParsingFeedException(Invalid XML) error occured.

References
  1. Rome WebSite
    https://rome.dev.java.net/
Problems
When using Rome RSS Reader, "com.sun.syndication.io.ParsingFeedException: Invalid XML" error sometimes occures.This problem occure while parsing the RSS feed and System raises the ParsingFeedException and NumberFormatException.

Error Stack when occuring this problem
com.sun.syndication.io.ParsingFeedException: Invalid XML
com.sun.syndication.io.ParsingFeedException: Invalid XML
at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:185)
at com.sun.syndication.io.SyndFeedInput.build(SyndFeedInput.java:122)
at RomeTest.main(RomeTest.java:35)
Caused by: java.lang.NumberFormatException: For input string: "09:31"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:63)
at java.lang.Long.parseLong(Long.java:427)
at java.lang.Long.parseLong(Long.java:476)
at com.sun.syndication.io.impl.RSS092Parser.parseItem(RSS092Parser.java:107)
at com.sun.syndication.io.impl.RSS093Parser.parseItem(RSS093Parser.java:39)
at com.sun.syndication.io.impl.RSS094Parser.parseItem(RSS094Parser.java:68)
at com.sun.syndication.io.impl.RSS090Parser.parseItems(RSS090Parser.java:263)
at com.sun.syndication.io.impl.RSS090Parser.parseChannel(RSS090Parser.java:178)
at com.sun.syndication.io.impl.RSS091UserlandParser.parseChannel(RSS091UserlandParser.java:84)
at com.sun.syndication.io.impl.RSS092Parser.parseChannel(RSS092Parser.java:49)
at com.sun.syndication.io.impl.RSS094Parser.parseChannel(RSS094Parser.java:45)
at com.sun.syndication.io.impl.RSS090Parser.parse(RSS090Parser.java:82)
at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:252)
at com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:179)
Reason why this errr occured
Some RSS data has a enclosure tag in channel/item element as follows and length parameter is defined in enclosure element.
 enclosure url="http://domain.com/file.mp3" length="123456789" type="audio/mpeg"
According to the wikipedia(http://en.wikipedia.org/wiki/RSS_Enclosures) or other web site(http://www.w3schools.com/rss/rss_tag_enclosure.asp), the length parameter means the length (in bytes) of the media file and this parameter is required field. The length parameter should be numerical value, but sometimes it isn't numerical in some RSS feeds.(In some feeds, the value of length parameter includes the comma separator like "123,456,789", or other RSS includes the "09:31" value similar to the timestamp)
In this case, while System tries to convert the length parameter from String object to Long object by using java.lang.Long.parseLong method, System throws the NumberFormatException because the value in the length field has invalid format value.

Solution
  1. Fixed file
    rome-0.9/src/java/com/sun/syndication/io/impl/RSS092Parser.java
  2. Fixed function
    Change as follows in parseItem() function.
  3. Description
    catches the exception while converting the String object to Long for the Length parameter.
    In case of my fix, catches the NumberFormatException and then, tries to remove the comma characters from the parameter and retry the conversion. retry is failed, ignore occuring this exception and doesn't set the value inf Length attribute.
  4. Fixed file
    Jar File: http://groups.google.com/group/taapps-sourcecode-libraries/web/rome-0.9-tafix.jar
    This jar file includes both this fix and http://taapps-javalibs.blogspot.com/2007/06/javarome-rss-when-using-rome-rss-reader.html problem.
  5. Fix Example
        att = e.getAttributeValue("length");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
    if (att!=null && att.trim().length()>0) {
    //Starting customization, added by tatsuya anno(taapps@gmail.com)
    //sometimes occures com.sun.syndication.io.ParsingFeedException
    //when converting the attribute value to the Long
    String trimmedAtt=att.trim();
    long enclosureLength=-1;
    try{
    enclosureLength=Long.parseLong(trimmedAtt);
    }catch(Exception exception){
    try{
    //remove commma character before converting
    //string to long.
    trimmedAtt=trimmedAtt.replaceAll(",","");

    //retry conversion from string to long
    //if exception occures, system will ignore it
    //in this case
    enclosureLength=Long.parseLong(trimmedAtt);
    }catch(Exception ignore){}
    }

    //if enclosureLength is greater than 0, set length
    if(enclosureLength>=0){
    enclosure.setLength(enclosureLength);
    }
    //end of customization
    }

2008年3月29日土曜日

[Groovy>Grails] Customization, how to execute Native SQL statement on Grails environment

I created a new plugin, please refer to http://taapps-javalibs.blogspot.com/2009/04/grailsupgraded-plugin-for-grails-to.html

Description

Grails is an open-source web application framework that leverages the Groovy language and complements Java Web development. Grails has the database access layer like the RubyOnRails's Active Record, it is very usefull and powerful, but sometimes we need to execute Native SQL Statement. We sometimes need to use the fulltext search statement(match/against statement) if we use mysql database as the backend server. We sometimes need to tune the sql performance and enter the QueryHint into the sql statenent.In case of ORACLE Database, we can use query hint like "select /*index hint */ .....", in case of using mysql, we can use "use/force index" statement.
But now, we can use these native sql statement on Grails framework, Grails System doesn't allow to use native statement.(We can use HQL Query Language by using executeQuery, findAll or other methods, but HQL doesn't allow to use native sql via these methods). I customized grails and added the "executeNativeQuery" method to run the native sql statement from the Grails framework.

Installation
(I tested this customization only on mysql database environment.)
  1. Download grails-1.0.1-dist-b4.tar file, this file is customized based on Grails-1.0.1 source code.
    jar files: http://groups.google.com/group/taapps-sourcecode-libraries/web/grails-1.0.1-dist-b4.tar
  2. Extract downloaded tar file
    source files: http://taapps-sourcecode-libraries.googlegroups.com/web/grails-1.0.1-b4-src.tar
  3. Copy 8 *.jar files existing under dist directory to the GRAILS_HOME/dist directory
  4. Restart application server, defailt server is jetty
How to use this customization program
While restarting the application server, System adds the executeNativeQuery method into the Domain Class object dynamically. The executeNativeQuery method has some parameters as follows and return the List object including some DomainClass objects fetched from the database.
Examples how to use this method are as follows.(the name "IndTest" means my Domain Test class name for the sample code)
  • Type1, put the raw SQL statement into the grails hibernate layer.
    Table alias name should be "tbl", the "tbl" alias will be mapped to the Domain Class.

    def objList=IndTest.executeNativeQuery(
    "select {tbl.*} from ind_test as {tbl} where user_id=10000 and match(description) against('aaaaaaa')")

    objList.each{obj-> //executeNativeQuery will return the List object including the fetched domain objects
    .....
    }

  • Type2 executeNativeQuery has 3 arguments, SQL Statement String, Map object for mapping table alias, List object including the bind parameter values.

    def objList=IndTest.executeNativeQuery(
    "select {alias.*} from ind_test as {alias} where user_id=? and match(description) against(?)",
    [alias:IndTest], --> table alias "alias" is mapped to the IndTest Domain Class.
    [10000,"bbbbbb"]) --> 10000 is replaced with user_id's, bbbbbb is replaced with description's

  • Type3 executeNativeQuery has 3 arguments, SQL Statement String, Map object for mapping table alias, Map object including the bind parameter values.

    def objList=IndTest.executeNativeQuery(
    "select {alias.*} from ind_test as {alias} where user_id=:p1 and match(description) against(:p2)",
    [alias:IndTest],
    [p1:10000, p2:"cccccc"])

  • Type4 executeNativeQuery has 4 arguments, SQL Statement String, Map object for mapping table alias, Map object including the bind parameter values, Map object for using pagination

    def objList=IndTest.executeNativeQuery(
    "select {alias.*} from ind_test as {alias} where user_id=:p1 and match(description) against(:p2)",
    [alias:IndTest],
    [p1:10000,p2:"dddddd"],
    [max:10,offset:1])


  • executeNativeQuery method has other parameter patterns as follows.
    Query means the sql query statement string.
    EntityMap means the Map object including the table alias mapping(alias name and Domain class name).
    ParamList means the List object including the parameter values for the bind parameters.
    NamedMap means the Map object including the parameter values for the bind parameters.
    PageMap means the Map object for using pagination parameter.

    Arg Number :0 1 2 3
    Type 1 :String :Query
    Type 2 :String Map :Query,EntityMap
    Type 3 :String Map List :Query,EntityMap,ParamList
    Type 4 :String Map Map :Query,EntityMap,NamedMap
    Type 5 :String Map List Map :Query,EntityMap,ParamList,PageMap
    Type 6 :String Map Map Map :Query,EntityMap,NamedMap,PageMap


2008年3月8日土曜日

[Groovy>Grails] Error "failed to create task or type native2ascii" occures when running grails war file on Tomcat environment

Description
When running grails war file on Tomcat environment, following error message occures and fail to execute the program.

Error Message
 : Problem: failed to create task or type native2ascii
Cause: the class org.apache.tools.ant.taskdefs.optional.Native2Ascii was not found.
This looks like one of Ant's optional components.
Solution
System can not find the ant-nodeps.jar file in the classpath.
Get ant-nodeps.jar file and put this file into the $TOMCAT_HOME/webapps/[app name]/WEB-INF/lib/ and restart Tomcat process. ant-nodeps.jar file is including Apache ant file.