Tuesday, June 30, 2009
Eclipse Update Site for Subclipse has been Updated, Now Works with Galileo
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
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
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"]
redirectPort="8443" />
[/sourcecode]
Change the port 8080 to something else, e.g. 8484.
[sourcecode lang="xml"]
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
HTTP Error 404 on Your Java Web App?
For me, I would run through these diagnostic process:
- Because the browser returned error HTTP status 404, means that the application server is there serving the HTTP request; make sure that the application server serving there is the Tomcat/JBoss/WebLogic/WebSphere that you intended to get the data from; typical mistakes would be that you are trying to get the data from your application server, ended up that you hit an Oracle XE web console running on the same port, or you are hitting something else other than what you intended to.
- Check whether your application has been deployed. The error could come because your application actually has not been deployed to the application server. Use Tomcat Manager for Apache Tomcat, use WebLogic console, or Glassfish console, or whatever console your application server provides.
- Check whether there are some failure in the deployment process. This time you or your IDE deployed the application, yet there are some failure that causes the deployment to stop. It is typical for example, on finding error on your Spring context configuration or your Hibernate context configuration, your application will cease to deploy. It is also common when you have something wrong in your web.xml file, the application server will refuse to deploy. Check what error you get from your console and application server's log.
- And if you find out that the application has been successfully deployed, check whether the URL is actually available: check whether your web application uses filter (check the web.xml file), and check whether the JSP file exists (if it hits the JSP file directly), or check whether the action request is configured property (in action based MVC framework such as Struts1.x, WebWork, Struts2, Spring MVC, etc).
Better luck next time.
Wednesday, June 17, 2009
Syntax Highlighting in Wordpress.com blog
In order to do it, you need to use the
[sourcecode lang="<language>"] tag:
[sourcecode language="xml"]
[/sourcecode]
Above code is using lang="xml".
For Java code snippets you could highlight it pretty easily using the lang="java" with the tag.
[sourcecode language="java"]
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
[/sourcecode]
I am just really excited on how it works. I think Alex Gorbatchev has done a great job on the syntax highlighter!
Tuesday, June 16, 2009
Friday, June 12, 2009
Spring Framework 2.5.6 Security Release (2.5.6.SEC01)
http://www.springsource.com/securityadvisory
According to SpringSource this ad-hoc release is due to bug in JDK 5 (not in the Spring Framework itself) that causes compilation process of certain java.util.regex.Pattern to be unusally long. This is a potential problem as it could be used as Denial Of Service (DoS) attack.