Saturday, July 13, 2013

Spring IDE copyright owner changed to GoPivotal...

I was quite surprised to when I opened the latest Groovy/Grails Tool Suite (GGTS) from SpringSource, the splash screen displays that the copyright owner of the Groovy/Grails Tool Suite. I believe it was previously VMware but i haven't checked it out again.

It turns out that VMware is spinning of the IDE, and teamed up with GE to setup this GoPivotal.

It's too early to comment, but it seems now the focus geared more toward monetizing the cloud platform.

Wednesday, August 22, 2012

Great products from Atlassian

I must admit that I've been a great fan of Atlassian, the company and its products. Great tools made for developers. Open source user, contributor and open source friendly company.
Great products, and they are Java based. Noone will ever say "Java is slow" (unless they stay in the caves, still hunting and gathering foods) when they have used Confluence or JIRA.

We used both  JIRA and Confluence at work.

I personally use Confluence for my personal content and knowledge repository.
I really liked it, just nice. Just as I need it. I can attach documents in it, version the document, attach pictures, etc. It's much better than folder or event some famous "document management". Of course only for my personal requirements point of view.

The other thing that I like is the architecture of the product, especially Confluence. It scales well, the search engine is based on Apache Lucene, it deploys stand alone on Tomcat, and also on many other application servers. It uses OSGi based on Apache Felix. So many good concept applied at the right spots. Another plus thing for me is, it supports PostgreSQL as one of the default databases for production. For me this is a big plus, as most of my personal production systems run on PostgreSQL.

Personally I think Confluence is much better structured (or architected) product than JIRA.

First, in term of the search engine, it's way much better. I don't know why JIRA couldn't have such good search capability as Confluence (e.g. it's difficult to find attachments or issues with attachments). Also the search completion as well.

Second thing is the backup and upgrade compatibility. After running for production a few years, it is so much easier to backup and restore Confluence, and it's much more difficult to backup and restore. Likewise the upgrade of versions.

Just from using such products I have learned so much for the products. Many items went into our products' wish lists... or at least my personal wish lists for our company's products.

PS: I am not related or getting paid by Atlassian. I am just a satisfied customer.

Sunday, August 5, 2012

Single Sign On using Centrify DirectControl for Web and Tomcat


I was way too lazy to update my blog on Java. FYI, I am still working with Java <blink>.

Last month we have just successfully implemented a Single Sign On to Active Directory on one of our product. The Single Sign On was using Centrify DirectControl for Java/Web.
We are running on this stack:


  1. Linux box for application server
    1. JDK 6.0 update 31 (Centrify DirectControl requires JDK, not just JRE)
    2. Apache Tomcat 6.0 (Tomcat 7.0 was not supported when we start implementing)
    3. Centrify DirectControl 4.4.1-203
    4. Centrify DirectControl for Java/Web 4.2.0-417
    5. Red Hat Enteprise Linux 5.7 (when we started, it was still version 5.6, but now upgraded to 5.7 smoothly)
  2. Active Directory
    1. Windows Server 2003 or 2008
    2. Active Directory 2003 or 2008
    3. multi-domain forest with nested group of domain local, domain global, and universal.
    4. global multi-site, replication over WAN.
  3. Client
    1. Windows XP Professional Service Pack 3, or Windows 7
    2. joined one of the Active Directory domain.


Lots of people will associate Single Sign On with LDAP. Though LDAP most likely being involved somewhere in the Single Sign On, not every systems that use LDAP are using Single Sign On. In fact, those are just shared username/password hash database systems.

This is what I mean: if you have to login again inside your browser, definitely it is not a real Single Sign On system we are talking about.

What we implement is when you have successfully logged in to your desktop (in this case Windows XP or Windows 7), whenever you open your browser pointing to the correct URL, the web application will recognize you as the user you have logged in to Windows Active Directory domain.

We came into Centrify DirectControl because it is desired by the customer's infrastructure team for systems that run on Linux boxes.

What we learned from this implementation:


  1. Implementing Single Sign On with Centrify DirectControl needs some paradigm change to the user and group that we already implemented.
  2. So far Spring Security Single Sign On (Kerberos) to Active Directory that we tried only works in the lab of those who play with it, but is very difficult to replicate everywhere else. We eventually ditch our beloved Spring Security component in order to implement using Centrify DirectControl. This may change in the future, but we spent considerable amount of time without being fruitful on it.
  3. On the other hand, the Centrify DirectControl for Java/Web works the first time we tried it. The sample just works.
  4. Modifying the sample of Centrify DirectControl for Java/Web to a real world Single Sign On is not a trivial task though. In the instance of our client, many have tried and gave up, and we were the first one to successfully implemented it using Centrify DirectControl for Java/Web.
  5. In the development site, make a working environment of Active Directory server, Active Directory client and a Linux server box is not so trivial, due to many factors that can make it fail.
    1. Get the DNS setting correct is the key to successful setting of the environment.
    2. Use of the tools to really diagnose, don't ignore slight problems that occurs as error messages.
  6. Among of those issues that we encountered:
    1. If something is wrong with the Single Sign On, usually you won't see any messages.
    2. It is difficult to get the Java logging to display something the first time.
    3. The forced use of old commons-logging 1.0 by CentrifyDC caused a lot of problems (we have to resolve the logging conflicts to get it working, yet because it is logging problem they won't tell you anything).
    4. When you want to create installer that doesn't depend on CentrifyDC web installer, you have to really trace the dependencies one by one.
    5. Some problems were caused by propagation delay or caching of Active Directory/Centrify DC/Kerberos data which simply just need to wait and try again. We encountered this several times in different places, e.g. adding user to new group but not recognized in the header, after waiting for (few) hours, it suddenly became working like magic. Yes, we tried to restart everything, leave and rejoin domain, and still the stubborn caching didn't flush at all.
    6. Tomcat has unusually small default maximum HTTP header size, this kind of SSO requires bigger HTTP header size. According to our friend this also happened before with other SSO on Windows/IIS.


Wednesday, February 23, 2011

Model 2 Code Eclipse

This www.model2code.com site is offering an affordable, agile and model driven Eclipse based tool that is able to forward engineer from model to application. I want to give it a try (it's a trial application).
The size is quite a fat download (more than 1GB!) and unfortunately today's Internet connection is slow here.

The incoming Spring 3.1 will have annotation based cache

I think this is one of the feature developers are waiting for.

I remember last time when my colleague have to implement our specific annotation to incorporate OSCache into the web layer. Now it will be as simple as adding annotation to existing Spring beans!

http://blog.springsource.com/2011/02/23/spring-3-1-m1-caching/

Friday, December 10, 2010

Singapore JUG Meetup January 2011

Next Java User Group Singapore Meet Up will be scheduled on January 25th 2011.
I posted the announcement at meetup.com, Facebook and also Twitter. Hopefully that will reach some people who really keen to it.

We are still looking for a good venue, and may be some figure on how much people will attend will help to find a suitable place for this meet up.

Ruslan Khafizov has been volunteered with the idea: "Fluent Interface in Java".
Anyone suggests place to meet somewhere in central Singapore?

Sunday, December 5, 2010

Trying to revive the Java User Group Singapore Meet Ups

Java User Group Singapore has been quite inactive for a while (last meet up was 189 days ago, according to meetup.com). I attended some of the meet ups in the past, but not recently because of the coming of our newborn baby. I guess a lot of people were also busy with their own things :O

Lots of changes happened, we can no longer use the Sun Microsystems office at Central Mall, 1 Magazine Road, Singapore. The office apparently had been shut down due to the consolidation after the acquisition by Oracle. The last 2 meetings were held at Hackerspace, 70A Bussorah Street, Singapore.

We want to revive the meet ups of Java User Group Singapore again.
I was thinking, probably the first month of next year will be best time to start, as December is too close and most people will be off in holidays during mid-December to mid-January.

Today I met one Oracle employee. He wants to pass me the contact person who's in charge of maintaining relationship with developers. We of course welcome anyone or companies who can provide place for meet ups. Ideally the place should be located somewhere central.

Thursday, July 22, 2010

Eclipse 3.6 Helios had problem after upgrading to JDK 6u21 (1.6.0_21)

Two days ago I upgraded my JDK to latest 1.6.0_21. My colleague had warned me that the JDK got problem (I helped installing the Helios on his machine). I upgraded anyway, and bumped into that problem. I was aware that the error was expected. I decided to downgrade back to JDK 1.6.0_20 because I didn't have time to explore within that tight schedule.

I found this link http://www.infoq.com/news/2010/07/eclipse-java-6u21 which explains well why they have this problem.

The native code launcher uses the "COMPANY_NAME=Sun Microsystems, Inc", which then changed to "COMPANY_NAME=Oracle Corporation" by Oracle. Not just Eclipse, all RCP based applications are affected.

Saturday, July 10, 2010

Again about Google DevFest 2010

Yesterday I had to leave an hour earlier from the Google DevFest 2010 event, as I have to  catch up with my wife, she was waiting for me for the second Antenatal Class. I missed the Code Lab, the Maps and Buzz T-shirts. Ouch. 5:30pm I had to leave while they ended the event on 6:30pm.

Flash back: After lunch time, there were some presentations on Google Apps, by Patrick Chanezon, followed by success story of people who developed applications for Google Apps. One from creately.com (http://www.creately.com). Another round from SingPath (http://singpath.appspot.com).

One thing that was missed a lot is the power points (aka power plugs). It was awful so many people carrying laptop and no power plug on the Connexis Theater. Almost everyone were running out of battery.

I just don't know why the crowd was kinda lacking enthusiasm to verbally respond to the speaker on stage with 'ooo's, 'aaaa's, 'yeah's, 'alright's and stuffs. Most of the time the crowd was silent.

Nevertheless it was a must-attend event of this year. I will attend the next event for sure.

 

Friday, July 9, 2010

In Google DevFest 2010

Currently I am attending the Google DevFest 2010. Timothy Jordan and Bob Aman in their presentation on Open Social.

Today the registration was pretty crowded, and they differentiate based on the first letter of your first name. I was in the "A-F queue". The queue was long and the registration process was draggy.

They changed the schedule a bit, Daniel Lee presented the Google Maps as opposed to the initial schedule on the web site: Google DevFest 2010 in Singapore. He showed us how to create a coffee shop location based informative web site as an example.

After the first session, Jeremy Orlow, an engineer working on the Chrome team, explained the HTML5 and the Chrome. They skipped the Q&A for HTML5 and Chrome. May be they pushed forward because we're late because of the registration, so in order to finish during the lunch time, the organizer advised to ask in person to Jeremy during lunch time for anyone who want to ask questions.

Then here comes the third session, and its about  Open Social.  Tim was of more lively presenter than others I think. More like MC may be? Google Buzz API stuffs, atom, OAuth, Salmon, Pubsubhubbub etc.

Saturday, June 12, 2010

Attending Singapore Google Technology Group Meetup

 

Today I attended this Singapore Google Technology User Group Meeting. It's my first time to attend such a Google meetings. Some of previous meet ups had always fallen on the wrong days -- on the day that I have something else to do. Today I am glad to be able to make it, attended the meeting, and Wesley Chun, was the speaker. He presented 2 sessions, one about Python and the other one about Google App Engine.

This guy's a hardcore Python guy, wrote the Core Python series of book, and was a presenter in the PyCon Asia Pacific 2010, Singapore -- an event that has been held last 3 days. Awesome in depth knowledge, vast industrial experiences, and keep the talk flows fluent.

The rest about the meeting can be found here: http://www.sg-gtug.org/2010/05/sg-gtug-special-tutorial-session-june.html

Wednesday, May 26, 2010

NTLM authentication is no longer supported by Spring Security 3.0.x

I am exploring the way to automatically authenticated on Windows platforms on Spring Security. The older way of doing this is by using the NTLM_FILTER which works with Spring Security 2.0.x.

I just realised that the NTLM filter is no longer supported in Spring Security 3.0.x. The preferred way to do authentication is using the Kerberos.

http://blog.springsource.com/2009/09/28/spring-security-kerberos/

I have stumbled upon this Kerberos authentication has since my freshmen year at university back in 1995. It should then be  I remember when using the yellow page tools on SunOS in SPARCstation  boxes; the ypbind, yppasswd, etc (renamed NIS) are Kerberos based. It's been around for years, yet I haven't had much experience in setting the configuration on the server from scratch.

Now that I have to explore this, it's time to go in depth with this Kerberos stuffs.

The Windows NT which formerly has its own authentication system, that time, began to adopting standards such as LDAP, Kerberos, etc. NTLM -- which stands for NT LAN Manager, hum, sounds very very oldies kind of stuff -- has been superseded by Kerberos based authentication. Windows 2000 started providing Kerberos authentication as an alternative. Of course since the introduction of Kerberos based system, the transition has been slow, suggesting the new user to use Kerberos by default, and only supporting NTLM when they need backward compatibility with old systems (such as Windows 98). Nevertheless there are some people is still using the NTLM on their legacy systems.

The Spring Security team has deprecated the NTLM integration and move to Kerberos based authentication (for Windows systems) instead.

Monday, March 29, 2010

Hudson Shows "No buffer space available (maximum connections reached?): JVM_Bind"

These few days we kept bumping into this "No buffer space available" issue with Hudson CI. Initially I thought it was because of we updated Hudson to the latest version and there was a kind of bug in that latest version. I reverted to the latest stable supported version in the Hudson CI website (http://hudson-ci.org). The problem didn't appear for a while, only to reappear again after a while!

Here is the capture in my browser:

I purposely put the same message as in the captured image so that search engine will be able to find when people search using the error message.

java.net.SocketException: No buffer space available (maximum connections reached?): JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native method)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.(Unknown Source)
at hudson.TcpSlaveAgentListener.(TcpSlaveAgentListener.java:91)
at hudson.model.Hudson.(Hudson.java:598)
at hudson.WebAppMain$2.run(WebAppMain.java:224)

I initially tried to find any solutions to this issue using  Google search without much luck. There are few reference on this kind of error but it happened long time ago and seemed to be unrelated to the problem we encountered.

Initially I was thinking of the user limits on Windows, something like ulimit in UNIX/Linux systems.

After 2 cups of coffee, there come the enlightenment.

It's hard to believe that this problem was caused by this (http://support.microsoft.com/kb/196271). The Hudson CI application is currently running on Windows Server 2003 box. This version of Windows Server has something called  "maximum ephemeral port number".

Quoting from this Wikipedia entry:

"Ephemeral port is a transport protocol port for Internet Protocol (IP) communications allocated automatically from a predefined range by the TCP/IP Stack Software. It is typically used by the TCP, UDP or SCTP as port for the client end of a client-server communication when the application doesn't bind the socket to a specific port number, or by a server application to free up service's well known listening port and establish a service connection to the client host. The allocations are temporary and only valid for the duration of the connection. After completion of the communication session the ports become available for reuse, although most implementations simply increment the last used port number until the ephemeral port range is exhausted."

According to the Microsoft support website:

Windows Vista and Windows Server 2008 use the IANA suggested ephemeral ports range while the Windows Server 2003 is still using port range of 1250 to 5000.

Ephemeral ports are short-lived port, chosen ad-hoc to serve. In most implementations, they usually only add the port numbers by one until get exhausted on port numbers.

May be this is just my silly thought of me, but it seems like they implemented like this pseudo-code:

[sourcecode lang="python"]
next_port_num = 1250

def get_next_ephemeral_port_num():
result = next_port_num
next_port_num = next_port_num + 1
if next_port_num > 5000:
raise ValueError('no buffer space available')
return result
[/sourcecode]

I wasn't really sure that it is the cause of the problem, but I guess no kangaroo being harmed in the making of the game, so I tried it anyway.

The remedy was simply, run the Registry Editor in the Administrator privilege, open  the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters and create new DWORD entry, "MaxUserPort", fill with 65534.

The result, after 2 days monitoring, Hudson is still running well.

NOTE:
  • It seems that the problem happens to this specific version of Windows (Windows Server 2003)
  • I haven't been able to reproduce this problem on another platforms

Monday, March 1, 2010

Apache Beehive Moved into Apache Attic

Our long time friend, Apache Beehive framework, which was  from BEA WebLogic Workshop Framework donated to Apache Software Foundation has reached its end of life. Personally I have encountered this framework a few times when dealing with production application developed using BEA WebLogic Workshop Framework 8.1.x (the BEA's proprietary IDE), and also the development that we did using BEA WebLogic Workshop Framework 9.2 (the Eclipse based IDE).

The framework consisted of NetUI, Control and Web Service Metadata.

The Beehive NetUI is a framework built on top of Struts 1.x (I think it was 1.1, but not from 1.3.x for sure). I remembered when using  the BEA WebLogic Workshop IDE, we can configure the page flow using diagrams. It was quite a mess after a while, when you have a lot of page flows though.

The Beehive Controls framework was a superb innovation that time. It simplifies a lot of things (taking into account that at those time it took a lot of extra jobs when you want to configure EJB 2.1 invocation yourself). I believe was based on EJBGen, and predates the Java annotations. The major setbacks with Controls frameworks were that it make it difficult for developers to decouple the application from the BEA WebLogic Workshop Framework, and even more difficult to decouple with the WebLogic Workshop IDE! The IDE did a lot of magic behind the scene (at least for WebLogic 8.1.x), such as generating Ant build files that uses weblogic.jar classes.

Most of the contribution from BEA Systems Inc had been absorbed into the Java Annotations. Well, I think the Beehive Control framework served its duty at its time, yet now it became less and less compelling to use for the reason that it's been obsolete. With almost every comparable framework providing the similar ease of use without having to couple with some jars; who wants to use this "maintenance mode" framework for new developments.

The Beehive WSM (web service metadata), has also served its duty during its time, as new web service standards and frameworks have rolled out one by one. It's been obsolete just as many other web service frameworks. it's cousin, the XMLBeans framework (http://xmlbeans.apache.org) seems to survive much longer. It has just released version 2.5.0 last December 14th, 2009. I personally enjoy using this component framework, generating Java classes and XML mapping. Though we have some other frameworks like Jibx, I personally feel that this XMLBeans is more sophisticated.

Commiters of the project eventually voted to close the Apache Beehive project (http://beehive.apache.org) due to lack of activity. It is moved to Apache Attic (http://attic.apache.org) - such an affectionate name :D

The project was lacking activities, and I agree that it should be shelved into the attic. I believe legacy applications that uses this component should not have any problems because the component is still there, the source code is still there, and more or less it is stable enough.

Recommendations for replacement components are shown in the page, Spring Web Flow/Struts 2 to replace Beehive NetUI, Spring Framework Core to replace Beehive Controls, and Axis2 to replace Beehive WSM.

Good bye, old friend!

Thursday, July 9, 2009

Python's Lazy Evaluation on Exception Handling

I tried a simple code like this:

[sourcecode lang="python"]
try:
while True:
print('yipee')
except KeyboardInterrupt:
print('w00t')
[/sourcecode]

It runs successfully on command line interface, and keeps printing "yipee" until the user press Ctrl-C. After that I did a typo, which turns out to mistype the "KeyboardInterrupt" as "KeybaordInterrupt".

[sourcecode lang="python"]
try:
while True:
print('yipee')
except KeybaordInterrupt:
print('w00t')
[/sourcecode]

To my surprise, it still runs well, it keeps printing "yipee" to the screen. It's just that
when I press Ctrl-C, Python threw this error:

[sourcecode lang="shell"]
Traceback (most recent call last):
File '<stdin>', line 3, in <module>
KeyboardInterrupt
[/sourcecode]

During handling of the above exception, another exception occurred:

[sourcecode lang="shell"]
Traceback (most recent call last):
File '<stdin>', line 4, in <module>
NameError: name 'KeybaordInterrupt' is not defined
[/sourcecode]

I looked at the documentation of Python 3.1 which says:
The try statement works as follows.

First, the try clause (the statement(s) between the try and except keywords) is executed.

  • If no exception occurs, the except clause is skipped and execution of the try statement is finished.

  • If an exception occurs during execution of the try clause, the rest of the clause is skipped. Then if its type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement.

  • If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements; if no handler is found, it is an unhandled exception and execution stops with a message as shown above.


The exception handling in Python works in a lazy manner, they will only validate the except clauses just before processing the exception!

Wednesday, July 1, 2009

Adding Embedded ActiveMQ to Spring Container (on Maven 2 Project)

Today, we need to add a queue to our application to better manage long running transaction on our web application. The choice fell into using embedded ActiveMQ.We plan to use the latest version available (which currently ActiveMQ 5.2.0). Previous version of our application use our proprietary code which I believe was an example of reinventing the wheel. For our latest version of application, we try to use as much as possible open standard and open source technologies. ActiveMQ is under the Apache Software Foundation umbrella which is suitable for us.

First I add the dependency for the latest version of ActiveMQ (version 5.2.0):

[sourcecode lang="xml"]
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.2.0</version>
<optional>false</optional>
</dependency>
[/sourcecode]

Now it's time to add something into the Spring application context configuration file.
As suggested by the documentation, I added new namespace amq in my XML. It points to "http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd" schema location.

[sourcecode lang="xml"]
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
[/sourcecode]

I tried to run a JUnit test just to make sure that the new change in the configuration works well. There were some 2 errors. It turns to be a stale schema location. I figured it out from opening the URL http://activemq.apache.org/schema/core and see what's in there. So now need to modify a bit, change "http://activemq.apache.org/schema/core/activemq-core.xsd" to "http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd".

So here goes the correct version that works (syntactically correct XML):

[sourcecode lang="xml"]
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd">
[/sourcecode]

Now the next beast coming in, when I tried to use the new namespace by adding this inside the <beans/> tag.

[sourcecode lang="xml"]
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:0" />
</amq:transportConnectors>
</amq:broker>
[/sourcecode]

It produced this error:

[sourcecode lang="shell"]

java.lang.ExceptionInInitializerError
at com.triquesta.tcm.core.services.MessagingServiceTest.init(MessagingServiceTest.java:17)
[...deleted...]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [tcm_configs.xml]; nested exception is org.springframework.beans.FatalBeanException: NamespaceHandler class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] for namespace [http://activemq.apache.org/schema/core] not found; nested exception is java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
[...deleted...]
Caused by: org.springframework.beans.FatalBeanException: NamespaceHandler class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] for namespace [http://activemq.apache.org/schema/core] not found; nested exception is java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:134)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1292)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
[...deleted...]
Caused by: java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:123)
... 37 more
[/sourcecode]

Tuesday, June 30, 2009

Eclipse Update Site for Subclipse has been Updated, Now Works with Galileo

Three days ago, I tried installing Subclipse to Eclipse 3.5/Galileo without luck (for 1.4.x, the site was working previously with Eclipse 3.4 Ganymede). The update site doesn't work. Now, today I give it a try again.
The page at tigris.net had just been updated to incorporate the subversion 1.6.x, and will be using Subversion 1.6.x client and working copy format. It wasn't there 3 days ago.

It's like more like mechanic, now open Help - Install New Software..., click [Add...] button at the top right of the dialog, type "Subclipse" in the Name field, and "http://subclipse.tigris.org/update_1.6.x" then click the [OK] button.

Now, the update site works as expected.

Saturday, June 27, 2009

Eclipse 3.5 Galileo has been Released

On June 25th, 2009 Eclipse release its 3.5 codenamed Galileo.

I'm trying to explore this new stuff a bit, and try to experience what's new.


http://www.eclipse.org/galileo


My personal experience, I was always excited to see how fast Eclipse has been in incorporating features that was missing before since pre-Europa. Before Europa release, I hate it if I have to use it. But since the Europa, it has become my IDE of choice (also due to its licensing mode).


Today I downloaded the eclipse-jee-galileo-win32.exe file, as it is the most suitable for our team needs. If everything seems to be acceptable, we will soon moving our development environment here to make use of this new release.


What I am waiting for is to see how far the IAM has progressed. On Ganymede SR1, some of the link still isn't consistent yet.


The most notable change is in the application icon. Now it's no longer the shaded purple planet satellite with double white equatorial stripes. The icon changed color with less saturation, and there is a halo outside that looks like a gear.


Other notable change is in the way how Eclipse update its features as in OSGi components. This is one of the most confusing part of Eclipse IDE. Before Ganymede, you have to add your own update site, give the site a name and URL, then Eclipse will load components data. You must select the checkboxes. On Ganymede you don't have to specify a name, just the URL. On Galileo, now they separate between update of Eclipse and update of third party components.


Eclipse has notoriously been problematic in the updating components, where as the update on the Eclipse components could fail some others. You can't just update your Eclipse component right. Most of the time you need to reinstall your Eclipse and build yours from release, e.g. when updating from Ganymede to Ganymede SR1, it'd better safe your time to start from a clean fresh Ganymede JEE SR1 installer and re-add your custom components one by one, rather than taking the risk to update the Ganymede JEE release.


It seems that now Eclipse separates the update of Eclipse from other componets, now have "Check for Updates", and "Install New Software...".


I tried to use the Subversive, and it complains no JavaHL. Haven't had luck to find a way to add it. I tried to get Subclipse instead, and the update URL provided (http://subclipse.tigris.org/update_1.4.x) that was working still haven't supported Galileo.


I guess I have to wait some more before moving our development to the new version.

Fallback.



(I'm still exploring it now).

Thursday, June 25, 2009

Float and Byte Array Conversion

One of my friends raised this question: How to convert sequence of bytes into float in Java?

He/she bumped into this problem when porting C application to Java which parses UDP packets. Sounds like Java is lacking the flexibility of C whereby it could simply copy the memory block content to a pointer of any types (including struct).

While in C/C++ it is legal to do this:
[sourcecode lang="c"]
#include

char cbuf[] = { 0, 0, 96, 64 }; /* representing single precision floating point 3.5f */

int main(int argc, char **argv) {
int i;
for(i = 0; i < 4; i++) {
printf("cbuf[%d] = %d\n", i, cbuf[i]);
}

float *fp = (float *) cbuf;
printf("*fp = %3.3f\n\n", *fp);
}
[/sourcecode]

Which prints the result:
[sourcecode lang="shell"]
cbuf[0]=0
cbuf[1]=0
cbuf[2]=96
cbuf[3]=64
res = 3.500

[/sourcecode]

You just can't do that in Java (plus you won't be getting mystifying errors due to memory stomping as well).
NOTE: because we are using C language, result might be different from platform to platform, due to Little Endian/Big Endian issue.

In order to achieve the conversion in Java, you have to parse the byte array (equivalent to char[] in above C example code).

I constructed a Java utility class named FloatByteArrayUtil:

[sourcecode lang="java"]
public class FloatByteArrayUtil {
private static final int MASK = 0xff;

/**
* convert byte array (of size 4) to float
* @param test
* @return
*/
public static float byteArrayToFloat(byte test[]) {
int bits = 0;
int i = 0;
for (int shifter = 3; shifter >= 0; shifter--) {
bits |= ((int) test[i] & MASK) << (shifter * 8);
i++;
}

return Float.intBitsToFloat(bits);
}

/**
* convert float to byte array (of size 4)
* @param f
* @return
*/
public static byte[] floatToByteArray(float f) {
int i = Float.floatToRawIntBits(f);
return intToByteArray(i);
}

/**
* convert int to byte array (of size 4)
* @param param
* @return
*/
public static byte[] intToByteArray(int param) {
byte[] result = new byte[4];
for (int i = 0; i < 4; i++) {
int offset = (result.length - 1 - i) * 8;
result[i] = (byte) ((param >>> offset) & MASK);
}
return result;
}

/**
* convert byte array to String.
* @param byteArray
* @return
*/
public static String byteArrayToString(byte[] byteArray) {
StringBuilder sb = new StringBuilder("[");
if(byteArray == null) {
throw new IllegalArgumentException("byteArray must not be null");
}
int arrayLen = byteArray.length;
for(int i = 0; i < arrayLen; i++) {
sb.append(byteArray[i]);
if(i == arrayLen - 1) {
sb.append("]");
} else{
sb.append(", ");
}
}
return sb.toString();
}
}

[/sourcecode]

One good thing about Java is, we don't have the Big Endian/Little Endian issue.

This is the sample code that shows how this utility works.

[sourcecode lang="java"]

public class SampleConversion {
public static void main(String args[]) {
float source = (float) Math.exp(1);
System.out.println("source=" + source);
byte[] second = FloatByteArrayUtil.floatToByteArray(source);
System.out.println("temporary byte array=" + FloatByteArrayUtil.byteArrayToString(second));
float third = FloatByteArrayUtil.byteArrayToFloat(second);
System.out.println("result=" + third);
}
}
[/sourcecode]

Which prints:
[sourcecode lang="shell"]
source=2.7182817
temporary byte array=[64, 45, -8, 84]
result=2.7182817
[/sourcecode]

Of course you also need to take consideration of the Little Endian/Big Endian issue when parsing the bytes passed from non-Java platform, or from native binaries (I think JNI supports the conversion seamlessly).

Thursday, June 18, 2009

I run my Tomcat, instead I get this "ORACLE DATABASE 10g EXPRESS..." message

You try to run  Apache Tomcat, but instead you  get this message "ORACLE DATABASE 10g EXPRESS EDITION LICENSE AGREEMENT".
This simply means
If you bump into this problem, you have an Oracle 10g Express Edition (OracleXE 10g) installation sitting on the same port as your Tomcat default port (TCP/IP port 8080). As the TCP/IP protocol doesn't allow you to have more than one process listening to the same port (except when you use the advanced channel/selector), then when you start Tomcat, it will fail. You might not be aware that your Tomcat has failed to start, until you get into that message mentioned above.

There are 2 cures to this symptoms, the first cure  is to let Oracle XE take the port, and we move the tomcat installation to another port. The second cure is to set the Oracle XE to use another port.

To achieve the first one, you need to modify your $CATALINA_HOME/conf/server.xml file. Find the portion of the file that contains this snippet (assuming you are using the standard Tomcat installation):

[sourcecode lang="xml"]
connectionTimeout="20000"
redirectPort="8443" />
[/sourcecode]

Change the port 8080 to something else, e.g. 8484.

[sourcecode lang="xml"]
connectionTimeout="20000"
redirectPort="8443" />
[/sourcecode]

By now you should be able to run you application.
Don't forget that you have to run it from port 8484. So if the application you deploy is someapp.war the URL that you aim should be http://localhost:8484/someapp/ instead of http://localhost:8080/someapp/

Ok, now if you want to take the second cure, go to your Oracle XE 10g console using sqlplus. Replace mypassword with that your SYS user password (as specified during the installation process). Note that the number 2, 3, 4 at the left side is generated by the sqlplus tools prompt (you don't need to type them in).

[sourcecode lang="sql"]
C:\> sqlplus sys/mypassword@xe as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 18 17:53:47 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> begin
2 dbms_xdb.sethttpport('8484');
3 end;
4 /
[/sourcecode]

Oracle XE should reply:

[sourcecode lang="sql"]
PL/SQL procedure successfully completed.
[/sourcecode]

After that check to ensure that the configuration has been changed properly:

[sourcecode lang="sql"]
SQL> select dbms_xdb.gethttpport as "HTTP-Port is " from dual;
[/sourcecode]

You should get a message like this:

[sourcecode lang="sql"]
HTTP-Port is
------------
8484
[/sourcecode]

Exit from sqlplus by typing "exit" at the prompt.

If everything as expected, now you can start the Tomcat server and use the port 8080 for Tomcat. To access the Oracle XE 10g database web console, access through http://localhost:8484/apex