woensdag 24 februari 2010

jvisualvm : beyond jconsole

Just discovered jvisualvm :D

IOException: Cannot run program "reg"

Running glassfish and IBM MQ7 on windows 2000 we got this error. IBM discovered this before and has this fix for us. It's a huge download for a small fix. In fact it's much quicker to simply download the missing reg.exe file (google for it) :p


WARNING: java.io.IOException: Cannot run program "reg": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at com.ibm.mq.jmqi.internal.JmqiTools.getRegistryPropertyInternal(JmqiTools.java:1388)
at com.ibm.mq.jmqi.internal.JmqiTools$4.run(JmqiTools.java:1351)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.mq.jmqi.internal.JmqiTools.getRegistryProperty(JmqiTools.java:1348)
at com.ibm.mq.jmqi.internal.Configuration.getProperty(Configuration.java:1202)
at com.ibm.mq.jmqi.internal.Configuration.getStringValue(Configuration.java:433)
at com.ibm.mq.jmqi.internal.Configuration.iniFileAsStreamWmqDataDir(Configuration.java:1091)
at com.ibm.mq.jmqi.internal.Configuration.findClientIni(Configuration.java:938)
at com.ibm.mq.jmqi.internal.Configuration.access$300(Configuration.java:55)
at com.ibm.mq.jmqi.internal.Configuration$1.run(Configuration.java:247)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.mq.jmqi.internal.Configuration.(Configuration.java:238)
at com.ibm.mq.jmqi.JmqiEnvironment.(JmqiEnvironment.java:251)
at com.ibm.mq.jmqi.system.JmqiSystemEnvironment.(JmqiSystemEnvironment.java:82)
at com.ibm.mq.jmqi.JmqiFactory.getInstance(JmqiFactory.java:92)
at com.ibm.mq.internal.MQCommonServices.(MQCommonServices.java:264)
at com.ibm.mq.MQSESSION.getJmqiEnv(MQSESSION.java:139)
at com.ibm.mq.MQSimpleConnectionManager.(MQSimpleConnectionManager.java:93)
at com.ibm.mq.MQEnvironment.(MQEnvironment.java:570)
at fatass.jsf.ContextListener.contextInitialized(ContextListener.java:250)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4523)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5184)
at com.sun.enterprise.web.WebModule.start(WebModule.java:326)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:973)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:957)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:688)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1584)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1222)
at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:182)
at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:278)
at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.java:974)
at com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:961)
at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:464)
at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:176)
at com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper.java:308)
at com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:226)
at com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(ServerDeploymentTarget.java:298)
at com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(ApplicationStartPhase.java:132)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:591)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:635)
at com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.start(ApplicationsConfigMBean.java:744)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:375)
at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:358)
at com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:464)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
at $Proxy1.invoke(Unknown Source)
at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304)
at com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:174)
at com.sun.enterprise.admin.jmx.remote.server.callers.InvokeCaller.call(InvokeCaller.java:69)
at com.sun.enterprise.admin.jmx.remote.server.MBeanServerRequestHandler.handle(MBeanServerRequestHandler.java:155)
at com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet.processRequest(RemoteJmxConnectorServlet.java:122)
at com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet.doPost(RemoteJmxConnectorServlet.java:193)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.W
WARNING: orkerThreadImpl.run(WorkerThreadImpl.java:116)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 94 more


This link has a small example of code using this executable. Note that this isn't platform independent and therefor not an ideal approach. I added a print of the stacktrace in the catch blocks:


import java.io.*;

public class RegQuery {

private static final String REGQUERY_UTIL = "reg query ";
private static final String REGSTR_TOKEN = "REG_SZ";
private static final String REGDWORD_TOKEN = "REG_DWORD";

private static final String PERSONAL_FOLDER_CMD = REGQUERY_UTIL +
"\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\"
+ "Explorer\\Shell Folders\" /v Personal";
private static final String CPU_SPEED_CMD = REGQUERY_UTIL +
"\"HKLM\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\""
+ " /v ~MHz";
private static final String CPU_NAME_CMD = REGQUERY_UTIL +
"\"HKLM\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\""
+ " /v ProcessorNameString";

public static String getCurrentUserPersonalFolderPath() {
try {
Process process = Runtime.getRuntime().exec(PERSONAL_FOLDER_CMD);
StreamReader reader = new StreamReader(process.getInputStream());

reader.start();
process.waitFor();
reader.join();

String result = reader.getResult();
int p = result.indexOf(REGSTR_TOKEN);

if (p == -1)
return null;

return result.substring(p + REGSTR_TOKEN.length()).trim();
}
catch (Exception e) {
e.printStackTrace()
return null;
}
}

public static String getCPUSpeed() {
try {
Process process = Runtime.getRuntime().exec(CPU_SPEED_CMD);
StreamReader reader = new StreamReader(process.getInputStream());

reader.start();
process.waitFor();
reader.join();

String result = reader.getResult();
int p = result.indexOf(REGDWORD_TOKEN);

if (p == -1)
return null;

// CPU speed in Mhz (minus 1) in HEX notation, convert it to DEC
String temp = result.substring(p + REGDWORD_TOKEN.length()).trim();
return Integer.toString
((Integer.parseInt(temp.substring("0x".length()), 16) + 1));
}
catch (Exception e) {
e.printStackTrace()
return null;
}
}

public static String getCPUName() {
try {
Process process = Runtime.getRuntime().exec(CPU_NAME_CMD);
StreamReader reader = new StreamReader(process.getInputStream());

reader.start();
process.waitFor();
reader.join();

String result = reader.getResult();
int p = result.indexOf(REGSTR_TOKEN);

if (p == -1)
return null;

return result.substring(p + REGSTR_TOKEN.length()).trim();
}
catch (Exception e) {
e.printStackTrace()
return null;
}
}

static class StreamReader extends Thread {
private InputStream is;
private StringWriter sw;

StreamReader(InputStream is) {
this.is = is;
sw = new StringWriter();
}

public void run() {
try {
int c;
while ((c = is.read()) != -1)
sw.write(c);
}
catch (IOException e) { e.printStackTrace(); }
}

String getResult() {
return sw.toString();
}
}

public static void main(String s[]) {
System.out.println("Personal directory : "
+ getCurrentUserPersonalFolderPath());
System.out.println("CPU Name : " + getCPUName());
System.out.println("CPU Speed : " + getCPUSpeed() + " Mhz");
}
}

donderdag 18 februari 2010

Android must have free applications

Since payed applications aren't yet supported in Belgium I can only find free applications on the market. These are my favorites:


System tools


Barcode Scanner
This one you'll need to scan the QR codes :D. You can also scan other barcodes but I didn't find much information on the net on the ones I tried.

ASTRO File Manager
The best filemanager I found for android so far.

Locale
In fact this one ain't available as a free app anymore. Only the beta was available so you'll need to look for an .apk on the web if you really want this one for free. It's a tool to change system properties based on location, date, time, etc. The properties you can change are dataconnection, wireless, flightmode, sounds, backgrounds, etc. There are several plugins available to extend the amount of events and properties.

Quick System Info
All you need to know about the system. Display processes, specs, logs, installed applications, etc.

Battery Widget
Can be placed on desktop (widget) and displays battery level. When selected an info screen with more details is shown.

Wifi Analyzer
Does exactly what you expect.

Navigation

c:geo
The best Geocaching tool I found so far. It lets you browse the caches nearby, show details of caches, show caches on the map, navigate to a cache (arrow), log when you found a cache, etc.

compass
Doesn't need much explication... you can set several styles.

GPS Status
Shows how many satellites are connected, min/max/avg speed, min/max/avg altitude, coördinates, etc.

My Tracks
Great for walkers and other outdoor sports. It tracks your route on a map. Also collects information (like GPS Status) and routes can be exported.

My Maps Editor
With this tool you can edit your google maps on your mobile.

Other
Mind Map Memo: create and edit mind maps
Pintail: get location of your cellphone by sms
SMS Backup: back up sms messages to your gmail account
Shazam: recognize music playing
Ringdroid: cut music for use as ringtone
Pricewatch Scanner: scan barcodes to find prices in the tweakers pricewatch
TVGiDS.tv: tv guide
Photoshop.com Mobile: mobile photoshop (limited)
Google Sky Map: a map of the stars
Facebook: facebook application for android
AndFTP: ftp client
A world of photo: receive and send photo's from/to all over the world
Bebbled: game like bubbles
GameBoid Lite: to play gamboy roms
Magic 8-Ball: shake to get an answer from the 8-ball
PicSay: edit pictures and add fun stuff

JavaBean properties: uppercase vs lowercase

In general JavaBean properties can be accessed by the getter method without the get and the first letter in lowercase. For instance:

public class SomeClass {
  private String test;
  public String getTest(){return test;}
  public void setTest(String test){this.text=test;}
}

When accessing from the frontend this works fine:

#{someClass.text}

But when you have a property that begins with several capitals java doesn't find it when you only lowercase the first letter like this:

public class SomeClass {
  private String xml;
  public String getXML(){return xml;}
  public void setXML(String xml){this.xml=xml;}
}

someClass.xML and someClass.XML don't work. You need to lowercase all capitals in a row:

#{someClass.xml}

Some other examples:

getXMLData => xmldata
getXMLTestData => xmltestData
getXmlTestData => xmlTestData

dinsdag 16 februari 2010

Timestamps with hibernate annotations

When you want timestamps on objects persisted with hibernate you can add callback methods that initialize these Date properties properly.

@Entity
@Table(name = "entities")    
public class Entity {
//...

  private Date created;
  private Date updated;

  @PrePersist
  protected void onCreate() {
    created = new Date();
  }

  @PreUpdate
  protected void onUpdate() {
    updated = new Date();
  }
}

donderdag 4 februari 2010

Setting up Android Development environment

Since I've got a HTC Hero Android device I started looking at developing for the android platform. It's all java based and it's all integrated in eclipse so it shouldn't be that hard for me.

I downloaded the Android SDK, unzipped everything and added this location to the system path (I'm using windows).

Next I fired up the Android SDK and AVD Manager to get it all configured...

Exception in thread "Loading Source" java.lang.NoSuchMethodError: org.w3c.dom.Node.getTextContent()Ljava/lang/String;
at com.android.sdklib.internal.repository.RepoSource.parsePackages(RepoSource.java:694)
at com.android.sdklib.internal.repository.RepoSource.load(RepoSource.java:262)
at com.android.sdkuilib.internal.repository.RepoSourcesAdapter$TreeContentProvider$1.run(RepoSourcesAdapter.java:194)
at com.android.sdkuilib.internal.tasks.ProgressTask$1.run(ProgressTask.java:135)

:D It should work out of the box :P I quickly check if I was running java 1.5 or higher but that was oké so instead of figuring out what library was in conflicht I fetched the AVD package for 1.5 directly from the web and unzipped it in the platforms folder of my android sdk installation folder. The manager recognized it so I could create an AVD for testing.

I didn't have any problems with the android eclipse plugin. After installation from the download site (https://dl-ssl.google.com/android/eclipse/) I configured it and got it running.

The virtual device really takes a long time to boot :s