Monday, June 29, 2009

java hangs after installing "Java for Mac OS X 10.5 Update 4"

I had been experiencing some issues with Java on my MacBook after an update was pushed by Apple.

Had to jump through some hoops, but I came up with a workaround. For more details see this post.

Tuesday, June 23, 2009

How to download and install Nokia .wgz widgets OTA

According to Nokia we should be using an "AddType x-nokia-widget .wgz" directive to change the settings of web server to add a new mapping from the filename to a new MIME type.

Tough some people don't have access to server settings, let alone that Nokia's instructions don't include the complete MIME type (application/x-nokia-widget) so I'm not sure that what they suggested would work well.

Another way is to include the appropriate HTTP response headers through a script running on the server side.

This one, writteh in PHP, seems to be doing the job just fine. Pointing the S60 browser to its URL downloads the widget and starts its installation.


$filename = 'example.wgz';

header('Content-type: application/x-nokia-widget');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($filename);

Friday, June 19, 2009

java.rmi.server.UID is not random

Well, here's an unfortunate result of having different ways of doing the same thing in Java.

I needed a way to generate a random unique ID to be used as an authentication token. So I thought hmmm a sort of UID ought to do it. So the first candidate that Google suggested was

java.rmi.server.UID

Running a quick test gave me the following results in 2 subsequent runs: '-31a4aa0:121f7402438:-7f1f' and '-31a4aa0:121f7402438:-7f1e'. Epic fail. So much for randomness.

Looking for alternatives,
java.util.UUID

seems to be a better choice. In particular its

randomUUID()

factory method seems to claim cryptographic strength.

Tuesday, June 09, 2009

How to run GlassFish on the default HTTP port 80 on Solaris

If GlassFish is run as non-root process, with reduced privileges, as recommended, it won't be able to bind to ports < 1024. You'll get an exception:


java.net.BindException: Permission denied: 80 at com.sun.enterprise.web.connector.grizzly.SelectorThread.initEndpoint


To get around this you could set up a domain that has the ability to bind to standard Unix ports, including the port 80. For this you use the --serviceproperties net_privaddr flag of asadmin create-service command.


You can use the following steps. Replace the italic portion with your specific settings.


/opt/gf21/glassfish/bin# ./asadmin create-domain --adminport 4848 --instanceport 80 --profile cluster --user admin --domaindir /opt/gf21/glassfish/domains ptmp

Please enter the admin password>

Please enter the admin password again>

Please enter the master password [Enter to accept the default]:>

Please enter the master password again [Enter to accept the default]:>

Using port 4848 for Admin.

Using port 80 for HTTP Instance.

Using default port 7676 for JMS.

Using default port 3700 for IIOP.

Using default port 8181 for HTTP_SSL.

Using default port 3820 for IIOP_SSL.

Using default port 3920 for IIOP_MUTUALAUTH.

Using default port 8686 for JMX_ADMIN.

On Unix platform, port numbers below 1024 may require special privileges.

Domain being created with profile:cluster, as specified on command line or environment.

Security Store uses: JKS

Domain ptmp created.


You need to create a file with the admin credentials:


cat > /opt/gf21/glassfish/domains/ptmp/.aspass

AS_ADMIN_USER=admin

AS_ADMIN_PASSWORD=something

AS_ADMIN_MASTERPASSWORD=something

^D


/opt/gf21/glassfish/bin# ./asadmin create-service --passwordfile /opt/gf21/glassfish/domains/ptmp/.aspass --type das --serviceproperties net_privaddr /opt/gf21/glassfish/domains/ptmp

The Service was created successfully. Here are the details:

Name of the service:application/SUNWappserver/ptmp

Type of the service:Domain

Configuration location of the service:/opt/gf21/glassfish/domains

Manifest file location on the system:/var/svc/manifest/application/SUNWappserver/ptmp_opt_gf21_glassfish_domains/Domain-service-smf.xml.

The service could be enabled using svcadm command.

Command create-service executed successfully.


Ckeck that the newly created service is online. 


# svcs -a | grep ptmp

online         14:26:14 svc:/application/SUNWappserver/ptmp:default


If not make it so.

# svcadm enable svc:/application/SUNWappserver/ptmp:default


An extra sanity check:

# netstat -a | grep 80



Time-out when calling file_get_contents on PHP scripts hosted on Godaddy accounts

I noticed that if you're using a Godaddy shared web hosting plan you're limited to calling file_get_contents only on URLs that use the standard HTTP port 80


It may be a firewall rule that they have in place.


So if you have an url like http://app.example.com:8080/do?param=value, 

the call to file_get_contents will hang and eventually timeout, 

even if the same url is accessible directly from within a browser.


If you control the called web component you may be able to change it 

so that it would listen on the standard port 80.

Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource

If you get this error when trying to ping a newly created JDBC connection pool from within GlassFish admin console, it's likely because you're missing the JDBC driver mysql-connector-java-5.1.*-bin.jar under the lib/ext folder on your domain. 


To fix it copy that file there (e.g. ~/glassfish-v2ur2/domains/domain1/lib/ext/mysql-connector-java-5.1.5-bin.jar ), restart the domain and try again.

You can get the latest copy of the driver from here.


Update: There was at least a comment below, indicating that this method may not work for GlassFish version 3.1.1 and the more recent JDBC connection drivers. Your best bet may be to use the official docs, for the particular version of GlassFish you're running. For 3.1.1 one doc and another doc indicates that mysql-connector-java-5.1.14-bin.jar should be placed under the lib folder, not under lib/ext folder. 

Saturday, June 06, 2009

How to troubleshoot the bootup of GlassFish + MySQL image on OpenSolaris

I've been using an Amazon image with GlassFish+MySQL+OpenSolaris. As I'm no sysadmin, I relied on a prebuilt image furnished by Sun as a base for my development.

Still I've been experiencing  various issues at bootup, when the app server wouldn't start. This is especially true when you reboot the instance with Amazon EC2 tools. It behaves better if you terminate and restart the instance.

So I devised a set of steps to ensure that the thing gets working. 


Check if the services are running:

svcs  | grep mysql

svcs  | grep glassfish


If not, start them:

svcadm restart svc:/application/mysql:default

svcadm restart svc:/application/glassfish/domain1:default


Keep an eye on the server log

e.g. tail -f /opt/gf21/glassfish/domains/domain1/logs/server.log


If that reports failure, you have work to do.


Sometimes the app server can't start due to a previous process not having released the essentials TCP ports. Do a

netstat -a | grep 3700 



if it shows some daemons listening do a

ps -ef

look for usr/jdk/instances/jdk1.6.0/jre/../bin/java -Dcom.sun.aas.instanceRoot=/opt/gf2


That may be a stale instance. Try to kill -9 and look for the process above to be vanished and the port 3700 to be free.


Try again 

svcadm restart svc:/application/glassfish/domain1:default


transient error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

While experimenting with an Amazon OpenSolaris+GlassFish+MySQL AMI. I have been getting some weird errors when launching mysql. 

-bash-3.2$ mysql -u root -p

Enter password: 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


I don't know if it has to do with this particular image (install/config issue) or if it's a side effect of the fact that's run on a virtual server, but a quick workaround seems to be:

svcadm restart mysql ran as root 

Friday, June 05, 2009

error when bundling OpenSolaris - based AMI on Amazon EC2

I needed a server in the cloud for a project, with Glassfish and MySQL installed. Having found a pre-built AMI (Amazon Machine Image) based on OpenSolaris it seemed to be fit for my purpose.

After kicking its tires I decided to place my customizations and re-bundle an image that would have them on upon reboot.

So I followed along the instruction from the Getting Started guide (http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/). Well, no good. The bundling failed with the following error reported by ec2-bundle-vol:


Cloning / into image file /mnt/ptmpimage...
Excluding:
/export/home
/rpool
/export
/
/mnt
/mnt
/mnt/ptmpimage
/mnt/ec2-bundle-workspace
Creating flash archive of file system...
Time: 0.086058s
Time: 0.023259s
Time: 0.229003s
Time: 0.023268s
Time: 0.113336s
Time: 0.023153s
Time: 0.036836s
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
devfsadm: disk_link: invalid disk device number (2051)
Time: 0.400378s
ERROR: Failed to evaluate 'flar create -n ec2.archive -S -R / -x /export/home/gf21 -x /export/home/mysql -x /rpool/boot -x /rpool/etc -x /export/home -x /bin -x /boot -x /dev -x /devices -x /etc -x /export -x /home -x /kernel -x /lib -x /lost+found -x /media -x /mnt -x /net -x /opt -x /platform -x /proc -x /.profile -x /root -x /rpool -x /sbin -x /sysbench -x /system -x /tmp -x /usr -x /var -x /mnt/cert-SGB3LC7W3STUADHK6YLJGLH45V6NGQQU.pem -x /mnt/ec2-bundle-workspace -x /mnt/pk-SGB3LC7W3STUADHK6YLJGLH45V6NGQQU.pem -x /mnt/cert-SGB3LC7W3STUADHK6YLJGLH45V6NGQQU.pem -x /mnt/ec2-bundle-workspace -x /mnt/pk-SGB3LC7W3STUADHK6YLJGLH45V6NGQQU.pem -x /mnt/ptmpimage -x /mnt/ec2-bundle-workspace /mnt/ec2-bundle-workspace/archive 2> /dev/null'. Reason: .




It turns out that Solaris AMIs have a different bundling procedure, so the instructions provided by Amazon in their guide don't apply (I think they're for Fedora (or other RedHat derrivatives) images).

For instructions specific to Solaris see
this.